It seems that you put in the wrong port in the following statement. Kafka's
default port is 9092. 2181 is for Zookeeper.
   props.put("bootstrap.servers", "localhost:2181");

Thanks,

Jun

On Mon, Feb 8, 2016 at 4:06 AM, Bhargav Maddikera <
bhargav.maddik...@altimetrik.com> wrote:

> Hi,
>
> I try executing the code
>
>        Properties props = new Properties();
>
>                props.put("bootstrap.servers", "localhost:2181");
>               props.put("metadata.broker.list","localhost:9092");
>               props.put("request.required.acks", "1");
>               props.put("retries", 4);
> //            props.put("batch.size", 16384);
> //            props.put("linger.ms", 1);
> //            props.put("buffer.memory", 33554432);
>               props.put("key.serializer",
> "org.apache.kafka.common.serialization.StringSerializer");
>               props.put("value.serializer",
> "org.apache.kafka.common.serialization.StringSerializer");
>
>               Producer<String, String> producer = new KafkaProducer(props);
>               int maxMessages = 1000;
>
>                   int count = 0;
>                   while(count < maxMessages) {
>                     producer.send(new ProducerRecord<String,
> String>("test",  "message --- #"+count++)).get();
>                     System.out.println("Message send.."+count);
>                   }
>                   producer.close();
>
>
>
> but I get Caused by: org.apache.kafka.common.errors.TimeoutException:
> Failed to update metadata after 60000 ms.
>
>
> But when I  do,
>
> //                Properties properties = new Properties();
> //             properties.put("metadata.broker.list","localhost:9092");
> //
>  properties.put("serializer.class","kafka.serializer.StringEncoder");
> //             properties.put("partitioner.class", "SimplePartitioner");
> //             properties.put("request.required.acks", "1");
> //             ProducerConfig producerConfig = new
> ProducerConfig(properties);
> //             kafka.javaapi.producer.Producer<String,String> producer =
> new kafka.javaapi.producer.Producer<String, String>(producerConfig);
> //             SimpleDateFormat sdf = new SimpleDateFormat();
> //             KeyedMessage message =new KeyedMessage("test","1","After
> Restart210");
> //             System.out.println(message.key());
> //             producer.send(message);
> //             producer.close();
> //             System.out.println("done");
>
> It works fine.
>
> Regards.
> Bhargav.
>

Reply via email to