英文:
Can Pulsar support multiple schemas on a single topic
问题
我对Pulsar提供的Schema功能感兴趣,但在继续之前我想验证一个假设。
假设我有一个名为inventorymgmt的单一主题的库存管理系统。我有一个生产者,生产多个事件,如InventoryItemAdded和InventoryItemRenamed。
所有与库存相关的事件都发布到同一个inventorymgmt主题。
看起来,如果我想使用模式功能,它仅限于主题上的单一消息类型。这意味着如果我想要利用模式支持,我需要为每种类型的事件创建单独的主题。
我尝试过但未成功地尝试过如下操作:
var producer1 = await client.NewProducer(Schema.JSON<InventoryItemAdded>()).Topic("inventorymgmt");
var producer2 = await client.NewProducer(Schema.JSON<InventoryItemRenamed>()).Topic("inventorymgmt");
上面的代码会引发IncompatibleSchemaException异常。
这种工作方式是有道理的,但我只是想确认我的假设是正确的,而不仅仅是缺少某种配置设置。
英文:
I'm interested in the Schema functionality provided by Pulsar, but I want to validate an assumption before moving forward.
Let's say I have an inventory management system with a single topic called inventorymgmt.
I have a producer than produces several events such as InventoryItemAdded and InventoryItemRenamed.
All of the inventory-related events are posted to the same inventorymgmt topic.
It looks to me that if I want to use the schema functionality, it's limited to a single message type per topic. The implication is that I would need separate topics for each type of event if I want to leverage the schema support.
I've tried and failed to do something like:
var producer1 = await client.NewProducer(Schema.JSON<InventoryItemAdded>()).Topic("inventorymgmt");
var producer2 = await client.NewProducer(Schema.JSON<InventoryItemRenamed>()).Topic("inventorymgmt");
The above throws an IncompatibleSchemaException.
It makes sense that it would work that way, but I just want to confirm that my assumption is correct and that it's not just a matter of missing some type of configuration setting.
答案1
得分: 1
是的,在Pulsar中,每个主题都有一个单一的模式。发送到该主题的所有事件都必须符合该模式。如果要使用不同的事件类型,您可以使用多个主题,每个主题都有自己的模式。
或者,您可以定义一个通用模式,适用于多个事件类型。在您的示例中,您可以创建一个通用的项目模式,其中包含一个操作字段,该字段可以设置为"Added"、"Renamed"等等。
英文:
Yes, there is a single schema per topic in Pulsar. All events sent to the topic must conform to the schema. To have different event types, you should use multiple topics each with their own schema.
Alternatively, you could define a generic schema that works for multiple event types. In your example, you could have a generic Item schema with an Action field that could be set to Added, Renamed, etc.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论