views:

322

answers:

2

I have a Camel Route Definition written in Java DSL like this:

from(myEndpoint) 
.throttle(200)
.to(myOtherEndpoint);

This connects my two endpoints using a Throttler which limits the message flow to 200 messages per second.

I'm looking for a way to change the maximumRequestCount / second during runtime. So I need to somehow get to the Throttler instance which is called and change the property.

How can I access the Throttler?

+1  A: 

Ok, I figured it out by myself ...

You need to define your Throttler instance yourself.

Throttler throttler = new Throttler(null, 200);

Then you can use it in your routes like this, because Throttler implements the Processor interface:

from(myEndpoint) 
.process(throttler)
.to(myOtherEndpoint);

Any time you like you can change the properties of the throttler.

arturh
Yeah anything in the Camel route boils down to a Processor so you can do as you did.You can assign an id to a processor in the route.from(myEndpoint).throttle(200).id("myThrottler").to(myOtherEndpoint);Then what lacks currently is a nice lookupThrottler throttler = context.getProcessorById("myThrottler", Throttler.class);// then change the throttler as you like.
Claus Ibsen
Just created a ticket for a nice lookup: CAMEL-2258
Claus Ibsen
+1  A: 

Yeah that is a neat solution.

In Camel 2.0 you can now navigate the runtime processors in the route and thus find any Throttlers and then be able to change it dynamically.

But we are also working on improving the JMX in Camel 2.1 so you can change throttler/delayer and the likes from JMX.

And maybe also improve the Navigate API so you can find in a one liner, eg maybe lookup by id if you provide an id in the route. Or by types so you can filter and only get the Throttlers etc.

Claus Ibsen
That was the kind of solution I was looking for initally. But as far as I know there is no way to put an "id" to a throttler to look for it.In my tests of simply traversing the runtime processors, my code became extremly coupled with the Routing Configuration and would not run anymore when I changed it.
arturh