Automatically register Kafka Topics/Queues for existing event classes in Java/Kotlin

12 views Asked by At

My aim is to connect several microservices with each other using events via Kafka.

In Java, for example, I would create an OrderCreatedEvent, which is sent from the order service to the payment service. This OrderCreatedEvent class is in a shared library to avoid duplicate code as far as possible.

In the code, however, I don't want to worry about which topic/queue or other microservice the event is sent to in Kafka or where the payment service reads it from. Basically, I just want to say "send the event" in the order service and "listen to the event" in the payment service. The general logic using Kafka should happen in the background.

Otherwise, Kafka would involve a lot of planning and maintenance work, as topics/queues have to be planned and maintained. Of course, this could also be solved with a few topics/queues, but then services would possibly receive data (or events) that they do not need, resulting in a high volume of traffic/load.

Now to my question. Is there a way to automate this process without having to reinvent the wheel? It would be great if event classes or event listeners in the codespace will be automatically detected, and the Kafka work will be done in the background?

The event class should be a simple POJO. I could imagine, for example, that it would have to be annotated with an annotation (e.g. @Event) so that it could be found and registered automatically by Spring or Quarkus (I use both frameworks).

During my research, I have already come across Nakadi from Zalando, which comes close to the concept through the defined event types and the events, but event types are not automatically generated from the event classes by the Nakadi clients and I don't want to have any other software (which may slow down the system through HTTP) in between. The web interface is now also deprecated and there is little good documentation / help. I couldn't get it to work myself.

I would be delighted to receive help with my question - or if you could tell me about your solutions for event communication between microservices.

If my request is not understood, please contact me and I will try to answer it as best I can.

0

There are 0 answers