我有一个简单的案例,我将多播与 3 个 bean 一起使用。thirs bean 返回一个 RuntimeException 但这很好,因为它不会阻止响应返回给客户端(servlet 调用)。但是,如果我在 from 和多播之间添加一个 dynamicRouter,则不会返回更多响应,并且我让 Camel 尝试通过将消息重新发送到多播来像以前一样以不同的方式处理异常。这会导致转换异常,因为在我的聚合器中我修改了 IN 消息。
如何保持相同的行为并使用 dynamicRouter?
谢谢
以下是我正在使用的文件的一些摘录:
骆驼.xml
<!-- Generic route listening to all the the requests -->
<route id="generic">
<from uri="servlet:///services?httpBindingRef=rsaHttpBinding"/>
<!-- <dynamicRouter>
<method ref="rsaDynamicRouter" method="route"/>
</dynamicRouter>
-->
<choice>
<when>
<simple>${property.rsaHeader.action} == 'getAccounts'</simple>
<to uri="direct:getAccounts#1.0" />
</when>
<when>
<simple>${property.rsaHeader.action} == 'createAccount'</simple>
<to uri="direct:createAccount#1.0" />
</when>
</choice>
</route>
<!-- Process getAccounts requests -->
<route>
<from uri="direct:getAccounts#1.0" />
<multicast strategyRef="accountAggregator">
<to uri="bean:accountBackend1?method=getAccounts" />
<to uri="bean:accountBackend2?method=getAccounts" />
<to uri="bean:accountBackend3?method=getAccounts" />
</multicast>
</route>
RsaDynamicRouter.java
public class RsaDynamicRouter {
public String route(Object body, @Properties Map<String, Object> properties) {
RsaHeader rsaHeader = (RsaHeader)properties.get("rsaHeader");
return "direct://" + rsaHeader.getAction() + "#" + rsaHeader.getVersion();
}
}
如果我取消注释 dynamicRouter 并注释选择,那么我收到的响应不会发送回客户端,并且我有以下异常发生 3 次:
Caused by: org.apache.camel.InvalidPayloadException: No body available of type: lu.bgl.example.mycamel.account.SearchCriteria but has value: [Account: number= 1314-1516-1718-1920, name=Larry Page, balance=30, Account: number= 2122-2324-2526-2728, name=Steve Jobs, balance=40] of type: java.util.ArrayList on: Message: [Account: number= 1314-1516-1718-1920, name=Larry Page, balance=30, Account: number= 2122-2324-2526-2728, name=Steve Jobs, balance=40]. Caused by: No type converter available to convert from type: java.util.ArrayList to the required type: lu.bgl.example.mycamel.account.SearchCriteria with value [Account: number= 1314-1516-1718-1920, name=Larry Page, balance=30, Account: number= 2122-2324-2526-2728, name=Steve Jobs, balance=40]. Exchange[Message: [Account: number= 1314-1516-1718-1920, name=Larry Page, balance=30, Account: number= 2122-2324-2526-2728, name=Steve Jobs, balance=40]]. Caused by: [org.apache.camel.NoTypeConversionAvailableException - No type converter available to convert from type: java.util.ArrayList to the required type: lu.bgl.example.mycamel.account.SearchCriteria with value [Account: number= 1314-1516-1718-1920, name=Larry Page, balance=30, Account: number= 2122-2324-2526-2728, name=Steve Jobs, balance=40]]
at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:101) ~[camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.builder.ExpressionBuilder$38.evaluate(ExpressionBuilder.java:934) ~[camel-core-2.11.0.jar:2.11.0]
... 131 common frames omitted
Caused by: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: java.util.ArrayList to the required type: lu.bgl.example.mycamel.account.SearchCriteria with value [Account: number= 1314-1516-1718-1920, name=Larry Page, balance=30, Account: number= 2122-2324-2526-2728, name=Steve Jobs, balance=40]
at org.apache.camel.impl.converter.BaseTypeConverterRegistry.mandatoryConvertTo(BaseTypeConverterRegistry.java:181) ~[camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:99) ~[camel-core-2.11.0.jar:2.11.0]
... 132 common frames omitted