Ad Code

Ticker

6/recent/ticker-posts

Quarkus- kafka- How to use Apache Kafka inside Quarkus application in simple steps and Verify in Windows Local System using Conductor Dashboard.

In this post we are going use Apache Kafka in Quarkus application in simple steps. 

Prerequisites To complete this example:

We are going to create a new project structure with the right dependencies. Go to https://code.quarkus.io, enter your group id and artifact id. Then in the extension list, select:

SmallRye Reactive Messaging - Kafka Connector

RESTEasy Jackson

Our Application pom file should have these below dependencies:

Here we created a simple class and inject an Emitter, i.e., an object responsible for sending a message to a channel. This emitter is attached to the "words-out" channel (and so will send messages to Kafka).

Next We will Consume the message from the "words-in" channel, uppercase it and send it to the "uppercase" channel. Messages come from the broker.

We will use Reactive Messaging. When you use Reactive Messaging, you send messages to a channel and receive them from another channel. These channels are mapped to the underlying messaging technology by configuration. In our application, we must indicate that our reception and publication channels will use the words Kafka channel. In src/main/resources/application.properties, add the following content.

After having configured the broker location with kafka.bootstrap.servers, we configure our two channels: "words-in" (receiving the records) and "words-out" (publishing the records).

We use the mp.messaging.incoming.words-in prefix to configure the channel. The connector attribute indicates who’s responsible for this channel, here the Kafka connector. As we don't configure the key and value deserializers, here it will take String as Default deserializers.

To configure the outbound movies-out channel, we use the mp.messaging.outgoing.words-out prefix. In addition to indicate who’s responsible for that channel, As we don't configure the key and value serializers, here it will take String as Default serializers.

Next Start Zookeeper zookeeper-server-start.bat C:\kafka_2.12-3.3.1\config\zookeeper.properties


Start Kafkakafka-server-start.bat C:\kafka_2.12-3.3.1\config\server.properties

Next Start the Quarkus Application using command: ./mvnw compile quarkus:dev


Quarkus Application will start and it will get connect to kafka broker running at localhost:9092

Now we will be able to see topic "words" should be created

C:\kafka_2.12-3.3.1\bin\windows>kafka-topics.bat --list --bootstrap-server localhost:9092

__consumer_offsets

test

words

Now Start the kafka consumer console using command : kafka-console-consumer.bat --bootstrap-server localhost:9092 --from-beginning --topic words


The same can be verified using Conduktor Dashboard




Summary:

Congratulations! In this post we have seen How to use Apache Kafka in Quarkus application in simple steps in Windows Local System and verify the kafka topics and messages using Conductor.

GitHub Link : rajivksingh13/teachlea
Please feel free to provide your valuable comments, Thanks.

Post a Comment

0 Comments

Ad Code