Apache Camel. Throttle Part of the Route
Asked Answered
T

1

7

I have a JMS queue. After receiving the message it needs to be stored to DB. Then depending on some condition I want send this message to third party service with fixed rate, so I use throttling.

I have the following route:

    from("jms:queue")
            .bean(persistingListener)
            .choice()
                .when(some condition ..)
                    .throttle(5)
                    .asyncDelayed()
                    .bean(thirdPartyServiceClient)
            .endChoice();

However, the entire route gets throttled, not the part related to third party service client. I mean, that if I put 100 messages in the queue, only first 5 will be read. So, in this case the processing of messages that don't require third party service get delayed.

Any ideas on how to throttle only on the part related to third party service?

Thanks in advance

Topmast answered 9/8, 2016 at 13:10 Comment(4)
Is there a chance that your condition is always true? You should also specify the time window.Xylia
@alobodzk, well, there's no such chance and I think it doesn't matter. By default throttle time window is set to 1 sec.Topmast
Set asyncConsumer=true on the JMS endpoint. See its docs: camel.apache.org/jmsDistil
@Claus Ibsen, thanks, that helped. Please, create an answer so I can accept itTopmast
D
5

The JMS endpoint runs in a mode by default where each JMS message is processed in sequence. If you want to allow to process messages (out of order) due to asynchronous processing, then you need to enable this explict by configuring asyncConsumer=true on the endpoint.

See more details in the JMS documentation: http://camel.apache.org/jms

Distil answered 9/8, 2016 at 14:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.