在从2.16.5迁移到2.22.0后,动态路由(toD)中的camel动态uri似乎已经无法正常工作。演示该问题的测试路由如下:
<route>
<from uri="timer://foo?fixedRate=true&period=1000"/>
<setHeader headerName="SMSURI">
<constant>localhost:9090/</constant>
</setHeader>
<toD uri="https4://${header.SMSURI}?throwExceptionOnFailure=false"/>
</route>
我遇到了以下异常:
2018-08-11T14:41:07,770 | INFO | Camel (testContext) thread #27 - timer://foo | route5 | 160 - org.apache.camel.camel-core - 2.22.0 | java.lang.IllegalArgumentException: Cannot find endpoint with scheme https4
at org.apache.camel.runtimecatalog.AbstractCamelCatalog.endpointProperties(AbstractCamelCatalog.java:529)
at org.apache.camel.http.common.HttpSendDynamicAware.prepare(HttpSendDynamicAware.java:57)
at org.apache.camel.processor.SendDynamicProcessor.process(SendDynamicProcessor.java:118)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:138)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:101)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201)
at org.apache.camel.component.timer.TimerConsumer.sendTimerExchange(TimerConsumer.java:197)
at org.apache.camel.component.timer.TimerConsumer$1.run(TimerConsumer.java:79)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
我知道有两种动态uri的替代方法,一种是设置Exchange.HTTP_URI,然后使用静态路由'to'与任意url一起使用,第二种是使用接收者列表reciepientList。然而,我不喜欢第一种选项,因为我需要设置一个任意的url。我目前正在使用第二个选项,类似于这样的接收者列表(请注意,此处仅用于演示的setHeader。url是在我的项目中的processor类中动态检索和设置的):
<route>
<from uri="timer://foo?fixedRate=true&period=1000"/>
<setHeader headerName="SMSURI">
<constant>localhost:9090/</constant>
</setHeader>
<recipientList>
<simple>https4://${header.SMSURI}?throwExceptionOnFailure=false</simple>
</recipientList>
</route>
这个可以工作。然而,我真的很喜欢toD选项。
此外,Camel网站上说:
动态To - 开箱即用
从Camel 2.16开始,有一个新的选项,它是一个动态的To。 请参见消息端点获取更多细节。
http://camel.apache.org/how-to-use-a-dynamic-uri-in-to.html
请问有人能帮我理解http4中的toD是否已经不再支持了吗?还是这是一个bug?
附注:我是在Karaf 4.2容器内部运行,使用蓝图XML。
camel-http4
依赖升级到版本2.22.0
。所有组件必须始终与camel-core
使用相同的版本进行导入。 - Bedla