【发布时间】:2016-03-16 08:54:05
【问题描述】:
我试图在 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 为空。我不知道为什么。
顺便说一句,当我用一个简单的stdout 端点替换 Kafka 端点以打印消息正文时,一切正常。
您能告诉我我的 Kafka 端点配置有什么问题,没有可用的EvaluationContext 吗?
【问题讨论】:
标签: spring spring-boot spring-integration apache-kafka kafka-producer-api