繁体   English   中英

带有AVRO的Apache kafka,架构ID在消息中的哪里?

[英]Apache kafka with AVRO, where in the message does the schema id go?

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”,//更多字段,“ payload”:{“ name”:“ xyz”,“ age”:“ 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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM