Spring integration 使用Spring Boot 2启用MessageHistory时无法发送kafka消息
我正在将我们的一项服务从spring boot 1.5升级到2,现在我看到一个与kafka producer相关的异常,该异常与将messageHistory写入标头有关。以下是收到的例外情况:Spring integration 使用Spring Boot 2启用MessageHistory时无法发送kafka消息,spring-integration,spring-kafka,Spring Integration,Spring Kafka,我正在将我们的一项服务从spring boot 1.5升级到2,现在我看到一个与kafka producer相关的异常,该异常与将messageHistory写入标头有关。以下是收到的例外情况: org.springframework.kafka.listener.ListenerExecutionFailedException: Listener failed; nested exception is java.lang.IllegalArgumentException: Incorrect
org.springframework.kafka.listener.ListenerExecutionFailedException: Listener failed; nested exception is java.lang.IllegalArgumentException: Incorrect type specified for header 'history'. Expected [class org.springframework.integration.history.MessageHistory] but actual type is [class org.springframework.kafka.support.DefaultKafkaHeaderMapper$NonTrustedHeaderType].
通过深入研究代码,在转换MessageHistory
标题时,似乎在DefaultKafkaHeaderrMapper
中引发了异常,因此任何人都可以帮助我理解:
MessageHistory
是否应该在
送出MessageHistory
的正确方法是什么提前谢谢 您可以将
org.springframework.integration.history
包添加到白名单中,以恢复以前的行为:DefaultKafkaHeaderMapper.addTrustedPackages()
:
或者您可以从映射中完全排除这样的头
添加自定义序列化程序的另一种方法是将消息历史记录
存储为列表
/**
* Add packages to the trusted packages list (default {@code java.util, java.lang}) used
* when constructing objects from JSON.
* If any of the supplied packages is {@code "*"}, all packages are trusted.
* If a class for a non-trusted package is encountered, the header is returned to the
* application with value of type {@link NonTrustedHeaderType}.
* @param packagesToTrust the packages to trust.
*/
public void addTrustedPackages(String... packagesToTrust) {