Docker deployment of Kafka and Spring Kafka implementation

Docker deployment of Kafka and Spring Kafka implementation

This article mainly introduces the deployment of Kafka with Docker and the implementation of Spring Kafka. The sample code in this article is very detailed and has a certain reference value for everyone's study or work. Friends in need can refer to it.

Find kafka from https://hub.docker.com/

The third one is active and has more stars. Go in and see how to use it.

We use docker-compose to build the image

See the docker-compose.yml file in the documentation

Because Kafka is used with Zookeeper, the document includes Zookeeper

I modified the version number and variable parameters

These two parameters seem to be exposed to external network access (the answer found from other blogs is that if spring kafka is not set, it will not be able to connect)

Run the command docker-compose up -d to start two containers.

Enter the Kafka container and use the official website guide 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:9092 --replication-factor 1 --partitions 1 --topic mytest (change localhost to your own IP number)

Step 2: Send information: kafka-console-producer.sh --broker-list 192.168.17.165:9092 --topic mytest

Step 3: Open another window to consume information: kafka-console-consumer.sh --bootstrap-server 192.168.17.165:9092 --topic mytest --from-beginning

It means the build has been successful.

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 information after creating a Controller request

Configure the listener:

Use the @KafkaListener annotation. The documentation has relevant instructions, so I won’t explain them one by one.

Run the project, then request the URL to view the log:

The configuration is successful.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Analysis of how to use Spring Boot cluster management tool KafkaAdminClient
  • Spring boot integration kafka process analysis
  • Spring pure Java configuration integrated kafka code example
  • Detailed explanation of Kafka configuration parameters in Spring Kafka
  • Sample code for integrating Springboot with Kafka to implement producer and consumer
  • Sample code for integrating Kafka with Spring Boot
  • Sample code for integrating Kafka+Storm with Spring boot
  • Springboot 1.5.7 integrated Kafka-client code example

<<:  jQuery+Ajax to achieve simple paging effect

>>:  Installation and use of mysql on Ubuntu (general version)

Recommend

Detailed process of FastAPI deployment on Docker

Docker Learning https://www.cnblogs.com/poloyy/p/...

Basic usage examples of listeners in Vue

Table of contents Preface 1. Basic usage of liste...

Summary of MySQL lock related knowledge

Locks in MySQL Locks are a means to resolve resou...

Tutorial on installing and configuring MySql5.7 in Alibaba Cloud ECS centos6.8

The default MySQL version under the Alibaba Cloud...

CentOS 7.9 installation and configuration process of zabbix5.0.14

Table of contents 1. Basic environment configurat...

Example of how to identify the user using a linux Bash script

It is often necessary to run commands with sudo i...

How to view available network interfaces in Linux

Preface The most common task after we install a L...

Detailed explanation of Vue's monitoring properties

Table of contents Vue monitor properties What is ...

Advantages and disadvantages of common MySQL storage engines

Table of contents View all storage engines InnoDB...

MySQL Optimization Summary - Total Number of Query Entries

1. COUNT(*) and COUNT(COL) COUNT(*) usually perfo...

In-depth understanding of CSS @font-face performance optimization

This article mainly introduces common strategies ...

How to install PostgreSQL and PostGIS using yum on CentOS7

1. Update the yum source The PostgreSQL version o...

Detailed analysis of classic JavaScript recursion case questions

Table of contents What is recursion and how does ...