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

相关推荐
KmSH8umpK5 小时前
Redis分布式锁从原生手写到Redisson高阶落地,附线上死锁复盘优化方案进阶第八篇
数据库·redis·分布式
KmSH8umpK7 小时前
Redis分布式锁从原生手写到Redisson高阶落地,附线上死锁复盘优化方案进阶第七篇
数据库·redis·分布式
_F_y12 小时前
仿RabbitMQ实现消息队列-服务端核心模块实现(4)
分布式·rabbitmq
Albert Edison16 小时前
【RabbitMQ】发布确认模式(使用案例)
分布式·rabbitmq·ruby
EXnf1SbYK17 小时前
Redis分布式锁进阶第十二篇:全系列终极兜底复盘 + 锁架构巡检落地 + 线上零事故收尾方案
redis·分布式·架构
EXnf1SbYK17 小时前
Redis分布式锁进阶第八篇:锁超时乱序深度踩坑 + 看门狗失效真实溯源 + 业务长耗时标准化兜底方案
数据库·redis·分布式
EXnf1SbYK18 小时前
Redis分布式锁进阶第十一篇
数据库·redis·分布式
biyezuopinvip19 小时前
分布式风电场低电压穿越故障建模与仿真
分布式·matlab·毕业设计·毕业论文·分布式风电场·低电压穿越故障·建模与仿真
苍煜19 小时前
SpringBoot单体应用到分布式下的数据库锁、事务、Redis事务、分布式锁、分布式事务协调
数据库·spring boot·分布式
fengxin_rou19 小时前
黑马点评项目万字总结:从redis基础到实战应用详解
java·开发语言·分布式·后端·黑马点评