glazkovalex / Rebus.Kafka

Apache Kafka transport for Rebus
MIT License
16 stars 6 forks source link

[Question] Multiple producers, using schema registry #12

Closed esskar closed 5 months ago

esskar commented 5 months ago

Hi, trying to get started. I want to be able to produce to two topics. Both topics have with different values. The values need to be serialized with protobuf.

var eventProvider1 =  new ProducerBuilder<string, Event1>(producerConfig)
    .SetValueSerializer(....)
    .Build()
var eventProvider2 =  new ProducerBuilder<string, Event2>(producerConfig)
    .SetValueSerializer(....)
    .Build()

Is this something that can be achieved? I saw that the KafkaTransport has a Producer<string, byte[]>

glazkovalex commented 5 months ago

Hello! Each instance of the Rebus bus can have only one incoming queue, but it can subscribe to an unlimited number of events (topics), as well as send messages and publish events to any topics. An example of sending events to two topics and processing these events is here: https://github.com/glazkovalex/Rebus.Kafka/blob/1e51fc25b33b1bd54f0bd2e2bfc07f5348d16139/Rebus.Kafka.Tests/SimpleTests.cs#L204C27-L204C49

The protobaf serializer is not supported by transport yet, it is in the long-term plans: "ToDo: Schema Registry support in Kafka: Avro, JSON and Protobuf"

However, there is a Protobuf-based message serializer for the Rebus bus, which may allow you to serialize a message in Protobuf, but I do not know if it will work, I did not use it.

glazkovalex commented 5 months ago

If you need to have not just a subscription to two events (topic), but to have two incoming message queues, then you will have to have two separate bus instances in the application. Moreover, you can send and receive many different types of messages to each incoming queue, for each of which, of course, there will be a different handler. How to make two separate instances of the Rebus bus in the application is shown in this example: https://github.com/glazkovalex/Rebus.Kafka/blob/1e51fc25b33b1bd54f0bd2e2bfc07f5348d16139/Examples/TwoBusInHost/Program.cs#L22 Only the second bus, of course, should not be t.UseKafkaAsOneWayClient(...), and should be the same bidirectional as the first t.UseKafka(...)