Integrating Kafka with a Helidon MicroProfile Application - Part 2

Recently I posted a very short article on using Kafka along with a Helidon MicroProfile application: https://www.jobinesh.com/2020/01/using-kafka-with-helidon-microprofile.html. It was using classic Kafka APIs and involved more manual coding. In this post, let us see how to build the same messaging solution declaratively availing the Reactive Messaging offering of MicroProfile specification. Uhh...Did I say less coding and more fun :)

What is MicroProfile Reactive Messaging?
The following doc may answer all your questions: https://smallrye.io/smallrye-reactive-messaging/ Another interesting blog post on this topic is here: https://dzone.com/articles/using-jakarta-eemicroprofile-to-connect-to-apache. We use the same constructs with a Helidon MP application in this example.

What is the usecase exercised in this example ?
It is simple :) We use the a simple greeting REST API  to exercise the Kafka messaging feature. When a client updates the greeting message, the Greeting resource implementation will publish the new greeting message to Kafka topic for use by interested parties(consumers)


Who does what?
Here is quick summary of the classes that you find in the example application:

RxMessagingKafkaConsumer: This class listens to the Kafka topic using the MicroProfile Reactive Messaging declarative constructs.
RxMessagingKafkaProducer:  This class publishes messages to the Kafka topic using the MicroProfile Reactive Messaging declarative constructs. It is used by GreetResource class.
GreetResource: This is the REST resource implementation used in this example. When updateGreeting method is called
via REST PUT operation, the new greeting sent by client is sent to Kafka queue for consumption by the Kafka consumers. See the method updateGreeting() in GreetResource class to learn the usage of RxMessagingKafkaProducer APIs in order to publish message to topic.
microprofile-config.properties: This config file holds the Kafka configuration used in this example

How to run this example?
All instructions are available here: https://github.com/jobinesh/cloud-native-applications/blob/master/helidon-example-mp-rx-msg-kafka/README.md

Comments

  1. Nice reading, I love your content. This is really a fantastic and informative post. Keep it up and if you are looking for Serp Api then visit SERPHouse.

    ReplyDelete

Post a Comment

Disclaimer

The views expressed on this blog are my own and do not necessarily reflect the views of my employer.