英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论