从主机操作系统访问沙盒中的kafka(尝试每个解决方案后) [英] Accessing kafka in sandbox from Host OS (after trying every solution)

查看:110
本文介绍了从主机操作系统访问沙盒中的kafka(尝试每个解决方案后)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对我来说是一个小菜。
我已经阅读了关于堆栈溢出的所有问题,并尝试了一天,但解决方案并未点击给我。请帮助我具体到我的设置和代码(因为我已经尝试了从堆栈溢出的相同问题的所有可能性 - )

这是我的Producer.properties文件





这是我的server.properties文件





这是我的代码

  Properties props = new Properties(); 
props.put(metadata.broker.list,sandbox.hortonworks.com:9093);
//props.put(\"zk.connect,sandbox.hortonworks.com:2181);
props.put(serializer.class,kafka.serializer.StringEncoder);
props.put(request.required.acks,1);

KeyedMessage< String,String> data = new KeyedMessage< String,String> (TOPIC1 ccccccccc);


System.out.println(data);
producer.send(data);

这是eclipse输出

  KeyedMessage(tweeter,null,ccccccccc)
kafka.common.FailedToSendMessageException:3次尝试后发送消息失败。


解决方案



server.properties文件中有4个属性
port host.name 广告主名称广告端口



Producer.properties文件中有1个属性
元数据.broker.list



确保broker.list与advertised.host.name:advertised.port相同

注释host.name属性,因为它不起作用如果给出广告主机名。



我简单地使用 ifconfig 命令,然后把这个IP与9092端口在这两个属性,它的工作。

Cnsider me a noob. I have read all the issues on stack overflow and tried for one day but the solution just do not click to me. PLEASE Help me specifically to my SETTINGS and CODE(because I have tried all possibilities from same issues on stack overflow - )

This is my Producer.properties file

This is my server.properties file

This is my code

Properties props = new Properties();
props.put("metadata.broker.list", "sandbox.hortonworks.com:9093");
//props.put("zk.connect", "sandbox.hortonworks.com:2181");
props.put("serializer.class", "kafka.serializer.StringEncoder");
props.put("request.required.acks", "1");

KeyedMessage<String, String> data = new KeyedMessage<String, String> (topic1,"ccccccccc");


System.out.println(data);
producer.send(data);

This is the eclipse output

KeyedMessage(tweeter,null,ccccccccc)
kafka.common.FailedToSendMessageException: Failed to send messages after 3 tries.

解决方案

Well in Hit and Trail strategy I finally Caught the problem.

There are 4 properties in server.properties file port, host.name, advertised host name and advertised port

And 1 property in Producer.properties file metadata.broker.list

Make sure that broker.list is same as advertised.host.name:advertised.port

Comment host.name property as it doesn't effect If advertised host name is given.

I simply got ip of my sandbox using ifconfig command and then put that IP with 9092 port in both properties and it worked.

这篇关于从主机操作系统访问沙盒中的kafka(尝试每个解决方案后)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆