问题描述
我正在尝试为队列中的JMS消息处理编写多线程实现.
I'm trying to write a multithreaded implementation for JMS message processing from a queue.
我尝试使用DefaultMessageListenerContainer和SimpleMessageListenerContainer类.
I've tried with DefaultMessageListenerContainer and SimpleMessageListenerContainer classes.
我遇到的问题是,无论我如何配置,似乎都只是实例化了MessageListener类的单个实例.这迫使我不必要地编写无状态或线程安全的MessageListener实现,因为我已将ListenerContainer配置为使用多个线程(concurrentConsumers = 8).
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?
推荐答案
这是设计使然. MessageListener
是您注入到Spring中的依赖项-它无法实例化新的依赖项.
This is by design. The MessageListener
is a dependency that you inject into Spring - it has no way of instantiating new ones.
您让这听起来像是一件坏事.设置MessageListener
是一个很好的主意,Spring消除了这样做的诱惑.
You make that sound like a bad thing. Making your MessageListener
is a very good idea, Spring just removes the temptation to do otherwise.
这篇关于Spring中的多线程JMS接收的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!