Home:ALL Converter>Consume messages from JMS queue using multithreading

Consume messages from JMS queue using multithreading

Ask Time:2016-01-29T18:47:56         Author:Nagendra

Json Formatter

I have a requirement in our project to process the JMS messages in parallel using threads. Currently our project works like this: When a file is placed in a directory the poller generates messages and the outbound adapter creates JMS messages and sends it to businessQueue. The JMS listener listens the messages from the queue and launches the batch job to process the file. So at a time only 1 file will be processed.

<jms:listener-container concurrency="1"
        acknowledge="client" container-type="default" destination-type="queue"
        connection-factory="cachingJmsConnectionFactory" cache="auto">
        <jms:listener id="businessFileJmsListener" ref="businessFileJmsReceiver"
            method="onMessage" destination="${BUSINESS_JMS_QUEUE_NAME}" />
    </jms:listener-container>

The requirement is to read the JMS messages from the queue using threads and process the files in parallel. For example we have to read 3 messages at a time and launch 3 batch jobs and process 3 files using threads. In the above configuration there is a property called concurrency. I don't know if we increase the number for that property will it works or not ? Please suggest if there is any way to implement our requirement. My final requirement is to read 3 JMS messages from queue at a time and process 3 files at a time. Please suggest. Thanks.

Author:Nagendra,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/35082574/consume-messages-from-jms-queue-using-multithreading
yy