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 小时前
RabbitMQ 通过HTTP API删除队列命令
分布式·http·rabbitmq
周某某~4 小时前
windows安装RabbitMQ
分布式·rabbitmq
Bug退退退1234 小时前
RabbitMQ 高级特性之消息确认
java·分布式·rabbitmq
一只程序汪7 小时前
【如何实现分布式压测中间件】
分布式·中间件
William一直在路上8 小时前
主流分布式中间件及其选型
分布式·中间件
茫茫人海一粒沙8 小时前
理解 Confluent Schema Registry:Kafka 生态中的结构化数据守护者
分布式·kafka
weixin_438335408 小时前
分布式定时任务:Elastic-Job-Lite
分布式·elasticjoblite
dessler11 小时前
Kafka-消费者(Consumer)和消费者组(Consumer Group)
linux·运维·kafka
hjs_deeplearning12 小时前
认知篇#10:何为分布式与多智能体?二者联系?
人工智能·分布式·深度学习·学习·agent·智能体
小毛驴85012 小时前
Windows 环境下设置 RabbitMQ 的 consumer_timeout 参数
windows·分布式·rabbitmq