Hi, All:

      Finally I fixed this bug.

1. set advertised.host.name at config/server.properites as AWS
*private IP* address
(not public *DNS*)
2. comment host.name at config/server.properites
3. In remote java producer:
props.put("metadata.broker.list",  borkerPrivateIp+ ":9092");
The value brokerPrivateIp is same as advertised.host.name
 at config/server.properites

     This bug blocked me a while...

Sincerely,
Selina

On Thu, Aug 13, 2015 at 9:56 PM, Job-Selina Wu <swucaree...@gmail.com>
wrote:

> Dear All:
>
>    I got kafka.common.FailedToSendMessageException: Failed to send
> messages after 3 tries as below. When I have a remote java Kafka producer
> try to produce message to Kafka broker Server. Both Producer and Broker are
> at AWS cloud. BTW, I tried my code first at local machine and Virtual
> machine first, It did not work either.(advertised.host.name was set to
> the ip address of the kafka server*)*
>
> *-------------**This is my KafkaProducer at remote Producer for producer
> configuration**-------------*
> public class KafkaProducer {
>
>     Properties props = new Properties();
>
>     private final Producer<String, String> producer;
>     private final String kafkaServerIP = "52.19.2.74:9092";
>
>     public KafkaProducer() {
>
>
>         props.put("metadata.broker.list", kafkaServerIP);
>         //props.put("bootstrap.servers", "localhost:9092 ");
>         props.put("serializer.class", "kafka.serializer.StringEncoder");
>         props.put("advertised.host.name", "localhost");
>         props.put("request.required.acks", "0");
>
>         ProducerConfig config = new ProducerConfig(props);
>
>         producer = new Producer<String, String>(config);
>     }
>
>     public Producer<String, String> getProducer() {
>
>         return this.producer;
>     }
> }
>
>
> --------*The configs/server.properties at Kafka Server at AWS*-----
>
> zookeeper.connect=localhost:2181
> zookeeper.connection.timeout.ms=6000
>
> delete.topic.enable=true
>
> broker.id=0
> port=9092
> host.name=localhost
> *advertised.host.name <http://advertised.host.name>*=
> ec2-51-18-21-235.us-west-1.compute.amazonaws.com
>
> # below is same as default
> #advertised.port=<port accessible by clients>
> #advertised.port=<port accessible by clients>
> num.network.threads=3
> num.io.threads=8
> socket.send.buffer.bytes=102400
> socket.receive.buffer.bytes=102400
> socket.request.max.bytes=104857600
> log.dirs=/tmp/kafka-logs
> num.partitions=1
> num.recovery.threads.per.data.dir=1
> #log.flush.interval.messages=10000
> #log.flush.interval.ms=1000
> log.retention.hours=168
> #log.retention.bytes=1073741824
> log.segment.bytes=1073741824
> log.retention.check.interval.ms=300000
> log.cleaner.enable=false
>
>
> - - --- - - - - --
>
> kafka.common.FailedToSendMessageException: Failed to send messages after 3
> tries.
> kafka.common.FailedToSendMessageException: Failed to send messages after 3
> tries.
> at
> kafka.producer.async.DefaultEventHandler.handle(DefaultEventHandler.scala:90)
> at kafka.producer.Producer.send(Producer.scala:77)
> at kafka.javaapi.producer.Producer.send(Producer.scala:33)
> at com.cinarra.kafka.Main.main(Main.java:21)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:606)
> at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:293)
> at java.lang.Thread.run(Thread.java:745)
>
>
> reference:
>
> http://stackoverflow.com/questions/30217255/cant-connect-to-a-remote-kafka-producer-from-windows-through-java-code
>
> Your help is highly appreciated,
> Selina
>
>

Reply via email to