My scenario is - I post message in to queue and once message is consumed I am sending it to third party middleware application. If that middleware application is down then my posted message gone for toss. I do not want to lose that message if middleware application is down instead I want it to be on hold or waiting in the queue. Please suggest, how to handle this scenario?
You should create the session like this:
Session session = connection.createSession(false,
Session.CLIENT_ACKNOWLEDGE);
when you try to deliver the message to your third party app:
If it's working you should acknoledge the message.
If it is down you should'nt acknwoledge it, this way the JMS provider will be able to rediliver it,and the message will not be lost. message.acknowledge();
Also, you can take a look at this: JMS AUTO_ACKNOWLEDGE when is it acknowledged?