I created a java producer on my local machine and setup a Kafka broker on
another machine, say M2, on the network(I can ping,SSH, connect to this
machine). On the Producer side in the Eclipse console I get "Message sent".
But when I check the console consumer on machine M2 I cannot see those
messages.

My java producer code is:

import org.apache.kafka.clients.producer.KafkaProducer;import
org.apache.kafka.clients.producer.ProducerConfig;import
org.apache.kafka.clients.producer.ProducerRecord;

import java.util.HashMap;import java.util.Map;
public class KafkaMessageProducer  {

    /**
     * @param args
     */
    public static void main(String[] args) {

        KafkaMessageProducer reportObj = new KafkaMessageProducer();
        reportObj.send();

    }

    public void send(){

        Map<String, Object> config = new HashMap<String, Object>();
        config.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,
"125.111.133.60:9092");
        config.put("value.serializer",
"org.apache.kafka.common.serialization.StringSerializer");
        config.put("key.serializer",
"org.apache.kafka.common.serialization.StringSerializer");

        KafkaProducer<String, String> producer = new
KafkaProducer<String, String>(config);
        int maxMessages = 5;
        int count = 0;
        while(count < maxMessages){
            producer.send(new ProducerRecord<String, String>("test",
"msg", "message --- #"+count++));
            System.out.println("Message send.."+count);
        }
        producer.close();
    }
}

Can you please let me know where I'm going wrong? I can send messages
locally on machine M2 from the console producer. Note: Even when I change
the IP address to the full hostname of the Kafka Broker it still has the
same issue.

I created a Producer jar and ran this jar on Machine M2 and it worked. So
it seems that there is something wrong with the way Producer tries to
connect to the Kafka broker. Not sure yet what is the problem.

I added a send().get() and now the Producer just blocks and keeps waiting
with this output:

log4j:WARN No appenders could be found for logger
(org.apache.kafka.clients.producer.ProducerConfig).

log4j:WARN Please initialize the log4j system properly.

log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for
more info.

Reply via email to