我试图从ChennelInterceptor中抛出一些异常。但它没有将消息发送到我定义的ErrrorChannel。
在摘录下方。
<int-file:inbound-channel-adapter id="fileInBound"
channel="fileProcessingChannel"
directory="${file.processing.folder}"
prevent-duplicates="true"
filename-pattern="*.txt">
</int-file:inbound-channel-adapter>
<int:channel id="fileProcessingChannel">
<int:queue/>
</int:channel>
<!--Setting the Error Channel -->
<int:header-enricher input-channel="inputchannel" output-channel="testChannel">
<int:error-channel ref="myErrorChannel" overwrite="true"></int:error-channel>
</int:header-enricher>
<!-- Accepts only the File data Type -->
<int:channel id="testChannel" >
<int:interceptors>
<bean class="com.abc.SomeValidationInterceptor"></bean>
</int:interceptors>
</int:channel>
<int:channel id="myErrorChannel">
</int:channel>
<int:service-activator input-channel="myErrorChannel" output-channel="nullChannel">
<bean class="com.abc.MyErrorHandlerEndpoint"></bean>
</int:service-activator>
抛出异常,即来自com.abc.SomeValidationInterceptor.And的MessagingException,我希望到达myErrorChannel,但它会到达myErrorChannel。
知道为什么它不起作用。提前谢谢。
答案 0 :(得分:1)
它不起作用。除非在非常特殊的情况下,否则通常不应自己操纵errorChannel
标题。
如何将消息发送到inputChannel
。
通常,您应该使用某种类型的网关并在其上声明error-channel
;让框架处理标题;网关捕获异常并ErrorMessage
正确路由。
同样,可以在轮询器上为轮询端点定义error-channel
。