首页 文章

EvaluationContext Null 与 Spring Integration 和 Kafka

提问于
浏览
1

我试图在 Spring Integration 中定义一个简单的消息流,它从一个通道读取,然后将消息转储到 Kafka 队列中。为此,我使用spring-integration-kafka。问题是我得到一个EvaluationContext错误,我无法破译。

这是我在 XML 中的配置:

<int:channel id="myStreamChannel"/>
<int:gateway id="myGateway" service-interface="com.myApp.MyGateway" >
    <int:method name="process" request-channel="myStreamChannel"/>
</int:gateway>
<int:channel id="activityOutputChannel"/>
<int:transformer input-channel="myStreamChannel" output-channel="activityOutputChannel" ref="activityTransformer"/>    
<int-kafka:outbound-channel-adapter id="kafkaOutboundChannelAdapter"
                                    kafka-producer-context-ref="kafkaProducerContext"
                                    auto-startup="false"
                                    channel="activityOutputChannel"
                                    topic="my-test"
                                    message-key-expression="header.messageKey">
    <int:poller fixed-delay="1000" time-unit="MILLISECONDS" receive-timeout="0" task-executor="taskExecutor"/>
</int-kafka:outbound-channel-adapter>

<task:executor id="taskExecutor"
               pool-size="5-25"
               queue-capacity="20"
               keep-alive="120"/>

<int-kafka:producer-context id="kafkaProducerContext" producer-properties="producerProperties">
    <int-kafka:producer-configurations>
        <int-kafka:producer-configuration broker-list="kafkaserver.com:9092"
                                          key-class-type="java.lang.String"
                                          value-class-type="java.lang.String"
                                          topic="my-test"
                                          key-encoder="stringEncoder"
                                          value-encoder="stringEncoder"
                                          compression-codec="snappy"/>
    </int-kafka:producer-configurations>
</int-kafka:producer-context>

当我通过 Spring Boot 运行我的应用程序时,我得到以下异常:

创建名为“org.springframework.integration.kafka.outbound.KafkaProducerMessageHandler#0”的 bean 时出错:init 方法的调用失败;嵌套异常是 java.lang.IllegalArgumentException:[6] - 这个参数是必需的;它不能为空

这是堆栈跟踪中的违规行:

在 org.springframework.integration.kafka.outbound.KafkaProducerMessageHandler.onInit(KafkaProducerMessageHandler.java:68)

以下是第 68 行的情况:

Assert.notNull(this.evaluationContext);

所以EvaluationContext为空。我不知道为什么。

顺便说一句,当我用一个简单的stdout端点替换 Kafka 端点来打印消息体时,一切正常。

你能告诉我我的 Kafka 端点配置有什么问题没有EvaluationContext可用吗?

1 回答

  • 3

    您的问题属于版本不匹配的地狱。 Spring Boot 提取了 Spring Integration Core 版本,它不支持IntegrationEvaluationContextAware来填充KafkaProducerMessageHandler中的EvaluationContext

    因此,您应该将 Spring Integration Kafka 升级到最新版本:https://github.com/spring-projects/spring-integration-kafka/releases

相关问题