我使用Camel 2.14.1将消息路由到一堆端点,例如:
from(...)
...
.to(monitoringEndpointId, broadcastEndpointId);
我想在运行时动态启用/禁用这些端点/路由。到目前为止,我已尝试使用CamelContext
的stopRoute
和suspendRoute
方法,例如:
camel.suspendRoute(broadcastEndpointId)
但这导致以下异常:
An unknown exception occurred:
org.apache.camel.component.direct.DirectConsumerNotAvailableException: No consumers available on endpoint: Endpoint[direct://broadcast]. Exchange[JmsMessage[JmsMessageID: ID:NB137-38323-1460630272896-5:1:1:1:1356]]
at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:47)
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:120)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:416)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:105)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:87)
at org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:103)
at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:685)
at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:623)
at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:591)
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:308)
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:246)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1142)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1134)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:1031)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
所以这实际上有效,但日志中充满了这些异常。有没有更好的方法来实现我想要的目标?
答案 0 :(得分:4)
将路线ID提供给您的路线,如下所示 -
from("activemq:queue:test")
.routeId("myrouteid")
.to("file:///hello");
然后你可以使用camel context -
来使用suspend和resume路由camelContext.suspendRoute("myrouteid") or camelContext.resumeRoute("myrouteid")
答案 1 :(得分:0)
一种方法可能是使用Filter。然后使用属性打开和关闭端点:
<filter>
<simple>${properties:endpoint1.isEnabled}</simple>
<to uri="direct:endpoint1"/>
</filter>