How to create a dynamic number DefaultMessageListenerContainer MDPojos in Spring?

I need to create a variable number of them based on the configuration value, the goal is to have several consumers, each of which corresponds to a physical resource that can be used by only one thing at a time to process the message.

+3
source share
1 answer

I implemented a container that manages multiple instances of DefaultMessageListenerContainer (s), which it creates based on the prototype, if the listener. Based on the system property (value #), several listeners are created, and the queues that they listen to are numeric "my.Queue" + serial number. This, obviously, can be changed to look up queue names if necessary. However, this is not a dynamically expanding / shrinking 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 want.

I wrote a rather rudimentary unit test and a very rudimentary implementation (without multithreading), and it seems to work.

maven - http://dl.dropbox.com/u/7812537/StackOverflowMultipleListeners.zip

- - http://forum.springsource.org/showthread.php?t=69604

, , bean factory, , .

+2

Source: https://habr.com/ru/post/1769707/


All Articles