Jsh0s
Jsh0s

Reputation: 599

How to create a persistent connection to Kafka through Spring Boot web application

Please excuse the ambiguity as I'm trying to be as clear as possible with the little knowledge that I have.

We have a Kafka cluster and the idea is to have a Spring Boot application to serve as the bridge between the Producers, Consumers and Kafka.

I've worked with simple REST, CRUD applications, in which I basically interact with the server on a request basis.


Question:

How do I go about creating a persistent connection between Spring and Kafka to send and receive messages?

Does the protocol matter?

Upvotes: 1

Views: 1035

Answers (2)

Ervin Szilagyi
Ervin Szilagyi

Reputation: 16815

Kafka uses its own binary protocol over TCP for publishing messages to topics for polling messages with subscriptions. For being able to connect to a Kafka cluster from a Spring Boot project, you may want to use spring-kafka which provides an implementation for this protocol:

<dependency>
  <groupId>org.springframework.kafka</groupId>
  <artifactId>spring-kafka</artifactId>
  <version>2.8.0</version>
</dependency>

A minimalist set-up for a publisher and a consumer can be found in the official spring-kafka docs.

Upvotes: 2

Sagar
Sagar

Reputation: 61

I understand you wan to create a producer and consumer on a Kafka topic. Have you checked https://www.baeldung.com/spring-cloud-stream

Upvotes: 1

Related Questions