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

相关推荐
用户3610588626122 小时前
Kafka写数据入口:消息进了Broker之后交给谁
大数据·kafka
我不会起名字3224 小时前
对象存储架构:直传签名、分片断点与防盗链的 4 个取舍
分布式·对象存储·oss·架构设计·s3
Pniubi5 小时前
Kafka和Zookeeper、KRaft
分布式·zookeeper·kafka
Pniubi1 天前
Kafka在CDC增量迁移数据库中的作用
分布式·kafka
安易算力1 天前
昇腾生态深度实践:CANN算子开发与MindSpore分布式部署优化
分布式
Regulus-Moon2 天前
Quorum:用一个不等式换掉分布式锁
数据结构·论文阅读·分布式·算法·系统架构
Lansonli3 天前
大数据Spark(九十五):Spark Shuffle 参数调优全解析
大数据·分布式·spark
Nefu_lyh4 天前
【Spark】05Spark 数据读取与保存:文件格式、文件系统与结构化数据
大数据·分布式·spark
云边有个稻草人4 天前
集中式与分布式怎么选?谈谈金仓数据库的架构取舍
分布式·国产数据库·架构选型·金仓数据库·集中式数据库·企业级数据库·核心业务系统
东风微鸣4 天前
QuePaxa VS Raft:广域网共识,为什么「慢但不停」胜过「快但一抖就死」
分布式·云原生·raft