How to gracefully disable Spring JMS MessageListenerAdapter

I have a message handler that consumes from a JMS queue and sends the results to another JMS queue. The message handler lives in Spring DefaultMessageListenerContainer. When the container closes, I would like it to complete processing any requests that it has already consumed and send the results. At the same time, it should no longer consume new messages from the request queue.

Currently, without special shutdown conditions for Safe ApplicationContext.registerShutdownHook (), the container expects the return of pending listernerMethod requests, but does not send the results to the response queue.

What would be the appropriate approach to ensure that responses executed by handlers are sent to the response queue?

+3
source share
1 answer

I think the path should go through an interface DisposableBeanor annotation @PreDestroy. The main thing is that IMHO does not allow Spring to close the DMLC, but rather allow it to execute a component that knows the messages that are currently "located inside the system." This way you will stop listening to new messages, waiting for the completion of currently completed messages.

Using the attribute depends-onin bean declarations, you can also disable the beans order. Once again about this in the Spring help documentation .

+2
source

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


All Articles