Kafka官方生产者和消费者脚本简单使用

问题

怎样使用Kafka官方生产者和消费者脚本进行消费生产和消费?这里假设已经下载了kafka官方文件,并已经解压.

生产者配置文件

producer_hr.properties

bash 复制代码
bootstrap.servers=10.xx.xx.xxx:9092,10.xx.xx.xxx:9092,10.xx.xx.xxx:9092
compression.type=none
security.protocol=SASL_PLAINTEXT
sasl.mechanism=SCRAM-SHA-256
sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required username="myname" password="mypassword";

消费者配置文件

consumer_hr.properties

bash 复制代码
bootstrap.servers=10.xx.xx.xxx:9092,10.xx.xx.xxx:9092,10.xx.xx.xxx:9092
group.id=my_consume_group_id
security.protocol=SASL_PLAINTEXT
sasl.mechanism=SCRAM-SHA-256
sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required username="myname" password="mypassword";

生产者脚本使用

bash 复制代码
./bin/kafka-console-producer.sh --bootstrap-server 10.xx.xx.xxx:9092,10.xx.xx.xxx:9092,10.xx.xx.xxx:9092 --producer.config ./config/producer_hr.properties --topic my_topic

消费者脚本使用

bash 复制代码
./bin/kafka-console-consumer.sh --bootstrap-server 10.xx.xx.xxx:9092,10.xx.xx.xxx:9092,10.xx.xx.xxx:9092 --consumer.config ./config/consumer_hr.properties --topic my_topic

总结

这就可以见到测试kafka对应topic了.

相关推荐
東雪蓮☆3 小时前
Filebeat+Kafka+ELK 日志采集实战
分布式·elk·kafka
努力买辣条3 小时前
KafKa概念与安装
分布式·kafka
不太可爱的叶某人5 小时前
【学习笔记】kafka权威指南——第8章 跨集群数据镜像(7-10章只做了解)
笔记·学习·kafka
Lansonli7 小时前
大数据Spark(六十七):Transformation转换算子distinct和mapValues
大数据·分布式·spark
失散1312 小时前
分布式专题——35 Netty的使用和常用组件辨析
java·分布式·架构·netty
奔跑吧邓邓子13 小时前
【C++实战(78)】解锁C++ 大数据处理:从并行到分布式实战
c++·分布式·实战·并发·大数据处理
Jolie_Liang13 小时前
证券业智能化投研与分布式交易系统架构:全球发展现状、技术创新与未来趋势研究
分布式·系统架构
2301_7720935614 小时前
tuchuang_myfiles&&share文件列表_共享文件
大数据·前端·javascript·数据库·redis·分布式·缓存
gsfl19 小时前
Redis分布式锁
数据库·redis·分布式
岁岁岁平安1 天前
分布式系统相关概念(单体、集群、分布式、分布式集群、微服务)
分布式·微服务