Kafka-Streams with Spring-Boot | Part1

In this blog, we would see, how can we leverage the Kafka-Streams along with Spring-Boot.

Step #1.) Let’s first start our confluent services at our local :-

Step #2.) Now, we can open the control-centre and create a new topic named : “test-topic” :-

Step #3.) Now, we can now start producing the data into Kafka-topic :-

Step #4.) Now, we can now start consuming the data from Kafka-topic :-

Step #5.) Next, we begin with out streams application. Let’s first create the properties file :-

Spring Cloud offers us a bunch of binder technologies. We can use Apache Kafka, RabbitMQ, Amazon Kinesis, Google PubSub, Azure Event Hubs, and many more. In this blog, we shall focus on Apache Kafka. Spring cloud offers us two types of Kafka Binders.

In this course, we will be focusing on Kafka Streams Binder. We are setting Kafka broker hostname and port so the application can connect to the Kafka Cluster. We are also setting the message key and value types. Since, we are expecting a string Key and a string value, so we are setting StringSerde for both. StringSerde is the type of message key and value for now.

Step #6.) Next, we begin to create an Interface to define the input/output bindings. We have named it as KafkaListenerBinding. The primary purpose of this interface is to define input and output bindings. We want to listen to an input topic. The input channel(defined in properties) must be picked up by the Spring Cloud framework and bind to the “users” Kafka topic. So, we defined a binding interface and linked the input channel using the @Input annotation.

Here is current-version of Spring-cloud being defined with us :-

Just to avoid the deprecation-warning, let’s lower our spring-cloud version to a stable and industry-adopted version i.e. Hoxton.SR9.

Step #7.) Next step, we move on to the KafkaListenerService. The @EnableBinding will trigger the Spring Cloud framework. Now, the Spring Cloud framework will implement the Binding interface and create a Kafka Stream. You can listen to the stream using a listener method. So, listener method will receive the input stream, and I am sending it to the log.

That’s all in this blog. We shall see you in next post with some more details.

References :-

--

--

Software Engineer for Big Data distributed systems

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store