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了.

相关推荐
菠萝崽.16 分钟前
Elasticsearch进阶篇-DSL
大数据·分布式·elasticsearch·搜索引擎·全文检索·jenkins·springboot
Uranus^37 分钟前
深入解析Spring Boot与Kafka集成:构建高性能消息驱动应用
spring boot·kafka·消息队列·分布式系统
{⌐■_■}38 分钟前
【kafka】kafka概念,使用技巧go示例
golang·kafka·linq
hong_zc1 小时前
服务端高并发分布式结构演进之路
分布式
461K.2 小时前
写spark程序数据计算( 数据库的计算,求和,汇总之类的)连接mysql数据库,写入计算结果
大数据·分布式·spark
却道天凉_好个秋11 小时前
系统架构设计(九):分布式架构与微服务
分布式·架构·系统架构
predisw14 小时前
kafka connect 大概了解
分布式·kafka
计算机毕设定制辅导-无忧学长16 小时前
RabbitMQ 快速上手:安装配置与 HelloWorld 实践(二)
分布式·rabbitmq·ruby
啾啾Fun16 小时前
【Java微服务组件】分布式协调P1-数据共享中心简单设计与实现
java·分布式·微服务
梦想画家20 小时前
Scrapy进阶实践指南:从脚本运行到分布式爬取
分布式·scrapy·数据工程