Search code examples
multithreadingactivemq-classicspring-integration

Spring-integration / ActiveMQ subscribe to multiple destinations in a single thread


I am using multiple <si:service-activator>'s and <jms:message-driven-channel-adapter>'s to subscribe to multiple queues and topics. Messages from each destination are received in a separate thread, which means that my receiving code is full of locks to guard the mutable internal state.

I would like my receiving code to be lock free. Is it possible to configure spring-integration/activemq to receive from multiple destinations on the same thread?

If this is not possible, I can think of two alternatives:

  1. Start my own processing thread which reads from a blocking queue, put all received messages on this queue.

  2. Dispatch all received messages onto a single destination and consume from this.

Anyone have any better ideas?


Solution

  • Use the wildcard pattern on a single queue.

    That is, instead of reading from two queues, use one queue and specify all queues you want to read from in the name.

    that is: "QUEUE.NR1,QUEUE.NR2" or "SOME.PREFIX.>" to read all queues with that prefix. Your client code handle this as a single queue.