注意: 本文不谈废话,低级问题请自行检查。

我使用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. 最无语的配置的更多相关文章

  1. kafka.common.FailedToSendMessageException: Failed to send messages after 3 tries.

    今天在写kafka生产者生成数据的程序并运行时,报如下错误: log4j:WARN No appenders could be found for logger (kafka.utils.Verifi ...

  2. 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 ...

  3. kafka Failed to send messages after 3 tries 问题解决

    kafka Failed to send messages after 3 tries. 在kafka0.8开发过程中 生产者测试用例碰到了 Exception in thread "mai ...

  4. 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 ...

  5. 开发环境解决 kafka Failed to send messages after 3 tries

    新建了一个kafka集群,在window下写了一个简单的producer做测试,结果遇到了消息发送失败的问题,代码如下: Properties props = new Properties(); pr ...

  6. kafka启动报错:kafka.common.KafkaException: Failed to acquire lock on file .lock

    kafka 异常退出后重启时遇到的问题 解决: 执行 netstat -lnp|grep 9092 在执行结果中找到进程号执行 kill -9 进程号再尝试启动Kafka  

  7. 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 ...

  8. 关于kafka定期清理日志后再消费报错kafka.common.OffsetOutOfRangeException的解决

    环境: kafka  0.10 spark  2.1.0 zookeeper  3.4.5-cdh5.14.0 公司阿里云测试机,十月一放假前,没有在继续消费,假期过后回来再使用spark strea ...

  9. org.apache.kafka.common.network.Selector

    org.apache.kafka.common.client.Selector实现了Selectable接口,用于提供符合Kafka网络通讯特点的异步的.非阻塞的.面向多个连接的网络I/O. 这些网络 ...

随机推荐

  1. ASP.NET Core 中读取 Request.Body 的正确姿势

    ASP.NET Core 中的 Request.Body 虽然是一个 Stream ,但它是一个与众不同的 Stream —— 不允许 Request.Body.Position=0 ,这就意味着只能 ...

  2. Docker数据卷

    1.volume操作命名:docker volume Usage:    docker volume COMMAND Manage Docker volumes Options:       --he ...

  3. [转载] apache ab压力测试报错(apr_socket_recv: Connection reset by peer (104))

    遇见相同的问题. https://www.cnblogs.com/felixzh/p/8295471.html -------------------------------------------- ...

  4. Restsharp常见格式的发送分析

    1.传递匿名对象JSON格式 public string Pay(string apisecret, string apikey, string token) { try { string url = ...

  5. cpu概念

    cpu的主频=外频x倍频 cpu的主频不能完全决定cpu的性能,只是cpu性能的一个参数 cpu的外频是cpu的基准频率,它决定着整个主板的运行速度,超频超的是cpu的外频 IPC:cpu每一个时钟周 ...

  6. node os模块

    const os = require('os'); console.log(os.homedir()); console.log(os.hostname()); console.log(os.plat ...

  7. 【UML】NO.46.EBook.5.UML.1.006-【UML 大战需求分析】- 用例图(Use Case Diagram)

    1.0.0 Summary Tittle:[UML]NO.46.EBook.1.UML.1.006-[UML 大战需求分析]- 用例图(Use Case Diagram) Style:DesignPa ...

  8. 初识GitHub之创建文件

    在新建了一个项目(repository)后,会跳转到项目主页,如下图 Create new file(创建新文件)就是新建一个代码文件,Upload file(上传文件)即从内存中将代码文件上传至本项 ...

  9. python类中的内置函数

    __init__():__init__方法在类的一个对象被建立时,马上运行.这个方法可以用来对你的对象做一些你希望的初始化.注意,这个名称的开始和结尾都是双下划线.代码例子: #!/usr/bin/p ...

  10. CurrentHashMap、HashMap、HashTable的区别

    HashTable 底层数组+链表实现,无论key还是value都不能为null,线程安全,实现线程安全的方式是在修改数据时锁住整个HashTable,效率低,ConcurrentHashMap做了相 ...