需要在编写 Avro 生产者时单独创建键模式吗(除了字段模式)?

huangapple go评论73阅读模式
英文:

Is there a need of seperate Key Schema(other than a schema for fields) while writing Avro producer?

问题

我正在为我的项目编写Java Avro生产者代码。我已经为所有需要传递的字段注册了Avro模式。

我的已注册模式-

{

"name": "Claim",

"type": "record",

"namespace": "com.schema.avro",

"fields": [

{

  "name": "icn",

  "type": "string"

},

{

  "name": "fln,

  "type": "int"

},

]

}

我正在使用"icn"字段值作为键,但我没有单独注册键模式。我不确定是否需要。

i) 我可以直接使用已在当前模式中的字段("icn"在这种情况下)作为键,而无需注册键模式吗?

ii) 我需要单独注册键模式吗?如果是这样,那么它是否是已为字段创建的模式的一部分,还是与之不同?

英文:

I am writing Java Avro Producer code for my project. I have registered an Avro schema for all the fields which need to be passed.

My Registered Schema-

{

"name": "Claim",

"type": "record",

"namespace": "com.schema.avro",

"fields": [

{

  "name": "icn",

  "type": "string"

},

{

  "name": "fln,

  "type": "int"

},

]

}

I am using "icn" field value as a key but I don't have a key schema registered separately. I am not sure if that is required.

i) Can I directly use a field already in my current schema("icn" in this case) as the key without having to register a key schema?

ii) Do I need to register the key schema separately? If so, is that part of the schema already created for fields or is it different?

答案1

得分: 1

你无需为键使用 Avro。如果您的键是字符串类型,可以使用 org.apache.kafka.common.serialization.StringSerializer。如果您想使用 Avro,您需要为每种对象类型注册模式。

英文:

You are not required to use avro for keys. If your key is of type string you may use org.apache.kafka.common.serialization.StringSerializer. If you want to use avro, you need to register the schema for each object type.

huangapple
  • 本文由 发表于 2020年8月24日 15:04:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/63556169.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定