Reputation: 11
Recently I came up with a problem. How to make a Camel application limit the connections being served simultaneously. First I thought about the Throttler EIP, but disconsidered using it after reading about it, and concluding it wouldn't fit my need. The Throttler configured with a maximum of 10 messages per second would allow only this much go through my messaging system, even if the 10 requests were served in a few milliseconds combined. I need to serve 10 concurrent connections, and it means I can have a throughput of hundreds of messages each second - but the 10 connections limit can never be exceded. Shall it ever be exceeded, I must return an exception to the caller, telling him that he is not allowed to use more than 10 connections at once. I can not queue his requests in any way, the requests must be served as soon as they arrive (or be rejected).
Then I discovered that the SEDA component would do just what I need. With 10 concurrentConsumers, and a queue size of 0 (zero), I would get a limit of 10 connections being served simultaneously, and every new connection would be refused. The problem is how SEDA is behaving, in Camel 2.10.3. When I configure "size=0", it automatically uses Integer.MAX_VALUE (seen in jConsole). When I set the queue to "1" it works as expected, but I can't have any queue at all.
Searching through the source code of Camel SEDA, I see it uses LinkedBlockingQueue for the SEDA queue, that just can't have a capacity of 0. So the default constructor is used, indeed using Integer.MAX_VALUE for the queue.
Am I missing something? Are there any other alternatives for solving my problem?
Any help is greatly appreciated!
Upvotes: 1
Views: 395
Reputation: 55555
You can also use a threads to execute messages concurrently using a thread pool, where you can specify min/max threads.
from(somewhere)
.threads(10)
.to(a)
.to(b)
Some details in the bottom of this page: http://camel.apache.org/async.html
Upvotes: 1
Reputation: 22279
A connection can mean many things, but I assume you want to limit number of in flight exchanges in a route. There are some components that does have something like this built in, such as the jetty component (given you don't do async stuff). In the generic case, you can use a route policy. You might need to write one of you own, but it should be fairly simple. I guess the supplied ThrottlingInFlightRoutePolicy is too coars grained for your case.
Upvotes: 0