I have multiple message containers with one listener each.
- Is not thread-safe
- Is declared @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
- Is not stateless. it has an internal buffer of processed messages
- Every X messages received it flushes the buffer to disk
Writing to this type of disk is very expensive and the only way to achieve the desired throughput is to only flush the buffer every X messages.
Each listener writes to their own files so that there is no need for locking.
I want to flush the buffers when the spring container is shutdown.
Each listener implements DisposableBean and a destroy() method to flush the buffer.
After some research I found out that since the beans are declared as scope prototype, the destroy method will never be called by spring because it stops managing the bean after its creation.
How can I cleanup the remaining messages in the buffer when spring shuts down in this situation?
Is there a hook in the SimpleMessageListenerContainer that I can use to call the destroy method in my listener?