简体   繁体   English

如何在Spring中创建动态数量的DefaultMessageListenerContainer MDPojos?

[英]How can I create a dynamic number of DefaultMessageListenerContainer MDPojos in Spring?

我需要根据配置值创建一个可变数量的这些,目的是让多个使用者,每个使用者对应一个物理资源,一次只能由一件事物来处理消息。

I implemented a container that manages multiple instances of DefaultMessageListenerContainer(s) which it creates based off of a prototypical instance if the listener. 我实现了一个容器,它管理DefaultMessageListenerContainer的多个实例,它是基于一个原型实例(如果是监听器)创建的。 Based on a system property (a # value), a number of listeners are created and the queues they listen to are numeric "my.Queue" + ordinal number. 基于系统属性(#值),创建了许多侦听器,并且他们侦听的队列是数字“my.Queue”+序号。 This could obviously be modified to look up the queue names if necessary. 显然可以修改它以在必要时查找队列名称。 That being said, this is not a dynamically expanding/contracting list of listeners. 话虽如此,这不是一个动态扩展/收缩的听众列表。 They are created at the beginning, although I think you could use this as a starting point to make it more dynamic if you wish to. 它们是在开始时创建的,但我认为你可以将它作为一个起点,使它更具动态性。

I wrote a pretty rudimentary unit test and a very rudimentary implementation (no multithreading taken into consideration), and it appears to work. 我写了一个非常基本的单元测试和一个非常基本的实现(没有考虑多线程),它似乎工作。

The maven project can be downloaded here - http://dl.dropbox.com/u/7812537/StackOverflowMultipleListeners.zip maven项目可以在这里下载 - http://dl.dropbox.com/u/7812537/StackOverflowMultipleListeners.zip

BTW - there's an interesting thread here - http://forum.springsource.org/showthread.php?t=69604 顺便说一句 - 这里有一个有趣的主题 - http://forum.springsource.org/showthread.php?t=69604

I think there could be a way to do this by extending a generic bean factory but i'm not sure what your requirements are. 我认为可以通过扩展泛型bean工厂来实现这一目标,但我不确定您的要求是什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM