控制骆驼航线的启动和关机 [英] Controlling Start-Up and Shutdown of Camel Routes

查看:345
本文介绍了控制骆驼航线的启动和关机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让那种朝ActiveMQ的投票站服务的使用骆驼的路线队列。

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

我使用的路由和路由,JSM插件Grails的。

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()
}

}

和我基本上想用一段时间,其间做.suspendRoute(daemonRoute)和.resumeRoute(daemonRoute)。虽然发行suspendRoute后路由不会停止。

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.

推荐答案

如果你只是想定期处理所有消息在队列中,那么另一种选择(而不是启动和停止的路线)就是用一个定时器和一个轮询消费者豆做检索队列中的所有邮件...

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);
    }
  }
}

这篇关于控制骆驼航线的启动和关机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆