I created a custom RecordMessageConverter which print in the toMessage and fromMessage (I create Bean as explained at https://www.confluent.io/blog/spring-for-apache-kafka-deep-dive-part-1-error-handling-message-conversion-transaction-support) but unfortunately it is not binded to the listener. Can I explicitly bind it or should I do something else to make it works?
public class MobileMessageConverter implements RecordMessageConverter {
@Override
public Message<?> toMessage(ConsumerRecord<?,?> record, Acknowledgment acknowledgment, Consumer<?, ?> consumer, Type payloadType) {
System.out.println("Converting toMessage");
return null;
}
@Override
public ProducerRecord<CustomKey, CustomValue> fromMessage(Message<?> message, String defaultTopic) {
System.out.println("Converting fromMessage");
return new ProducerRecord("UNKNOWN",new CustomValue());
}
}
@RestController
public class CustomKafkaController {
@Bean
public RecordMessageConverter converter() {
return new CustomMessageConverter();
}
@KafkaListener(topics = "UNKNOWN", containerFactory = "kafkaListenerContainerFactory", groupId = "1")
public void listenAsObject(ConsumerRecord<CustomKey, CustomValue> cr) {
System.out.println(cr.getValue().getCustomMessage());
}
}