Controlling Start-Up and Shutdown of Camel Routes

守給你的承諾、 提交于 2019-12-12 02:52:34

问题


I am trying to make kind of a polling service towards a activemq queue using camel routes.

I am using routing and routing-jsm plugins for grails.

I have my route configuration set like this.

class QueueRoute {
def configure = {
    from("activemq:daemon").routeId("daemonRoute")
    .noAutoStartup()
    .shutdownRunningTask(ShutdownRunningTask.CompleteCurrentTaskOnly)
    .to('bean:daemonCamelService?method=receive')
    .end()
}

}

and I am basically trying to do .suspendRoute("daemonRoute") and .resumeRoute("daemonRoute") with some time inbetween. Though after issuing suspendRoute the route is not stopped.

Anyone have tried this?, I have read something about needing to kill the exchange in progress or something similar.


回答1:


if you are just trying to periodically process all messages in a queue, then another option (instead of starting and stopping the route) is to use a timer and a polling consumer bean to do retrieve all the messages in the queue...

from("timer://processQueueTimer?fixedRate=true&period=30000")
    .to("bean:myBean?method=poll");

public class MyBean {

  public void poll() {
    // loop to empty queue
    while (true) {
        // receive the message from the queue, wait at most 3 sec
        Object msg = consumer.receiveBody("activemq:queue:daemon", 3000);
        if (msg == null) {
            // no more messages in queue
            break;
        }

        // send it to the next endpoint
        producer.sendBody("bean:daemonCamelService?method=receive", msg);
    }
  }
}



回答2:


See this FAQ how to stop/suspend a route from a route http://camel.apache.org/how-can-i-stop-a-route-from-a-route.html

An alternative is to use a route policy http://camel.apache.org/routepolicy

For example as we do with the throttling route policy that is provided out of the box, take a look at how its implemented, you can do similar for your route as well.



来源:https://stackoverflow.com/questions/9078621/controlling-start-up-and-shutdown-of-camel-routes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!