Kafka常用命令操作

Create a topic

Let’s create a topic named “test” with a single partition and only one replica:

> bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test

We can now see that topic if we run the list topic command:

> bin/kafka-topics.sh --list --bootstrap-server localhost:9092

test
Start some messages

Kafka comes with a command line client that will take input from a file or from standard input and send it out as messages to the Kafka cluster. By default, each line will be sent as a separate message.
Run the producer and then type a few messages into the console to send to the server.

> bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test

This is a message
This is another message

Start a consumer

Kafka also has a command line consumer that will dump out messages to standard output.

> bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning

This is a message
This is another message

Understand random characters in the log file of kafka
> bin/kafka-run-class.sh kafka.tools.DumpLogSegments --deep-iteration --print-data-log --files topic/*.log|index|timeindex
Inspect kafka group
> bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group hiway.group.projection --describe -- state
TOPICPARTITIONCURRENT-OFFSETLOG-END-OFFSETLAGCONSUMER-IDHOSTCLIENT-ID
hiway.topic.order0660consumer-21-d8cb9666-2d54-408b-82a6-0480a0b5a10b/172.168.5.9consumer-21
hiway.topic.aps-billing010100consumer-21-fbea0085-d5fa-4645-a2cf-c3b4e9f2837b/172.168.0.7consumer-21
hiway.topic.account023230consumer-15-24e95c62-03f9-4051-8cd0-8b40d691b0c9/172.168.0.7consumer-15
Lookup for assigned of partition
> bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --members --group hiway.group.projection
CONSUMER-IDHOSTCLIENT-ID#PARTITIONS
consumer-27-d56cb0ba-90a8-498a-b019-9f71c6046e03/172.168.0.7consumer-270
consumer-6-cacd38dc-dffb-456c-b0d2-5badbb06f108/172.168.0.7consumer-60
consumer-24-ba6ef6b7-d0fe-4104-a0e9-5bcda354cda8/172.168.0.7consumer-241
consumer-21-d8cb9666-2d54-408b-82a6-0480a0b5a10b/172.168.5.9consumer-211
consumer-21-fbea0085-d5fa-4645-a2cf-c3b4e9f2837b/172.168.0.7consumer-211

关注公众号:JAVA九点半课堂,回复【资料】获取2T最新技术资料,每天还有技术分享,我们一起进步,谢谢!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值