I'm using the Kafka example from GitHub (https://github.com/marinkobabic/axon-kafka-example) and it's working when connecting to a locally deployed Kafka cluster. As suggested by Axon's docs, I'm trying to use a custom kafka ProducerFactory by exposing a KafkaPublisher bean and overriding withProducerFactory(). My bean is created, but createProducer() of my custom kafka ProducerFactory is never getting called. In fact, Axon's DefaultProducerFactory is still used. Any suggestions?
@Bean
KafkaPublisher<byte[], byte[]> kafkaPublisher(ProducerFactory factory) {
KafkaPublisherConfiguration configuration = KafkaPublisherConfiguration.<String, byte[]>builder()
.withMessageSource(new SimpleEventBus())
.withProducerFactory(new org.axonframework.kafka.eventhandling.producer.ProducerFactory<String, byte[]>() {
@Override
public Producer<String, byte[]> createProducer() {
return factory.createProducer();
}
@Override
public void shutDown() {
}
})
.withTopic(topic)
.build();
KafkaPublisher<byte[], byte[]> publisher = new KafkaPublisher<>(configuration);
publisher.start();
return publisher;
}
DefaultProducerFactory
, whilst you're creating an anonymous class in this snippet. – Steven