简体   繁体   中英

How to write camel route that handles request concurrently

I am trying to write a camel route that consumes incoming message from a JMS queue and handles them concurrently in different threads. The camel route I have got is like this:

<camel:endpoint id="requestQueue" uri="jms:queue.request" camelContextId="camel"/>
<camel:endpoint id="responseQueue" uri="jms:queue.response" camelContextId="camel"/>

<camel:camelContext id="camel">
    <camel:threadPool id="serviceThreadPool" poolSize="10" threadName="workerThread" maxPoolSize="20"/>

    <camel:route id="requestServingRoute">
        <camel:from ref="requestQueue"/>

        <camel:threads executorServiceRef="serviceThreadPool">
            <camel:to uri="bean:doSomething"/>
            <camel:to ref="responseQueue"/>
        </camel:threads>
    </camel:route>
</camel:camelContext>

However, what I can observe is that the incoming message is indeed handled by separate threads, but they are handled in a sequential order.

What I tried to achieve is that camel handles each request in the doSomething bean in separate threads for each incoming request.

How can I achieve this?

Thank you very much.

You need to specify the number of concurrent consumers for the JMS request queue. See http://camel.apache.org/jms.html . You don't need to message around with the thread pools. eg in Java DSL syntax you would write something like:

from("jms:queue.request?concurrentConsumers=10")
.beanRef("bean", "doSomething")
.to("jms:queue.response)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM