spring 集成:错误通道:第一个异常阻止处理其余消息
spring integration: error-channel : the first exception prevent the rest of messages to be handled
在 file:splitter 和 http:outbound 网关期间需要帮助处理链中的错误。
现在,如果当我们收到 status-code=400, 500 ... 时错误消息中存在任何异常,我希望在错误通道的服务激活器中处理它并继续其他拆分消息。
当我们收到异常时,它会在服务激活器中处理,但不会处理其他拆分的消息。
链条:
<int-file:inbound-channel-adapter> ---><int-file:splitter> ---> <int-http:outbound-gateway>
对于从文件中读取的每一行,我们都应该调用 WS,因此当我们收到错误消息(状态代码 400 或 500)时,我们应该通过邮件发送它并继续为其他消息调用 ws。
代码是这样的:
<int-file:inbound-channel-adapter
directory="/META-INF/tmp" id="filesIn" channel="toSplitter">
<int:poller fixed-delay="1000" error-channel="error.channel" />
</int-file:inbound-channel-adapter>
<int-file:splitter input-channel="toSplitter"
output-channel="router" />
<int:recipient-list-router id="recipentRouter" input-channel="router">
<int:recipient channel="type1.channel.request"
selector-expression="headers['file_name'].startsWith('${type1}')" />
<int:recipient channel="another.type1.channel"
selector-expression="headers['file_name'].startsWith('${type1}')" />
<int:recipient channel="type2.channel.request"
selector-expression="headers['file_name'].startsWith('${type2}')" />
<int:recipient channel="anothertype2.channel.request"
selector-expression="headers['file_name'].startsWith('${type2}')" />
</int:recipient-list-router>
<int-http:outbound-gateway
request-channel="type1.channel.request"
url="${url}"
http-method="PUT" expected-response-type="java.lang.String" charset="UTF-8"
reply-timeout="5000" reply-channel="changesim.channel.reply">
</int-http:outbound-gateway>
拆分后的错误需要处理
一个解决方案是使type1.channel.request
成为QueueChannel
(添加一个<int:queue/>
子元素),然后在http网关上放置一个<poller/>
,带有错误通道.
splitter/router会将拆分后的消息放入队列中,轮询器会一次拉出一条消息。
另一种解决方案(如果您出于某种原因不想使用队列通道)是在拆分器之后放置一个带有错误通道的中流 <gateway/>
- 网关将是 ref
来自服务激活器。
在 file:splitter 和 http:outbound 网关期间需要帮助处理链中的错误。 现在,如果当我们收到 status-code=400, 500 ... 时错误消息中存在任何异常,我希望在错误通道的服务激活器中处理它并继续其他拆分消息。
当我们收到异常时,它会在服务激活器中处理,但不会处理其他拆分的消息。
链条:
<int-file:inbound-channel-adapter> ---><int-file:splitter> ---> <int-http:outbound-gateway>
对于从文件中读取的每一行,我们都应该调用 WS,因此当我们收到错误消息(状态代码 400 或 500)时,我们应该通过邮件发送它并继续为其他消息调用 ws。
代码是这样的:
<int-file:inbound-channel-adapter
directory="/META-INF/tmp" id="filesIn" channel="toSplitter">
<int:poller fixed-delay="1000" error-channel="error.channel" />
</int-file:inbound-channel-adapter>
<int-file:splitter input-channel="toSplitter"
output-channel="router" />
<int:recipient-list-router id="recipentRouter" input-channel="router">
<int:recipient channel="type1.channel.request"
selector-expression="headers['file_name'].startsWith('${type1}')" />
<int:recipient channel="another.type1.channel"
selector-expression="headers['file_name'].startsWith('${type1}')" />
<int:recipient channel="type2.channel.request"
selector-expression="headers['file_name'].startsWith('${type2}')" />
<int:recipient channel="anothertype2.channel.request"
selector-expression="headers['file_name'].startsWith('${type2}')" />
</int:recipient-list-router>
<int-http:outbound-gateway
request-channel="type1.channel.request"
url="${url}"
http-method="PUT" expected-response-type="java.lang.String" charset="UTF-8"
reply-timeout="5000" reply-channel="changesim.channel.reply">
</int-http:outbound-gateway>
拆分后的错误需要处理
一个解决方案是使type1.channel.request
成为QueueChannel
(添加一个<int:queue/>
子元素),然后在http网关上放置一个<poller/>
,带有错误通道.
splitter/router会将拆分后的消息放入队列中,轮询器会一次拉出一条消息。
另一种解决方案(如果您出于某种原因不想使用队列通道)是在拆分器之后放置一个带有错误通道的中流 <gateway/>
- 网关将是 ref
来自服务激活器。