Throttling in Camel

南楼画角 提交于 2019-12-08 04:10:51

问题


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.

My route is following:

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

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.

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.


回答1:


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.

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

  • http://camel.apache.org/routepolicy

And the code for the inflight throttler

  • https://github.com/apache/camel/blob/master/camel-core/src/main/java/org/apache/camel/impl/ThrottlingInflightRoutePolicy.java


来源:https://stackoverflow.com/questions/24904114/throttling-in-camel

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