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. 这些网络 ...
随机推荐
- Luogu 1023 - 税收与补贴问题 - [数学题]
题目链接:https://www.luogu.org/problemnew/show/P1023 题目背景每样商品的价格越低,其销量就会相应增大.现已知某种商品的成本及其在若干价位上的销量(产品不会低 ...
- LeetCode 696 Count Binary Substrings 解题报告
题目要求 Give a string s, count the number of non-empty (contiguous) substrings that have the same numbe ...
- time和datetime和tzinfo
time和datetime模块还有tzinfo (时区)(一直不明白两者的区别,然后摘了两片文章(最后面的两个链接),很清晰...) 一.time模块 常用函数 1. time()函数 time()函 ...
- filter过滤器实现验证跳转_返回验证结果
1. 需求背景 需要对某个请求url进行拦截,模拟是否可以进入某一个接口,如果拦截需要返回数据false,别问我为何不用intercept拦截器. 2. web.xml <filter> ...
- 004-mac下Java6与Java8 安装
一.Java6安装 官方下载下载地址:http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-down ...
- [js]变量提升-关于条件
条件函数变量提示于全局中函数变量提升不一样. 条件中: 函数变量提升, 只是声明(现新版本浏览器中) if(g()){ function g() { return true } console.log ...
- openshift 容器云从入门到崩溃之五《部署应用》
1.配置部署模板 配置好用户权限之后就可以部署应用了oc常用的两种部署方式: Deploy Image方式 优点:这种方式是最简单的部署方式,你只需要有一个容器镜像就行了或者公开的docker hub ...
- Eclipse集成scala插件
1.Eclipse中右击help,选择Eclipse Marketplace,搜索scala,一路点击安装,重启Eclipse. 2.新建工程,new->other->出现scala wi ...
- jQuery实现购物车物品数量的加减
基于jquery的一款代码,实现购物车数据的加减,在淘宝网.京东商城购物时时经常见到的一个功能,点击文本框两侧的“+”与“-”,就可以增加或减少文本框内的数字值,每次步长为1,当然这个是可以自己设置的 ...
- 解决IDEA无法安装插件的问题
进入2018年以来,在IDEA插件中心中,安装插件经常安装失败,报连接超时的错误.如下: 我们发现连接IDEA的插件中心使用的是https的链接,我们在浏览器中使用https访问插件中心并不能访问. ...