• Kafka Configuration with SpringBoot

    Posted by Dipen Chawla | Last Updated: 29-Sep-17

    Kafka is a distributed streaming platform.



    1. It keep running as a group on at least one cluster.


    2. The Kafka group stores surges of records in classes called points.


    3. Each record comprises of a key, an esteem, and a timestamp.


    4. Kafka is quick.


    It performs 2 million transactions per second.This makes it simple to exchange information from page reserve to arrange attachment. Kafka is high throughput frameworks. Kafka works extremely well as a swap for some more conventional message specialist like RabbitMQ, ActiveMQ and so forth.



    There are different benefits of Kafka:








    Installation steps:


    Step 1 — Install Java

    sudo apt-get update

    sudo apt-get install default-jre



    Step 2 — Install ZooKeeper
    sudo apt-get install zookeeperd

    telnet localhost 2181



    Step 3 — Download and Extract Kafka Binaries

    mkdir -p ~/Downloads

    wget "" -O ~/Downloads/kafka.tgz



    Step 4 — Configure Kafka Server

    Open using vi:

    vi ~/kafka/config/

    delete.topic.enable = true



    Step 5 — Start the Kafka Server

    nohup ~/kafka/bin/ ~/kafka/config/ > ~/kafka/kafka.log 2>&1 &

    Configure Kafka with SpringBoot:


    Step1 : Maven Dependency


    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="" xmlns:xsi=""
      <description>Spring Kafka - Consumer Producer Example</description>
        <!-- spring-boot -->
        <!-- spring-kafka -->
          <!-- spring-boot-maven-plugin -->



    Step 2: kafka Sender


    public class Sender {
      private static final Logger LOGGER = LoggerFactory.getLogger(Sender.class);
      private KafkaTemplate<String, String> kafkaTemplate;
      public void send(String topic, String payload) {"sending payload='{}' to topic='{}'", payload, topic);
        kafkaTemplate.send(topic, payload);



    Step 3: kafka consumer


    public class Receiver {
      private static final Logger LOGGER = LoggerFactory.getLogger(Receiver.class);
      private CountDownLatch latch = new CountDownLatch(1);
      public CountDownLatch getLatch() {
        return latch;
      @KafkaListener(topics = "${kafka.topic.helloworld}")
      public void receive(String payload) {"received payload='{}'", payload);