kafka

昨天用kafka传文件的时候,发现有一条数据,一直传不进kafka,然后一直在重试,导致一直增加,于是把kafka停了,重新配置kafka选项。

broker参数里(server.properties)  配置两个字段:

replica.fetch.max.bytes =4097152    //每次获取数据的最大字节数
message.max.bytes =2000000   //消息体的最大容量,单位是B

在consumer.properties里配置

fetch.message.max.bytes=9097152 //单位为B   consumer复制消息的最大内存

  

设置完重启,消息可以进kafka,但是消费端读不出这条消息,会提示说

found a message larger than the maximum fetch size of this consumer on topic xyz partition 0 at fetch offset 29. Increase the fetch size, or decrease the maximum message size the broker will allow.

看起来是consumer的配置没有更新,提示很明显,要么减小kafka能接受的大小,要么增加consumer能接受的大小,又去到处找百度找bing,终于发现了神奇的地方,在起consumer的时候,需要加上--consumer.config  config/consumer.properties   才能读配置项,不然就是用的是默认配置项,完整命令行如下

bin/kafka-console-consumer.sh --zookeeper kg2:2181 --topic jydb-topic  --consumer.config config/consumer.properties 

 

 

下面是一些常用的kafka命令

 

删除某个topic

bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic test

创建某个topic

bin/kafka-topics.sh --create --topic test --replication-factor 1 --partitions 1 --zookeeper kg1:2181  

查看topic列表

bin/kafka-topics.sh --list --zookeeper kg1:2181

生产者

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

消费者(建议不要用 --from-beginning)

bin/kafka-console-consumer.sh --zookeeper kg1:2181 --topic test --from-beginning

  

posted @ 2017-08-11 09:22  猪是得念来过倒  阅读(190)  评论(0)    收藏  举报