Integrating Kafka with a Helidon MicroProfile Application - Part1

The Apache Kafka has become an industry defacto standard for  all messaging use cases that you may find today for an enterprise application.  In this short post I am sharing a simple application that show cases classic integration of Kafka APIs with a Helidon MicroProfile application. You can checkout the source form here: https://github.com/jobinesh/cloud-native-applications.git

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 source:
  • ClassicKafkaMessageConsumer: This class contains the logic for listening to the Kafka topic. This class uses a custom annotation '@Startup' so that it gets instantiated on application start up. The annotation '@Startup' is provided by io.helidon.examples.mp.spi.StartupInitializerExtension class in this project. To learn more about this extension, read section '16.1. Creating an Extension' in https://docs.jboss.org/weld/reference/latest/en-US/html/extend.html
  • ClassicKafkaMessageProducer: This class contains the logic for publishing messages to the Kafka topic. 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 ClassicKafkaMessageProducer class 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-kafka/README.md

What next ?
Look like it involves bit of boiler plate code to publish messages to Kafka. Well, we are not done yet :) If you are looking for declarative solution for the above usecase with less coding, check out this post:
https://www.jobinesh.com/2020/01/integrating-kafka-with-helidon.html 

Comments

Disclaimer

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