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



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

任何可能导致produce to 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>

请遵循int_jpa:updating-outbound-gateway异常处理问题的答案。

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

最新更新