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

相关推荐
需要8261 小时前
分布式 ID 生成:雪花算法、号段模式与时钟回拨
分布式·算法
灯澜忆梦5 小时前
【RabbitMQ #11】 | 消费者可靠性
分布式·rabbitmq·ruby
灯澜忆梦6 小时前
【RabbitMQ #9】 | 生产者可靠性
分布式·rabbitmq
此时不提桶,更待何时8 小时前
06-09-A-Kafka架构与存储原理详解
架构·kafka·linq
银河技术8 小时前
TB级文本去重实战:从单机 OOM 到 Spark / Ray 分布式架构的工程演进
分布式·微服务·重构·架构·spark·llm·rag
deepdata_cn9 小时前
从集中式到分布式:Data Mesh颠覆传统数据架构的底层逻辑
分布式·data mesh
5008410 小时前
React Native for OpenHarmony 实战:三方库 react-native-device-uptime 的鸿蒙化适配指南
javascript·分布式·react native·react.js·harmonyos
灯澜忆梦17 小时前
【RabbitMQ #10】 | MQ可靠性
分布式·rabbitmq
醉颜凉19 小时前
Kafka 与 RabbitMQ/RocketMQ 选型对比:场景匹配、性能基准与迁移成本
kafka·消息队列·rabbitmq·rocketmq·中间件选型
逐流人21 小时前
Ceph分布式存储集群配置与池管理:从配置优先级到PG、复本池与纠删码池
运维·分布式·ceph·云原生·云计算·rados