wood burning stoves 2.0*
The moose likes Spring and the fly likes Disabling JMS Topic Subscription via property Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Disabling JMS Topic Subscription via property" Watch "Disabling JMS Topic Subscription via property" New topic
Author

Disabling JMS Topic Subscription via property

John Bize
Greenhorn

Joined: Aug 23, 2009
Posts: 5
I have a Spring application deployed in an EAR on WLS 10.3. The same EAR is deployed in a couple of different enclaves/environments, and there are a few things that differ between the installations. So I have a small properties file that's read and processed by an initialization bean to accommodate these differences (mostly webservice endpoints).

One of the things this application does is subscribe to a JMS topic on a remote server. However, I want to be able to enable or disable this subscription when I restart the application. The remote publisher may publish over a thousand messages per minute, so I don't just want to return prematurely from the onMessage() method. I want to completely disable the connection/subscription to the topic.

I thought if I could get the container bean reference in the initialization bean, I could shut it down that way. However, "<jms:listener-container" doesn't have an id attribute.

How can I enable/disable a JMS connection to a topic on application start up; preferably via an initialization bean?

John
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

Sorry, I am a little confused. But I have a motto, where if something seems difficult to figure out, or you have to do some odd fix to make something work, then there is something missing in the design or thought approach.

My guess here would be to have different Spring configurations for the different environments. And if you separate your JMS configuration from all you other configurations, then all the other configuration files stay the same, and the only different is the config file for JMS. In most cases your build process can do this automatically for you.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
John Bize
Greenhorn

Joined: Aug 23, 2009
Posts: 5
I apologize for the confusion. There are other factors and constraints involved. Rebuilding and packaging the application with the enabled or disabled JMS listener is how I am doing it now. It's disruptive and impractical in my environment/network. I want to change that. My preference would be to simply change the Boolean state of a property in a properties file and restart. I'm open to other suggestions too, as long as I don't have to rebuild and deploy the EAR to make the change.

I suppose the bottom line is: How can I enable/disable a JMS listener connection to a topic programatically?

Thanks.
John Bize
Greenhorn

Joined: Aug 23, 2009
Posts: 5
Well, I stumbled into this... Although the "<jms:listener-container" doesn't have an id attribute, the embedded "<jms:listener" does. So I injected the reference into my initialization bean, checked the class name, and (surprise!) it's a (the) DefaultMessageListenerContainer. Not what I expected, but what I wanted.

So now, should I issue a .shutdown(), .stop(), or .destroy() to properly disable the listener and connection?
Sandeep Awasthi
Ranch Hand

Joined: Oct 23, 2003
Posts: 597
Jhon,
I don't think the way you are trying to do will work. By the time your initialzing method, is called the bean is already created by container and references are injected. So it has already subscribed to topic.


Sandeep
John Bize
Greenhorn

Joined: Aug 23, 2009
Posts: 5
Thanks Sandeep.

There's actually a fairly significant delay before the messages start to come in. But even if there wasn't, it wouldn't really affect this particular application. It's more important that I shut it down as soon as is practicable.

That said, and with a reference to my DefaultMessageListenerContainer, (directly or via sub-class)...

What is the proper (safe and effective) way to terminate the subscription?

Thanks.
Sandeep Awasthi
Ranch Hand

Joined: Oct 23, 2003
Posts: 597
I am not sure but just suggesting.

Try to get reference to javax.jms.Connection and call stop method on it on the condition in which you do not want to receive messages.

I have never tried such things. But you may have to do some research.
John Bize
Greenhorn

Joined: Aug 23, 2009
Posts: 5
Well as of right now, I have the message listener container reference as an AbstractJmsListeningContainer, and I call shutdown(), stop(), and destroy() on it.

It seems to behave correctly, but I don't know if it really is.

What's the correct way to safely, reliably, and effectively shut it down (without hanging, blocking, crashing, throwing exceptions, etc.)?

Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Disabling JMS Topic Subscription via property