【发布时间】:2017-03-28 15:53:00
【问题描述】:
我有一个带有 http-outbound-gateway 的 spring-xd http-processor 模块,它有一个 errorChannel 和 outputChannel。任何带有 HTTP 200 的消息都进入 outputChannel,其余消息进入 failureChannel。
现在,http-processor 模块使用带有 TopicX 的 kafka-outbound-adapter 连接到 Kafka-Sink。 TopicX 仅接收 HTTP 200 消息以进行进一步处理。现在,我们需要将 failureChannel 中的消息路由到 TopicY。
如何在 kafka-sink 中发送多个 kafka 主题的消息。我在消息头中有 httpStatusCode。我项目中使用的Kafka版本是0.8.2,java版本是1.7
<!-- http-processor-config -->
<int-http:outbound-gateway
request-channel="input"
url-expression="'myUrlLink'"
http-method="POST"
expected-response-type="java.lang.String"
charset="UTF-8"
reply-timeout="10"
reply-channel="output">
<int-http:request-handler-advice-chain>
<bean class="org.springframework.integration.handler.advice.RequestHandlerRetryAdvice">
<property name="recoveryCallback">
<bean class="org.springframework.integration.handler.advice.ErrorMessageSendingRecoverer">
<constructor-arg ref="errorChannel" />
</bean>
</property>
<property name="retryTemplate" ref="retryTemplate" />
</bean>
</int-http:request-handler-advice-chain>
</int-http:outbound-gateway>
<!-- Handle failed messages and route to failureChannel for specific http codes-->
<int:service-activator input-channel="errorChannel" ref="customErrorHandler" method="handleFailedRequest" output-channel="failureChannel"/>
在 Kafka Sink 上,我有以下生产者上下文:
<int-kafka:producer-context id="kafkaProducerContext">
<int-kafka:producer-configurations>
<int-kafka:producer-configuration broker-list="localhost:9092"
topic="${topicX}"
key-class-type="java.lang.String"
key-serializer="serializer"
value-class-type="[B"
value-serializer="valueSerializer"/>
</int-kafka:producer-configurations>
</int-kafka:producer-context>
【问题讨论】:
标签: apache-kafka spring-integration spring-xd kafka-producer-api