apache kafka与avro,在消息中使用架构ID

  • 本文关键字:ID 消息 kafka avro apache java avro
  • 更新时间 :
  • 英文 :

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 - 

{ " componentName":" 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被编码为消息的第一个字节。

当键或值被去序列化时(代码(:

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

序列化(代码(:

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

最新更新