Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

How to handle exception if message lost during publishing to kafka

public class ProduceToKafka {

  private ProducerRecord<String, String> message = null;

 // TracerBulletProducer class has producer properties
  private KafkaProducer<String, String> myProducer = TracerBulletProducer
      .createProducer();

  public void publishMessage(String string) {

    ProducerRecord<String, String> message = new ProducerRecord<>(
        "topicName", string);

    myProducer.send(message, new MyCallback(message.key(), message.value()));
  }

  class MyCallback implements Callback {

    private final String key;
    private final String value;

    public MyCallback(String key, String value) {
      this.key = key;
      this.value = value;
    }


    @Override
    public void onCompletion(RecordMetadata metadata, Exception exception) {
      if (exception == null) {
        log.info("--------> All good !!");
      } else {
        log.info("--------> not so good  !!");
        log.info(metadata.toString());
        log.info("" + metadata.serializedValueSize());
        log.info(exception.getMessage());

      }
    }
  }

}
Comment

PREVIOUS NEXT
Code Example
Java :: https://javahungry.blogspot.com/2020/01/list-of-lists-in-java.html 
Java :: download a website as string kotlin 
Java :: add element to queue java 
Java :: javafx style default 
Java :: collapsingtoolbarlayout collapse listener 
Java :: @expose(serialize = false) not working 
Java :: how to generate randome number in desired range java 
Java :: Accept Integer only in if else statement 
Java :: how to read returned arraylist from another class method 
Java :: Java @Repeatable 
Java :: is type java 
Java :: getarguments().getstring updates android 
Java :: Based on the method exampleMethod, what is the return type of the method? 
Java :: get string match percentage java 
Java :: rerun main method 
Java :: how to use advanced math in java 
Java :: Why String is popular HashMap key in Java? 
Java :: handle customized popup in selenium 
Java :: join table in where clause criteria in java hibernate 
Java :: integer to roman 
Java :: gc algorithms java 8 
Java :: @column spring boot jpa 
Java :: least significant bit java 
Java :: hystrix configuration spring boot 
Java :: java anomymous code block 
Java :: java skip foreach 
Java :: place.getlatlng() returning null 
Java :: zufallszahl java 
Java :: java como comprobar que un numero es entero? 
Java :: how much epsom salt should strawberries need 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =