Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multithreaded JMS receiving in Spring

Tags:

java

spring

jms

I'm trying to write a multithreaded implementation for JMS message processing from a queue.

I've tried with DefaultMessageListenerContainer and SimpleMessageListenerContainer classes.

The problem I have is that it seems like just a single instance of the MessageListener class gets ever instantiated, no matter how I configure it. This forces me to unnecessarily write stateless or thread-safe MessageListener implementations, since I have the ListenerContainer configured to use multiple threads (concurrentConsumers=8).

Is there an obvious solution to this that I'm overlooking?

like image 639
Iker Jimenez Avatar asked Oct 29 '10 11:10

Iker Jimenez


1 Answers

This is by design. The MessageListener is a dependency that you inject into Spring - it has no way of instantiating new ones.

This forces me to unnecessarily write stateless or thread-safe messageListener implementations

You make that sound like a bad thing. Making your MessageListener is a very good idea, Spring just removes the temptation to do otherwise.

like image 168
skaffman Avatar answered Sep 30 '22 04:09

skaffman