To consume messages from a Persistent queue in an old monolithic app, I had used javax.jms.MessageListener#onMessage(javax.jms.Message)
10 years ago.
For a new spring-boot app, I am looking to use Solace Java API and going through provided samples.
e.g. HowToConsumePersistentMessageWithAutoAcknowledgement and HelloWorld
I noticed receiveAsync
of PersistentMessageReceiver
fetches waiting/pending messages in the queue and finishes the thread immediately, instead of waiting for a future message. receiveAsync
call requires to be in a while
loop if more messages are expected for future messages based on samples. I am not sure if using while
loop is an elegant solution (was expecting something similar to onMessage
).
Should I use receiveAsync
in a while
loop, with a flag pushed from app/spring bean shutdown
? Is my approach wrong? Please guide me in the right direction.