我是集成新手。我有一个路由器。在特定场景下,该方法会抛出异常。基于该异常,我如何路由我的消息。我想捕获该异常并基于将我的消息路由到另一个例如 channel 。
<integration:router ref="serviceImpl" method="getName"/>
最佳答案
您可以尝试如下操作:
首先按以下方式配置路由器和 bean:
<integration:router ref="serviceImpl" method="getName"/>
<beans:bean class="com.test.ServiceImpl" id="serviceImpl">
</beans:bean>
</int:router>
那么你的ServiceImpl.java
应该如下所示:
public class ServiceImpl {
public String getName(Name name) {
String channel = "";
try {
//Your business validations should be here and if everything is okay, then route the message to some channel
channel = "goToSomeChannel"
} catch (SomeException e) {
//You got the exception, So route to different channel
channel = "goToSomethingElseChannel";
}
return channel;
}
}
最后,您在 spring 集成配置文件中定义了 channel goToSomeChannel
和 goToSomethingElseChannel
。
关于java - Spring集成路由器中的异常处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44148930/