[英]Messages DO NOT appear in the Spring Integration (Kafka) ErrorChannel when Broker is unavailable
I am working with a simple Kafka based project using Spring Integration and we require that when the Broker is down, messages will pass into the ErrorChannel and we can deal with them /save as 'dead-letters' etc. 我正在使用Spring Integration处理一个基于Kafka的简单项目,我们要求当Broker关闭时,消息将传递到ErrorChannel中,并且我们可以将它们处理为/ dead-letters等。
What we are getting is a countless run of Exceptions: 我们得到的是无数的异常运行:
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]
But the error channel is not referenced :-/ 但是错误通道没有被引用:-/
I have tried to hook it up, but to no avail - here is part of my app-context: 我曾试图把它挂起来,但无济于事-这里是我的应用程序上下文的一部分 :
<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>
Sadly, I am not an expert at Spring Integration - any ideas what I am doing wrong? 不幸的是,我不是 Spring Integration的专家-有什么想法我做错了吗?
Thanks for your help. 谢谢你的帮助。
Everything is correct so far. 到目前为止,一切都正确。 The problem that you are missing the fact of
async
behavior by default in the KafkaProducerMessageHandler
: 默认情况下,您在
KafkaProducerMessageHandler
中缺少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) {
So, consider to use sync="true"
attribute on the <int-kafka:outbound-channel-adapter>
. 因此,请考虑在
<int-kafka:outbound-channel-adapter>
上使用sync="true"
属性。
In addition, with the latest upcoming versions we have introduced: 此外,在即将发布的最新版本中,我们引入了:
<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>
which is useful for the async
behavior to catch those errors. 这对于
async
行为捕获这些错误很有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.