我试图在python中序列化,在golang中解封,但我面临错误。
错误消息 --“无法解析无效的有线格式数据”。
代码配置 --
python代码 --
schema_registry_client = SchemaRegistryClient({'url': 'http://localhost:8082'})
protobuf_serializer = ProtobufSerializer(user_attributes_pb2.UserProperties,
schema_registry_client,
{'use.deprecated.format': True})
producer_conf = {'bootstrap.servers': 'localhost:9092', 'key.serializer': StringSerializer('utf_8'), 'value.serializer': protobuf_serializer}
producer = SerializingProducer(producer_conf)
producer.poll(0.0)
########## Add an address #########
PromptForAddress(user_attr)
producer.produce(topic=topic, key=str(uuid4()), value=user_attr)
producer.flush()golang代码 --
Brokers: []string{brokerAddress},
Topic: topic,
GroupID: "test-consumer-group",
Logger: l,
})
for {
msg, err := r.ReadMessage(ctx)
user := &pb.UserProperties{}
err = proto.Unmarshal(msg.Value, user)
// client.Query() NewKey(Namespace, Set, user.Id)
if err != nil {
log.Fatal(err)
}
fmt.Printf("\n%s\n", proto.Message(user))
fmt.Printf("\n%v\n", user)
if err != nil {
panic("could not read message " + err.Error())
}
// after receiving the message, log its value
fmt.Println("received: ", string(msg.Value))
}proto文件在两种语言中都是类似的。
发布于 2022-09-07 13:58:51
由于您使用的是Confluent序列化程序及其模式注册表,因此需要在Go中进行同样的操作,并且不能只使用简单的Protobuf反序列化。
Confluent还维护一个Go客户端,您可以使用它。Protobuf - https://github.com/confluentinc/confluent-kafka-go/blob/master/examples/protobuf_consumer_example/protobuf_consumer_example.go示例
我不知道use.deprecated.format对Python做了什么,但是Go可能不会接受
https://stackoverflow.com/questions/73631871
复制相似问题