Creating ProtoBuf object schema for Kafka usage 生成用于Kafka的ProtoBuf对象模式

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

Creating ProtoBuf object schema for Kafka usage

问题

I am using ProtoBuf over Kafka. We are creating a lot of ProtoBuf messages, but we are stuck on these two options. Wondering what is the best way to do this? Hopefully question won't be downgraded as it is somehow opinion based!

Say, I want to send Employee message on Kafka. I want to use "id" as the kafka key and value as the "Employee" message as below.

Option - 1 includes "id". In this option, your entire object is in one place as a domain object.

message Employee {
 string id;
 string name;
 string title;
}

Option - 2 doesn't include id - as it tries to use Kafka key (which we are populating with id) and let the consumer piece them together when they take a message out of Kafka?

message Employee {
 string name;
 string title;
}

Any suggestions on the pros and cons of these two and any known best practice? Thanks.

英文:

I am using ProtoBuf over Kafka. We are creating a lot of ProtoBuf messages, but we are stuck on these two options. Wondering what is the best way to do this? Hopefully question won't be downgraded as it is somehow opinion based!

Say, I want to send Employee message on Kafka. I want to use "id" as the kafka key and value as the "Employee" message as below.

Option - 1 includes "id". In this option, your entire object is in one place as a domain object.

message Employee {
 string id;
 string name;
 string title;
}

Option - 2 doesn't include id - as it tries to use Kafka key (which we are populating with id) and let the consumer piece them together when they take a message out of Kafka?

message Employee {
 string name;
 string title;
}

Any suggestions on the pros and cons of these two and any known best practice? Thanks.

答案1

得分: 1

从我的经验来看:

  • 消息应包含所有所需的信息。
  • 键是消息系统知道如何处理消息的辅助信息。

因此,在两个选项之间,第一个选项更可取。

英文:

From my experience:

  • Message should contain all required information.
  • Key is auxiliary information for the messaging system to know how to work with the message.

So, between two options, the first one is preferable.

huangapple
  • 本文由 发表于 2020年8月13日 02:27:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/63382685.html
匿名

发表评论

匿名网友

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

确定