kafka.common.FailedToSendMessageException: Failed to send messages after 3 tries. 最无语的配置
注意: 本文不谈废话,低级问题请自行检查。
我使用Java版本的Kafka Producer生产数据,但是抛出了这个异常。百思不得其解,明明防火墙配置,ZooKeeper,Kafka配置都是没问题的啊。
困扰了我一天,最终发现这样一个问题: kafka.common.FailedToSendMessageException: Failed to send messages after 3 tries.
Kafka的server.properties文件中IP不能写主机名,必须写IP地址而不能写映射后的主机名.

如果你在这写的是hostname,例如bigdata:


跑一个Producer程序,你就会喜提Exception:

但是如果改成IP地址:

程序就能正常运行:

我用的版本是Kafka 0.8 ,果然版本低还是BUG太多。浪费了不少时间。
我的生产者代码:
import kafka.javaapi.producer.Producer;
import kafka.producer.KeyedMessage;
import kafka.producer.ProducerConfig; import java.util.Date;
import java.util.Properties;
import java.util.Random; public class TestProducer {
public static void main(String[] args) {
long events = 10;
Random rnd = new Random(); Properties props = new Properties();
props.put("metadata.broker.list", "192.168.29.132:9092");
props.put("serializer.class", "kafka.serializer.StringEncoder");
props.put("partitioner.class", "SimplePartitioner");
props.put("request.required.acks", "1"); ProducerConfig config = new ProducerConfig(props); Producer<String, String> producer = new Producer<String, String>(config); for (long nEvents = 0; nEvents < events; nEvents++) {
long runtime = new Date().getTime();
String ip = "192.168.2." + rnd.nextInt(255);
String msg = runtime + ",www.example.com," + ip;
KeyedMessage<String, String> data = new KeyedMessage<String, String>("advClickStreamTopic", ip, msg);
producer.send(data);
}
producer.close();
}
}
import kafka.producer.Partitioner;
import kafka.utils.VerifiableProperties; public class SimplePartitioner implements Partitioner {
public SimplePartitioner (VerifiableProperties props) { } public int partition(Object key, int a_numPartitions) {
int partition = 0;
String stringKey = (String) key;
int offset = stringKey.lastIndexOf('.');
if (offset > 0) {
partition = Integer.parseInt( stringKey.substring(offset+1)) % a_numPartitions;
}
return partition;
} }
我在JIRA上并没找到相关BUG。.... 只能说有点坑
版本信息:
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-reflect</artifactId>
<version>2.10.0</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.9.2-RC3</version>
</dependency> <dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.9.2</artifactId>
<version>0.8.1.1</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>jmxri</artifactId>
<groupId>com.sun.jmx</groupId>
</exclusion>
<exclusion>
<artifactId>jms</artifactId>
<groupId>javax.jms</groupId>
</exclusion>
<exclusion>
<artifactId>jmxtools</artifactId>
<groupId>com.sun.jdmk</groupId>
</exclusion>
</exclusions>
</dependency>
kafka.common.FailedToSendMessageException: Failed to send messages after 3 tries. 最无语的配置的更多相关文章
- kafka.common.FailedToSendMessageException: Failed to send messages after 3 tries.
今天在写kafka生产者生成数据的程序并运行时,报如下错误: log4j:WARN No appenders could be found for logger (kafka.utils.Verifi ...
- Thread-0" kafka.common.FailedToSendMessageException: Failed to send messages after 3 tries.
http://blog.csdn.net/jingshuigg/article/details/25001979 zookeeper.connect=localhost:2181改成zookeeper ...
- kafka Failed to send messages after 3 tries 问题解决
kafka Failed to send messages after 3 tries. 在kafka0.8开发过程中 生产者测试用例碰到了 Exception in thread "mai ...
- kafka.common.KafkaException: Failed to acquire lock on file .lock in /tmp/kafka-logs. A Kafka instance in another process or thread is using this directory.
1.刚才未启动zookeeper集群的时候,直接启动kafka脚本程序,kafka报错了,但是进程号启动起来来,再次启动出现如下所示的问题,这里先将进程号杀死,再启动脚本程序. [hadoop@sla ...
- 开发环境解决 kafka Failed to send messages after 3 tries
新建了一个kafka集群,在window下写了一个简单的producer做测试,结果遇到了消息发送失败的问题,代码如下: Properties props = new Properties(); pr ...
- kafka启动报错:kafka.common.KafkaException: Failed to acquire lock on file .lock
kafka 异常退出后重启时遇到的问题 解决: 执行 netstat -lnp|grep 9092 在执行结果中找到进程号执行 kill -9 进程号再尝试启动Kafka
- Caused by java.lang.Exception Failed to send data to Kafka Expiring
flink 写kafka,报错,作业挂掉 Caused by: java.lang.Exception: Failed to send data to Kafka: Expiring 89 recor ...
- 关于kafka定期清理日志后再消费报错kafka.common.OffsetOutOfRangeException的解决
环境: kafka 0.10 spark 2.1.0 zookeeper 3.4.5-cdh5.14.0 公司阿里云测试机,十月一放假前,没有在继续消费,假期过后回来再使用spark strea ...
- org.apache.kafka.common.network.Selector
org.apache.kafka.common.client.Selector实现了Selectable接口,用于提供符合Kafka网络通讯特点的异步的.非阻塞的.面向多个连接的网络I/O. 这些网络 ...
随机推荐
- 《Maven实战》文字版[PDF]
从亚马逊买的电子书,导出来的,需要的下吧. 下面是截图: 除了代码部分有一点点不清楚之外,其他还是蛮清楚的. 下载地址: http://download.csdn.net/download/apple ...
- git diff 结果分析
git diff 的5个使用场景: 1.staging area和working area的文件 (无其他参数时) git diff 2.master分支和working area的文件 (用ma ...
- Java如何获取图片验证码保存
举例网站:https://my.1hai.cn/Login/?url=http://www.1hai.cn/ 一.场景:出于安全性考虑,越来越多的Web平台登录都会增加图形验证码(图片),或者短信验证 ...
- WCF中的ServiceHost初始化两种方式
1 代码方式 using(ServiceHost host=new ServiceHost(typeof(HelloWordService))) { host.AddServiceEndpoint(t ...
- linux+nginx+phpfpm 访问出现Access denied错误解决方案
linux上安装nginx,php-fpm后访问页面一直出现Access denied错误. 网上搜原因大概如下图: 我试了第一个方案,然后就好了.
- html5中JavaScript删除全部节点
如果div里有这么些内容: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type ...
- javaweb(2)之Servlet入门
Hello Servlet 方式一 1.新建 web 工程,编写一个类,实现 javax.servlet.Servlet 接口: package com.zze.servlet; import jav ...
- 关于 Shell 的相关概念和配置方法,全在这儿了!
使用Linux的过程中少不了使用各种各样的Shell, 而根据启动环境的不同,Shell会读取不同的配置文件.本文便来详细介绍这些不同名字的配置文件在何时会被Shell读取. 什么是 Shell Sh ...
- cherry-pick多个commitid时的顺序说明
有的时候,我们在一个分支上提交了几个commit,然后我们会需要提交到其他分支上,一般情况下,我们会采用的merge的方式来合并分支,另外一种方式是只需要其中几个提交时,我们会cherry-pick到 ...
- 用python写多线程
import threading #首先导入threading 模块,这是使用多线程的前提 from time import ctime,sleep def music(func): ): print ...