How can I create a dynamic number of DefaultMessageListenerContainer MDPojos in Spring?
I need to create a variable number of these based on a configuration value, the intention is to have multiple consumers where each corresponds to a physical resource that can onl开发者_如何学编程y be used by one thing at a time to process the message.
I implemented a container that manages multiple instances of DefaultMessageListenerContainer(s) which it creates based off of a prototypical instance if the listener. 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. 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
BTW - there's an interesting thread here - 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.
精彩评论