public class KafkaProducer { @Autowired @Qualifier("mainProducer") private KafkaTemplate<String, Object> kafkaTemplate; public void sendMessage(String topic, String key, Object message) { log.info("Producing message: {}", message); kafkaTemplate.send(topic, key, message) .addCallback( result -> log.info("Message sent to topic {}: {}", topic, message), ex -> log.error("Failed to send message", ex)); } }
Обсуждают сегодня