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

相关推荐
小北方城市网10 小时前
分布式锁实战指南:从选型到落地,避开 90% 的坑
java·数据库·redis·分布式·python·缓存
范桂飓12 小时前
大模型分布式训练框架 Megatron-LM
人工智能·分布式
oMcLin15 小时前
如何在Debian 11上通过配置MySQL 8.0的分布式架构,提升跨区域数据同步的效率与延迟?
分布式·mysql·debian
一条咸鱼_SaltyFish16 小时前
[Day15] 若依框架二次开发改造记录:定制化之旅 contract-security-ruoyi
java·大数据·经验分享·分布式·微服务·架构·ai编程
IT 行者18 小时前
Spring Security 7 OAuth2 授权码分布式存储之Redis存储方案
redis·分布式·spring
潇凝子潇18 小时前
kafka之监控告警
分布式·kafka
Light6019 小时前
从“报告”到“能力”——构建智能化、可审计的数据治理闭环——领码 SPARK 数据质量平台白皮书
大数据·分布式·spark
maozexijr19 小时前
RabbitMQ Exchange Headers类型存在的意义?
分布式·rabbitmq
还在忙碌的吴小二19 小时前
XXL-SSO 分布式单点登录框架
分布式
独自破碎E19 小时前
RabbitMQ的消息确认机制是怎么工作的?
分布式·rabbitmq