java - How to detect connection errors in Kafka -


i'm using kafkaproducer java. example of code:

package com.mypackage.kafka.producer;  import org.apache.kafka.clients.producer.kafkaproducer; import org.apache.kafka.clients.producer.producerrecord;  import java.util.properties;  public class producertotest {     public static void main(string[] args)     {         properties props = new properties();         props.put("bootstrap.servers", "localhost:9092");         props.put("retries", 0);         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");          kafkaproducer<string, string> producer = new kafkaproducer<string, string>(props);         (int = 0; < 100; i++)         {             system.out.println(i);             producer.send(new producerrecord<string, string>("my-topic", integer.tostring(i), integer.tostring(i)));         }          producer.close();     } } 

i have problem. if kafka down , run code stops @ first send , waits until kafka again.

how can detect connection errors or use send in way don't stop execution?

producer try re-connect till request.timeout.ms. not wait broker indefinitely. please refer below detail information request.timeout.ms.

the configuration controls maximum amount of time client wait response of request. if response not received before timeout elapses client resend request if necessary or fail request if retries exhausted.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -