Dec 8th, 2011, 01:47 AM
Runtime creation of new DefaultMessageListenerContainer for new queue/destination
Please note, this is my first thread so may be you can guide me if anything is wrong here.
Also I have tried searching for solution in this/other forums but could not find it. If you have any links, please share.
I am trying to develop an application where I can add new destinations and listeners to them at runtime to my web applications. No. of destination-listener pairs are unknown and can change during lifetime of the application. I need to add/remove them dynamically keeping web application running and also not calling context.refresh().
For this I am using DefaultMessageListenerContainer which will forward any new message to already available messageListener bean.
Also I have used BeanDefinitionRegistryPostProcessor which gives me control to add new bean definitions after loading of bean xml but before actual initialization of the beans.
So at deploy time, I can create as many destination-listener pairs as required. But this only works at the deployment time of the application.
Also I have an ApplicationContextProvider which implements ApplicationContextAware which I can use to access application context.
Now I need to add functionality where user provides a new destination and I need to initialize a new listener for it in same web application.
I have tried
1) Creating a new instance of DefaultMessageListenerContainer and then setting destination, messageListener,
connectionFactory. But here I need to do:
applicationContext.getBeanFactory().registerSingle ton(beanName, defaultMessageListenerContainer);
after which the listener initializes but it still cannot get access to other bean objects (e.g. BO/DAO) called during processing of received message.
Seems like I am not able to wire the other beans in this object.
2) When I use
applicationContext.getBeanFactory().createBean(Def aultMessageListenerContainer.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
spring bean initialization fails saying it requires destination property...
When I pass 'false' for dependencyCheck argument, it again fails saying it requires connection factory.
What I really want is a single listener listening to multiple destinations (where I could add/remove the destinations at runtime) but spring listeners do not listen on multiple destinations (correct?). So I am trying to initialize new listener, for new destination and that too, during lifetime of the application.
Any idea how to do this?
Any other way/approach to implement the same functionality will also do.
Jul 12th, 2012, 02:39 AM
Any luck with this?
I am dealing with the same issue now.
Aug 6th, 2012, 10:21 AM
I (newbie) am also looking to solve same issue. Someone, please help! Thanks.
Aug 7th, 2012, 11:43 PM
You need to configure them as prototype beans and activate the DMLC, but you cannot destroy them as prototype beans are controlled by Container.
Originally Posted by ona
I tried these options to create multiple DMLC's for on Demand topics, but I was unable to destroy them
Below link has more info on DMLC
I had successfully built a framework without DMLC to create topics on demand and destroy them on demand and automatic re-subscription of topics onException
Right now I am working on JMS connection polling using spring. Once I have the pool of connections then I can use random function to distribute my topics across the pool.
Tags for this Thread