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

相关推荐
千禧皓月4 小时前
【C++】基于C++的RPC分布式网络通信框架(二)
c++·分布式·rpc
教练、我想打篮球5 小时前
05 kafka 如何存储较大数据记录
java·kafka·record
杂家6 小时前
Zookeeper完全分布式部署(超详细)
大数据·分布式·zookeeper
雨点保护雪花7 小时前
15、RabbitMQ
分布式·rabbitmq
Lansonli11 小时前
大数据Spark(七十二):Transformation转换算子repartition和coalesce使用案例
大数据·分布式·spark
hzk的学习笔记12 小时前
Redisson 的 Watchdog 机制
数据库·redis·分布式·缓存
熙客19 小时前
TiDB:分布式关系型数据库
java·数据库·分布式·tidb
Sirius Wu1 天前
Rclone实战技巧
分布式
言之。1 天前
TiDB分布式数据库技术架构概述
数据库·分布式·tidb
老夫的码又出BUG了1 天前
分布式Web应用场景下存在的Session问题
前端·分布式·后端