kafka producer fails to publish message in java -jar but works fine in mvn spring-boot:run or debugger

12 Views Asked by At

Kafka publisher sending message using

@Bean
public KafkaTemplate<String, byte[]> kafkaTemplate() {
    return new KafkaTemplate<>(producerFactory());
}



@Bean
public ProducerFactory<String, byte[]> producerFactory() {
   
    configProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "127.0.0.1:9092");
    configProps.put("spring.kafka.bootstrap-servers", "127.0.0.1:9092");
    configProps.put("spring.kafka.consumer.auto-offset-reset","earliest");
    configProps.put("spring.kafka.consumer.group-id","data-group");
    configProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,         StringSerializer.class.getName());
    configProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,  ByteArraySerializer.class.getName());
   
    configProps.put(ConsumerConfig.CLIENT_ID_CONFIG,"ClientIDdata-group");
    return new DefaultKafkaProducerFactory<>(configProps);
}

ListenableFuture<SendResult<String, byte[] >> futureResult =  kafkaTemplate.send(topic, binarydata);
futureResult.addCallback(PublishCallback());

If the above snippet is run with mvn spring-boot:run data is published but after compiling the code in jar and running java -jar it does not publish the data. there is no error in log.

Ensured that kafka-client 2.7.1 is included in jar and is added in pom.xml

0

There are 0 best solutions below