当代理不可用时,java消息不会出现在SpringIntegration(kafka)错误通道中

ar7v8xwq  于 2021-06-07  发布在  Kafka
关注(0)|答案(1)|浏览(378)

我正在使用spring集成处理一个简单的基于kafka的项目,我们要求当代理关闭时,消息将传递到errorchannel,我们可以处理它们/另存为“死信”等。
我们得到的是无数例外:

2017-09-19 17:14:19.651 DEBUG 12171 --- [ad | producer-1] o.apache.kafka.common.network.Selector   : Connection with localhost/127.0.0.1 disconnected

java.net.ConnectException: Connection refused
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) ~[na:1.8.0_131]
    at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717) ~[na:1.8.0_131]

但错误通道未被引用:-/
我试过连接它,但没有用-下面是我的应用程序上下文的一部分:

<bean id="channelExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
    <property name="corePoolSize" value="1"/>
    <property name="maxPoolSize" value="10"/>
    <property name="queueCapacity" value="1000"/>
</bean>

<int:channel id="producingChannel" >
    <int:dispatcher task-executor="channelExecutor" />
</int:channel>

<int-kafka:outbound-channel-adapter id="kafkaOutboundChannelAdapter"
                                    kafka-template="kafkaTemplate"
                                    auto-startup="true"
                                    channel="producingChannel"
                                    topic="${kafka.topic}">
</int-kafka:outbound-channel-adapter>

<int:service-activator input-channel="errorChannel" ref="errorLogger" method="logError" />
<bean id="errorLogger" class="uk.co.sainsburys.integration.service.ErrorLogger" />

<bean id="kafkaTemplate" class="org.springframework.kafka.core.KafkaTemplate">
    <constructor-arg ref="producerConfigs"/> <!-- producerConfigs piece is NOT included! -->
</bean>

可悲的是,我不是spring集成的Maven——你知道我做错了什么吗?
谢谢你的帮助。

cedebl8k

cedebl8k1#

到目前为止一切都是正确的。你所忽略的问题 async 中的默认行为 KafkaProducerMessageHandler :

/**
 * A {@code boolean} indicating if the {@link KafkaProducerMessageHandler}
 * should wait for the send operation results or not. Defaults to {@code false}.
 * In {@code sync} mode a downstream send operation exception will be re-thrown.
 * @param sync the send mode; async by default.
 * @since 2.0.1
 */
public void setSync(boolean sync) {

所以,考虑使用 sync="true" 属性 <int-kafka:outbound-channel-adapter> .
此外,我们还推出了最新版本:

<xsd:attribute name="send-failure-channel" type="xsd:string">
            <xsd:annotation>
                <xsd:documentation><![CDATA[
                    Specifies the channel to which an ErrorMessage for a failed send will be sent.
                ]]></xsd:documentation>
                <xsd:appinfo>
                    <tool:annotation kind="ref">
                        <tool:expected-type type="org.springframework.messaging.MessageChannel" />
                    </tool:annotation>
                </xsd:appinfo>
            </xsd:annotation>
        </xsd:attribute>

这对于 async 捕捉这些错误的行为。

相关问题