我会使用骆驼try catch
块(如@soilworker建议)。
.doTry()
.to("http://datasource1/data")
.doCatch(UnknownHostException.class)
// Add message 1 here
.end()
//process
.doTry()
.to("http://datasource2/data")
.doCatch(UnknownHostException.class)
// Add message 2 here
.end()
// process
它更冗长,但它很容易理解,并明确地将该消息与异常关联。如果您希望使to
调用异步,您可以。
您可以使用路由特定onException
但你会需要你的路线分成多个路线:
from("somewhere")
.to("direct:datasource1")
//process
.to("direct:datasource2")
//process
from("direct:datasource1")
.onException(UnknownHostException.class)
// add message 1 here
.end()
.to("http://datasource/data")
from("direct:datasource2")
.onException(UnknownHostException.class)
// add message 2 here
.end()
.to("http://datasource2/data")
我不相信有使用onException
与一个路线的方式,但应用于不同to
来电(除了使用@Alexeys或@Ewouts建议)。如果有的话,很乐意听到它。
也许你可以在你的路由中使用2个try/catch块分别处理异常,而不是使用onException块?有关更多信息,请参阅http://camel.apache.org/try-catch-finally.html。 – soilworker