骆驼节流 [英] Throttling in Camel

查看:90
本文介绍了骆驼节流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试弄清Camel中的节流概念.我已经看过骆驼(Camel)的路线政策,但这可用于机上交换次数.

I am trying to figure out throttling concepts in Camel. I have already seen Camel's route policy, but this works for number of inflight exchanges.

我的路线如下:

routeBuilders.add(new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("rabbitmq://127.0.0.1:5672/abc?queue=a&username=XXX&password=XXX&autoAck=false&durable=true&exchangeType=direct&autoDelete=false")
                .to("rabbitmq://127.0.0.1:5672/abc?queue=b&username=XXX&password=XXX&autoAck=false&durable=true&exchangeType=direct&autoDelete=false");
            }
        });

现在,我的用例是我想在这些路由之间传输2000条消息,并且我知道可以通过.throttle(2000)完成.但是我陷入了必须决定何时路由下2000条消息时如何控制的问题.我只想在接收者队列为空时才路由下2000条消息.

Now my use case is that I want to transfer say 2000 messages between these routes, and I know that it can be done via .throttle(2000). But I am stuck at the point where I have to decide that how would I control that when the next 2000 messages should be routed. I want to route next 2000 messages only when the receiver queue becomes empty.

例如,邮件正在从队列a路由到b.假设2k邮件已成功路由,现在我想暂停路由,以便在队列b变空之前不会传输更多消息(假设有一个使用者正在从队列b提取消息)

For example, messages are getting routed from queue a to b. Say 2k messages have been routed successfully, now I want to suspend my route so that it won't transfer more messages until the queue b becomes empty (assume that there is a consumer which is pulling messages from queue b)

对此有任何帮助/指导.

Any help/direction on this is appreciated.

推荐答案

您可以为此使用路由策略.您在该路由策略中实现逻辑,以暂停/恢复到油门路由的路由.

You can use a route policy for that. The you implement logic in that route policy to suspend/resume the route to throttle the route.

我们有一个开箱即用的策略,它使用Camel中的机上消息数作为指标.但是您应该添加逻辑以检查该队列是否为空.

We have a out of the box policy that is using the number of inflight messages in Camel as its metrics. But you should add logic to check that queue if its empty or not.

有关路由策略的文档在这里

The documentation for route policy is here

还有机上油门的代码

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