gpt4 book ai didi

java - Apache kafka 与 AVRO,模式 id 在消息中的哪里?

转载 作者:行者123 更新时间:2023-12-02 11:35:00 26 4
gpt4 key购买 nike

I do have a number of queries about AVRO schema.

I have read that, we need to pass a schema id and the message in the Kafka event.The body of my Kafka event is like -

{ "组件名称": "ABC", //更多的字段, “有效负载”:{ “名称”:“xyz”, “年龄”:“23” } }

In payload field, we provide the actual data. Here, where will I provide the schema id. I found one answer related to this at [link][1] 


[1]: https://stackoverflow.com/questions/31204201/apache-kafka-with-avro-and-schema-repo-where-in-the-message-does-the-schema-id,

这表示有一个编码器接受一个模式并从模式注册表中找到它的模式 ID。这是编码器序列化器还是不同的东西?我们是否还需要将模式嵌入到我们发送的消息中?编码器将如何选择模式?

Do we need to explicitly register schema in schema registry as said on this [link][1] 

Also, how will we associate a schema with a topic name?

最佳答案

我今天正在查看这个,似乎架构 ID 被编码为消息的第一个字节。

当键或值被反序列化时( code ):

ByteArrayOutputStream out = new ByteArrayOutputStream();
out.write(0);
out.write(ByteBuffer.allocate(4).putInt(e).array());

序列化时( code ):

ByteBuffer e = this.getByteBuffer(payload);
int id1 = e.getInt();
Schema schema = this.schemaRegistry.getById(id1);

关于java - Apache kafka 与 AVRO,模式 id 在消息中的哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49007766/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com