Spring中的多线程JMS接收 [英] Multithreaded JMS receiving in Spring

查看:64
本文介绍了Spring中的多线程JMS接收的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为队列中的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实现

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

您让这听起来像是一件坏事.设置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接收的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆