Reputation: 4101
I am routing messages to a bunch of endpoints using Camel 2.14.1, for example:
from(...)
...
.to(monitoringEndpointId, broadcastEndpointId);
I want to to dynamically enable/disable these endpoints/routes during runtime. So far I've tried to use CamelContext
's stopRoute
and suspendRoute
methods, for example:
camel.suspendRoute(broadcastEndpointId)
But this results in the following exception:
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)
So this actually works, but the logs are full of these exceptions. Is there a better way to achieve what I want?
Upvotes: 3
Views: 5457
Reputation: 432
Give route id to your route as shown below -
from("activemq:queue:test")
.routeId("myrouteid")
.to("file:///hello");
Then you can use suspend and resume route using camel context -
camelContext.suspendRoute("myrouteid") or camelContext.resumeRoute("myrouteid")
For more information go through http://camel.apache.org/lifecycle.html
Upvotes: 4
Reputation: 820
One approach could be using Filter. Then 'switch' the endpoint on and off using properties:
<filter>
<simple>${properties:endpoint1.isEnabled}</simple>
<to uri="direct:endpoint1"/>
</filter>
Upvotes: 0