kafka发送的字符串长度问题

■□ 微笑 ,只是对人~ 发表于: 2018-05-28   最后更新时间: 2018-05-28 16:02:47   5,811 游览

我在客户端模拟发送一个特别长的字符串,客户端会漏掉一部分。请问这种情况怎么解决,谢谢。

发送的消息如下

{"header":{"msgId":10,"lineId":6},"msgBody":{"a":2,"b":[{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6}]}}

发表于 2018-05-28
添加评论

这个不会吧。你把你要发的消息贴出来 我模拟一下。

我是发送的完整的对象,但是往producer发的时候 总会发送不完整 会丢失部分数据。{"header":{"msgId":10,"lineId":6},"msgBody":{"a":2,"b":[{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6},{"c":6,"d":6,"e":6,"f":6,"g":"a","h":"a","i":"a","j":6,"k":"a","l":"a","m":6,"n":6,"o":6}]}}


对象里边有个b集合 大概有50个对象 。但是评论里回复好像应该写不了那么长的字符 所以一直发不出去。

这样,你用命令来测试发送和消费,看看。先别走客户端

bash kafka-console-producer.sh --broker-list 172.28.11.241:9092,172.28.11.242:9092,172.28.11.243:9092 --sync --topic xxx 我是使用完这个命令后发的数据。 

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

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

用您给的命令还是会出现那种错误,非常感谢您的回答。

上面那个字符串就是你要发的完整消息吗?

我测试是正常的。

上面那个字符串中 msgbody中b集合里我实际发送的大概有50个对象。但是由于评论有字数限制,里边的对象数量较少。

我测试过了,消息没丢。
步骤:
1、先把要发送的消息写到test.txt中。
2、执行发送 bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test < test.txt 
消费者正常拿到全部消息。

好的 ,谢谢您  我测试一下

你的答案

查看kafka相关的其他问题或提一个您自己的问题