Get the App
SLTechnology News&Howtos  ›  Servers  › 

Implementation of Docker deployment Kafka and Spring Kafka

Shulou Source: shulou.com Published: 2022-06-01 20:17:25 09月23日 Update

This article will explain in detail the implementation of Docker deployment Kafka and Spring Kafka. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.

View the docker-compose.yml in the usage document

Because kafka is used with zookeeper, zookeeper is included in the document

I changed the version number and variable parameters.

These two parameters seem to be exposed to public network access (answers found from other blogs, cannot be connected if you don't set spring kafka)

Run the command docker-compose up-d and two containers will be opened

Enter the kafka container and use the guide on the official website to test http://kafka.apache.org/quickstart.

Docker exec-it {Container id&name} / bin/bash

After entering the container, enter the command directory cd / opt/kafka/bin/

Step 1: create a new topic

Kafka-topics.sh-- create-- bootstrap-server 192.168.17.165 partitions 9092-- replication-factor 1-- partitions 1-- topic mytest (localhost changed to its own ip number)

Step 2: send a message: kafka-console-producer.sh-- broker-list 192.168.17.165-topic mytest

Step 3: open another window for consumption information: kafka-console-consumer.sh-- bootstrap-server 192.168.17.165-from-beginning-- topic mytest-- from-beginning

It means that it has been built successfully.

Start building Spring Kafka

Pom.xml:

Configure producer Config:

Configure Consumer Config

The relevant configuration comes from the spring official website kafka document: https://docs.spring.io/spring-kafka/docs/2.3.1.RELEASE/reference/html/

Send a message after creating a Controller request

Configure snooping:

Using @ KafkaListener annotations, all documents have relevant instructions, so they will not be explained one by one

Run project, and then request url to view the log:

This is the end of the implementation of Docker deployment Kafka and Spring Kafka. I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Containers documents configuration information content parameters commands articles more knowledge articles consumption not bad success two blogs variables guides logs comments Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia MariaDB OPPO Reno Shulou Information Microsoft