我试图在 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: [Assertion failed] - 此参数是必需的;它不能为空
这是堆栈跟踪中的违规行:
在 org.springframework.integration.kafka.outbound.KafkaProducerMessageHandler.onInit(KafkaProducerMessageHandler.java:68)
这是第 68 行发生的情况:
Assert.notNull(this.evaluationContext);
所以EvaluationContext
是空的。我不知道为什么。
顺便说一句,当我用一个普通的端点替换 Kafka 端点stdout
来打印消息正文时,一切正常。
你能告诉我我的 Kafka 端点配置有什么问题,没有EvaluationContext
可用的吗?