在骆驼中节流 [英] Throttling in Camel

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

问题描述

我正在尝试找出 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.

路线政策的文档在这里

以及机上油门的代码

这篇关于在骆驼中节流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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