java - camel-http4 2.22 - toD 不工作
问题描述
迁移到 2.22.0(从 2.16.5)后,动态路由 (toD) 中的骆驼动态 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,然后使用带有任意url的静态路由'to',第二种是使用reciepientList。但是,我不喜欢使用“to”的第一个选项,因为我需要设置任意 url。我目前正在使用第二个选项,receipientList 类似这样的东西(请注意,这里使用的 setHeader 仅用于演示。在我的项目的处理器类中动态检索和设置 url):
<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 2.16 开始,有一个新的动态的。在消息端点查看更多详细信息。
http://camel.apache.org/how-to-use-a-dynamic-uri-in-to.html
任何人都可以帮助我了解是否已经删除了对 http4 的 toD 的支持?或者这是一个错误?
PS:我在 OSGI 包内的 Karaf 4.2 容器中运行它,使用蓝图 xml。
解决方案
我通过将组件放在我在 toD 中使用的标题中解决了这个问题。例子:
<route>
<from uri="timer://foo?fixedRate=true&period=1000"/>
<setHeader headerName="SMSURI">
<constant>https4://localhost:9090/</constant>
</setHeader>
<toD uri="${headers.SMSURI}" />
</route>