Spring integration 使用Spring Boot 2启用MessageHistory时无法发送kafka消息

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

我正在将我们的一项服务从spring boot 1.5升级到2,现在我看到一个与kafka producer相关的异常,该异常与将messageHistory写入标头有关。以下是收到的例外情况:

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
    是否应该在 送出

  • 如果1)的答案是肯定的,那么对受信任的包创建
    MessageHistory
    的正确方法是什么

  • 如果1)为否,则可能错误地执行了哪些操作以防止将历史记录写入标头


  • 提前谢谢

    您可以将
    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) {