Table of contents
1. Kafka cluster deployment
- Kafka cluster deployment reference lz this blog post link: https://wwwxz.blog.csdn.net/article/details/129804602
Two, three server information
- three servers
name of server server ip centos7 virtual machine 1 192.168.136.27 centos7 virtual machine 2 192.168.136.28 centos7 virtual machine 3 192.168.136.29
3. Producer command line operation
3.1. View the example of operating producer command parameters
-
View operation producer command parameters
[root@localhost kafka-3.0.0]# bin/kafka-console-producer.sh
3.2. View the detailed explanation of the command parameters of the operation producer
-
Detailed Explanation of Producer Command Parameters
parameter describe –bootstrap-server <String: server toconnect to> The connected Kafka Broker host name and port number. –topic <String: topic> The topic name of the operation.
3.3. Example of producer sending message
-
Create a news topic
[root@localhost kafka-3.0.0]# bin/kafka-topics.sh --bootstrap-server 192.168.136.28:9092 --create --partitions 1 --replication-factor 3 --topic news
-
Producers send messages to the news topic
[root@localhost kafka-3.0.0]# bin/kafka-console-producer.sh --bootstrap-server 192.168.136.28:9092 --topic news >hello world >this is a news topic
4. Consumer command line operation
4.1. View an example of operating consumer command parameters
-
View operation consumer command parameters
[root@localhost kafka-3.0.0]# bin/kafka-console-consumer.sh
4.2. View the detailed explanation of the operation consumer command parameters
-
Detailed Explanation of Consumer Order Parameters
parameter describe –bootstrap-server <String: server toconnect to> The connected Kafka Broker host name and port number. –topic <String: topic> The topic name of the operation. –from-beginning Consume from scratch. -group <String: consumer group id> Specify the consumer group name.
4.3. Example of data in consumer consumption news topic
-
Data in the Consumer News (news) topic
[root@localhost kafka-3.0.0]# bin/kafka-console-consumer.sh --bootstrap-server 192.168.136.28:9092 --topic news
-
Producer sends abcdef message to news topic
[root@localhost kafka-3.0.0]# bin/kafka-console-producer.sh --bootstrap-server 192.168.136.28:9092 --topic news >hello world >this is a news topic >abcdef >
-
Consumers check the data in the news (news) topic, whether it can be received
[root@localhost kafka-3.0.0]# bin/kafka-console-consumer.sh --bootstrap-server 192.168.136.28:9092 --topic news abcdef
4.4. An example of consumer consumption of all data (including historical data) in the topic of news
-
Consumers consume all the data in the news topic (including historical data)
[root@localhost kafka-3.0.0]# bin/kafka-console-consumer.sh --bootstrap-server 192.168.136.28:9092 --topic news --from-beginning