kafka中 FailedToSendMessageException解决
博客专区 > JerryYux 的博客 > 博客详情
kafka中 FailedToSendMessageException解决
JerryYux 发表于3年前
kafka中 FailedToSendMessageException解决
  • 发表于 3年前
  • 阅读 25204
  • 收藏 3
  • 点赞 0
  • 评论 4

标题:腾讯云 新注册用户域名抢购1元起>>>   

摘要: 运行kafka官网上demo时遇到的问题解决办法;

这两天在学kafka,把官网上的demo部署到自己的虚拟机上运行,正常;

然后部署到公司的研发线主机上,发现producer一直无法发送消息;

部分错误日志如下:

[2014-11-13 09:58:09,660] WARN Error while fetching metadata [{TopicMetadata for topic mor ->
No partition metadata for topic mor due to kafka.common.LeaderNotAvailableException}] for topic [mor]: class kafka.common.LeaderNotAvailableException  (kafka.producer.BrokerPartitionInfo)
[2014-11-13 09:58:09,660] ERROR Failed to send requests for topics mor with correlation ids in [17,24] (kafka.producer.async.DefaultEventHandler)
[2014-11-13 09:58:09,660] ERROR Error in handling batch of 17 events (kafka.producer.async.ProducerSendThread)
kafka.common.FailedToSendMessageException: Failed to send messages after 3 tries.
        at kafka.producer.async.DefaultEventHandler.handle(DefaultEventHandler.scala:90)
        at kafka.producer.async.ProducerSendThread.tryToHandle(ProducerSendThread.scala:104)
        at kafka.producer.async.ProducerSendThread$$anonfun$processEvents$3.apply(ProducerSendThread.scala:87)
        at kafka.producer.async.ProducerSendThread$$anonfun$processEvents$3.apply(ProducerSendThread.scala:67)
        at scala.collection.immutable.Stream.foreach(Stream.scala:526)
        at kafka.producer.async.ProducerSendThread.processEvents(ProducerSendThread.scala:66)
        at kafka.producer.async.ProducerSendThread.run(ProducerSendThread.scala:44)

操作步骤完全一样,只是在研发线上修改了zookeeper的监听端口,输入命令时也是按照对应的端口输入的,所以不是参数有问题导致的;

对比了研发线和虚拟机上的配置,发现除了这个端口之外,没有区别;

鼓捣了一天,没找到问题出在哪里;

第二天来上班,把server.properties文件里

#host.name=localhost

的注释去掉,然后运行,发现问题解决了;

(但是在虚拟机里明明没有修改这个东西也是可以正常运行的;

怀疑是发行版不同,一些内部的配置有区别导致的;

虚拟机:

Distributor ID:    Ubuntu
Description:    Ubuntu 14.04.1 LTS
Release:    14.04
Codename:    trusty

研发线:

LSB Version:    :
Distributor ID: RedHatEnterpriseServer
Description:    Red Hat Enterprise Linux Server release 5.4 (Tikanga)
Release:        5.4
Codename:       Tikanga

)



在解决问题的过程中,还发现其他的问题,但是目前没发现影响运行;

就是zookeeper和broker跑起来之后,创建producer,创建话题,创建Consumer,的时候,zookeeper都会报异常,部分记录如下:


[2014-11-13 09:12:13,486] INFO Got user-level KeeperException when processing sessionid:0x149a6b3e36c0001 type:setData cxid:0x3 zxid:0xfffffffffffffffe txntype:unknown reqpath:n/a Error Path:/config/topics/morning Error:KeeperErrorCode = NoNode for /config/topics/morning (org.apache.zookeeper.server.PrepRequestProcessor)

[2014-11-13 09:12:13,506] INFO Got user-level KeeperException when processing sessionid:0x149a6b3e36c0001 type:create cxid:0x4 zxid:0xfffffffffffffffe txntype:unknown reqpath:n/a Error Path:/config/topics Error:KeeperErrorCode = NodeExists for /config/topics (org.apache.zookeeper.server.PrepRequestProcessor)

[2014-11-13 09:12:13,535] INFO Processed session termination for sessionid: 0x149a6b3e36c0001 (org.apache.zookeeper.server.PrepRequestProcessor)

[2014-11-13 09:19:50,958] INFO Got user-level KeeperException when processing sessionid:0x149a6bbeaf50000 type:create cxid:0x4 zxid:0xfffffffffffffffe txntype:unknown reqpath:n/a Error Path:/brokers Error:KeeperErrorCode = NoNode for /brokers (org.apache.zookeeper.server.PrepRequestProcessor)
[2014-11-13 09:19:50,982] INFO Got user-level KeeperException when processing sessionid:0x149a6bbeaf50000 type:create cxid:0xa zxid:0xfffffffffffffffe txntype:unknown reqpath:n/a Error Path:/config Error:KeeperErrorCode = NoNode for /config (org.apache.zookeeper.server.PrepRequestProcessor)
[2014-11-13 09:19:50,998] INFO Got user-level KeeperException when processing sessionid:0x149a6bbeaf50000 type:create cxid:0x10 zxid:0xfffffffffffffffe txntype:unknown reqpath:n/a Error Path:/admin Error:KeeperErrorCode = NoNode for /admin (org.apache.zookeeper.server.PrepRequestProcessor)
[2014-11-13 09:19:51,295] INFO Got user-level KeeperException when processing sessionid:0x149a6bbeaf50000 type:setData cxid:0x19 zxid:0xfffffffffffffffe txntype:unknown reqpath:n/a Error Path:/controller_epoch Error:KeeperErrorCode = NoNode for /controller_epoch (org.apache.zookeeper.server.PrepRequestProcessor)
[2014-11-13 09:19:51,374] INFO Got user-level KeeperException when processing sessionid:0x149a6bbeaf50000 type:delete cxid:0x27 zxid:0xfffffffffffffffe txntype:unknown reqpath:n/a Error Path:/admin/preferred_replica_election Error:KeeperErrorCode = NoNode for /admin/preferred_replica_election (org.apache.zookeeper.server.PrepRequestProcessor)

[2014-11-13 10:31:50,651] INFO Got user-level KeeperException when processing sessionid:0x149a6bbeaf5001a type:setData cxid:0x19 zxid:0xfffffffffffffffe txntype:unknown reqpath:n/a Error Path:/consumers/test-consumer-group/offsets/mor/0 Error:KeeperErrorCode = NoNode for /consumers/test-consumer-group/offsets/mor/0 (org.apache.zookeeper.server.PrepRequestProcessor)
[2014-11-13 10:31:50,661] INFO Got user-level KeeperException when processing sessionid:0x149a6bbeaf5001a type:create cxid:0x1a zxid:0xfffffffffffffffe txntype:unknown reqpath:n/a Error Path:/consumers/test-consumer-group/offsets Error:KeeperErrorCode = NoNode for /consumers/test-consumer-group/offsets (org.apache.zookeeper.server.PrepRequestProcessor)


一开始producer无法发送消息,以为是和这些异常有关,但是在虚拟机里运行的时候,同样出现这些异常,但是也没有影响producer发送消息;

在网上查了半天,有人说是不正确关闭zookeeper和server的原因,有人说是没有删除/tmp下的zookeeper日志和kafka日志的原因,

总之,我试了上面提到的方法,还是报这些异常;

如果有哪位仁兄知道这些异常是什么原因引起的,请告诉我,十分感谢;



另外,从本机运行java代码的Consumer连接研发线的时候,连接迅速被关闭了,收不到producer发来的消息;

原因是配置的超时时间太短,zookeeper没有读完Consumer的数据,连接就被Consumer断开了,部分日志如下:

[2014-11-13 10:28:47,989] INFO Accepted socket connection from /192.168.50.33:2676 (org.apache.zookeeper.server.NIOServerCnxn)
[2014-11-13 10:28:47,989] WARN EndOfStreamException: Unable to read additional data from client sessionid 0x0, likely client has closed socket (org.apache.zookeeper.server.NIOServerCnxn)


解决办法,就是把配置里的超时时间配置的长点儿,如下:

props.put("zookeeper.session.timeout.ms", "400000");



对了,还有个问题,kafka官网上关于java版producer部分的代码,有个地方写的不是很明确,如下:

props.put("metadata.broker.list", "broker1:9092,broker2:9092");
 

broker1和broker2代表broker对应的hostname,而不是broker的id.正确示例如下:

 props.put("metadata.broker.list", "localhost:9092,localhost:9093");


共有 人打赏支持
粉丝 4
博文 15
码字总数 8418
评论 (4)
CCLL
您好!请问您这个问题解决了吗?[2014-11-13 10:31:50,661] INFO Got user-level KeeperException when processing sessionid:0x149a6bbeaf5001a type:create cxid:0x1a zxid:0xfffffffffffffffe txntype:unknown reqpath:n/a Error Path:/consumers/test-consumer-group/offsets Error:KeeperErrorCode = NoNode for /consumers/test-consumer-group/offsets (org.apache.zookeeper.server.PrepRequestProcessor)
怎么解决的?能够告知一下吗?
JerryYux

引用来自“CCLL”的评论

您好!请问您这个问题解决了吗?[2014-11-13 10:31:50,661] INFO Got user-level KeeperException when processing sessionid:0x149a6bbeaf5001a type:create cxid:0x1a zxid:0xfffffffffffffffe txntype:unknown reqpath:n/a Error Path:/consumers/test-consumer-group/offsets Error:KeeperErrorCode = NoNode for /consumers/test-consumer-group/offsets (org.apache.zookeeper.server.PrepRequestProcessor)
怎么解决的?能够告知一下吗?
一直没解决,后来这个东西也没有确定是否替代生产环境中的memcache;然后我就离职了;
ericquan8

引用来自“CCLL”的评论

您好!请问您这个问题解决了吗?[2014-11-13 10:31:50,661] INFO Got user-level KeeperException when processing sessionid:0x149a6bbeaf5001a type:create cxid:0x1a zxid:0xfffffffffffffffe txntype:unknown reqpath:n/a Error Path:/consumers/test-consumer-group/offsets Error:KeeperErrorCode = NoNode for /consumers/test-consumer-group/offsets (org.apache.zookeeper.server.PrepRequestProcessor)
怎么解决的?能够告知一下吗?
这不是错误,是zk正常的日志信息,原因是zk自己删除不存在的节点导致的。如果你不喜欢看到,可以调整zk日志级别。
xiao艾24716
org.apache.kafka.common.errors.TimeoutException: Batch expired
原因:Flume与Kafka连接时,Kafka回送集群信息,以hostname返回,本地无法识别
解决:Flume配置hosts文件
×
JerryYux
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: