tags:

views:

733

answers:

1

I have a message handler, which consumes from a JMS queue and that sends results to another JMS queue. The message handler lives in a Spring DefaultMessageListenerContainer. When the container shuts down, I would like for it to finish handling any requests that it already consumed and send out the results. At the same time, it should no longer consume any new messages from the request queue.

Right now, with no special shutdown provisions safe ApplicationContext.registerShutdownHook(), the container waits for any pending listernerMethod invocations to return, but it isn't sending out the results to the response queue.

What would be the appropriate approach for making sure that responses produced by running handlers are sent to the response queue?

+2  A: 

I think the way to go has to lead via DisposableBean interface or @PreDestroy annotation. The key thing IMHO is not to let Spring shut down the DMLC but rather let this being done by a component that is aware of messages currently "inside the system". This way you stop listening for new messages while waiting for currently proccessed messages to be finished.

Using the depends-on attribute on bean declarations you can also define the order of beans to be shut down. Red more on this in the Spring reference documentation.

Oliver Gierke