[英]Spring Boot inject ObjectMapper into Kafka JsonDeserializer
I would like to inject jackson's ObjectMapper into JsonDeserializer for Kafka's ConsumerFactory.我想将 jackson 的 ObjectMapper 注入到 Kafka 的 ConsumerFactory 的 JsonDeserializer 中。 I've done what is mentioned on this post:我已经完成了这篇文章中提到的内容:
Inject ObjectMapper into Spring Kafka serialiser/deserialiser 将 ObjectMapper 注入 Spring Kafka 序列化器/反序列化器
However, when I have multiple @KafkaListener
s on different topics, the ConcurrentKafkaListenerContainerFactory
constructs multiple instances of ConcurrentMessageListenerContainer
using the properties map to initialize the ConsumerFactory
instead of the instance passed into ConcurrentKafkaListenerContainerFactory.setConsumerFactory()
.但是,当我在不同的主题上有多个@KafkaListener
时, ConcurrentMessageListenerContainer
使用属性映射构造ConcurrentKafkaListenerContainerFactory
多个实例来初始化ConsumerFactory
而不是传递给ConcurrentKafkaListenerContainerFactory.setConsumerFactory()
的实例。 Only the first ConcurrentMessageListenerContainer
is using the correct ConsumerFactory
.只有第一个ConcurrentMessageListenerContainer
使用正确的ConsumerFactory
。
How do I fix this and configure Kafka properly?如何解决此问题并正确配置 Kafka?
You need a different consumer / container factory for each listener.您需要为每个侦听器使用不同的使用者/容器工厂。 Then use the containerFactory property on @KafkaListener to specify the factory to use.然后使用 @KafkaListener 上的 containerFactory 属性来指定要使用的工厂。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.