Spring集成kafka如何处理生成到kafka时的错误

时间:2016-10-10 23:40:24

标签: spring spring-integration spring-kafka

使用int-kafka:outbound-channel-adapter生成kafka时,似乎没有可用的错误通道。在这种情况下,如何处理消息在转换次数后无法生成到kafka?

任何可能导致kafka失败的错误。 (以下代码只是来自互联网的代码片段,只是想知道如何添加错误句柄)

<int-kafka:outbound-channel-adapter id="kafkaOutboundChannelAdapter"
                                    kafka-producer-context-ref="kafkaProducerContext"
                                    auto-startup="true"
                                    channel="inputToKafka"
                                    topic="test">
    <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" keep-alive="120" queue-capacity="500"/>

<int-kafka:producer-context id="kafkaProducerContext" producer-properties="producerProps">
    <int-kafka:producer-configurations>
        <int-kafka:producer-configuration broker-list="XXXXXX:6667"
                   key-class-type="java.lang.String"
                   value-class-type="java.lang.String"
                   topic="rating"
                   value-serializer="kafkaSerializer"
                   key-serializer="kafkaSerializer"
                   compression-type="none"/>
    </int-kafka:producer-configurations>
</int-kafka:producer-context>


<util:properties id="producerProps">
    <prop key="queue.buffering.max.ms">500</prop>
    <prop key="topic.metadata.refresh.interval.ms">3600000</prop>
    <prop key="queue.buffering.max.messages">10000</prop>
    <prop key="retry.backoff.ms">100</prop>
    <prop key="message.send.max.retries">2</prop>
    <prop key="send.buffer.bytes">5242880</prop>
    <prop key="socket.request.max.bytes">104857600</prop>
    <prop key="socket.receive.buffer.bytes">1048576</prop>
    <prop key="socket.send.buffer.bytes">1048576</prop>
    <prop key="request.required.acks">1</prop>
</util:properties>

1 个答案:

答案 0 :(得分:0)

请按照此问题的答案exception handling in int-jpa:updating-outbound-gateway

由于您有<polled>,因此您可以指定error-channel并处理该频道上的流中的错误。