arturh
arturh

Reputation: 6106

How to change Processor properties during runtime using Camel?

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?

Upvotes: 1

Views: 2251

Answers (3)

shijin raj
shijin raj

Reputation: 91

I am having a Apache camel spring boot application which has 5 instances reading from a kafka topic with a group ID and posting to a REST API. We would like to implement a throttling mechanism across these 5 Apache camel spring boot instances . For example 20K requests per minute to be routed to the REST API. I read about the correlationExpression feature for Throttling . https://camel.apache.org/components/3.15.x/eips/throttle-eip.html

Let's name camel spring boot applications as A, B, C, D and E Then correlationExpression will only work 20K request per minute for individual instance basis - 20K request per minute for A, 20K request per minute for B, 20K request per minute for C, 20K request per minute for D and 20K request per minute for E Then it will be over loaded for the REST API endpoint.

I need to implement throttling feature across the 5 camel spring boot instances - total request per minute should be 20K by adding all the instances request rate - i.e, Request per minute in A + Request per minute in B+Request per minute in C+Request per minute in D+Request per minute in E = 20K per minute

But I am not sure how we can configure this correlationExpression connecting the 5 camel spring boot instances so that total request per minute should be 20K requests per minute by considering all requests from these 5 camel spring boot instances.

I would appreciate all the help and guidance.

Throttling multi instance Apache camel spring boot

Upvotes: 0

Claus Ibsen
Claus Ibsen

Reputation: 55540

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.

Upvotes: 1

arturh
arturh

Reputation: 6106

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.

Upvotes: 2

Related Questions