Appreciate your help on this issue.
I am using Kafka 0.8.2
Here's the producer code I've written.
The issue is everything is working fine..I am able to publish the message and get the acknowledgement (metadata) after successful publish. But the issue is .....
How can I track If the kafka broker is down. I need to display an error message If the broker is down.
If the broker is down I need to capture the messages publish in the meantime till the broker is up & running.
Any insights would be very helpful.
public class cvsKafkaProducerAck {
public static void main(String args[]) {
String topic = "test_topic";
String msg = "test...22";
Properties props = new Properties();
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
props.put(ProducerConfig.RETRIES_CONFIG, "1");
props.put(ProducerConfig.ACKS_CONFIG, "all");
//props.put(ProducerConfig.METADATA_FETCH_TIMEOUT_CONFIG , "1");
props.put(ProducerConfig.BATCH_SIZE_CONFIG, 1);
props.put(ProducerConfig.BLOCK_ON_BUFFER_FULL_CONFIG, true);
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArraySerializer");
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArraySerializer");
KafkaProducer<byte[], byte[]> m_kafkaProducer = new KafkaProducer<byte[], byte[]>(props);
ProducerRecord<byte[], byte[]> prMessage = new ProducerRecord<byte[],byte[]>(topic, msg.getBytes());
try
{
RecordMetadata metadata = m_kafkaProducer.send(prMessage).get();
System.out.println("The offset of the record we just sent is: " + metadata.offset());
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
m_kafkaProducer.close();
}
}