Edited Question : I am working on a multithreaded JMS receiver and publisher code (stand alone multithreaded java application). MOM is MQSonic.
XML message is received from a Queue, stored procedures(takes 70 sec to execute) are called and response is send to Topic within 90 sec.
I need to handle a condition when broker is down or application is on scheduled shutdown. i.e. a condition in which messages are received from Queue and are being processed in java, in the mean time both Queue and Topic will be down. Then to handle those messages which are not on queue and not send to topic but are in java memory, I have following options:
(1) To create CLIENT_ACKNOWLEDGE session as :
connection.createSession(false, javax.jms.Session.CLIENT_ACKNOWLEDGE)
Here I will acknowledge message only after the successful completion of transactions(stored procedures)
(2) To use transacted session i.e., connection.createSession(true, -1). In this approach because of some exception in transaction (stored procedure) the message is rolled back and Redelivered. They are rolled back again and again and continue until I kill the program. Can I limit the number of redelivery of jms messages from queue?
Also in above two approached which one is better?
The interface
progress.message.jclient.ConnectionFactoryhas a methodsetMaxDeliveryCount(java.lang.Integer value)where you can set the maximum number of times a message will be redelivered to yourMessageConsumer. When this number of times is up, it will be moved to theSonicMQ.deadMessagequeue.You can check this in the book “Sonic MQ Application Programming Guide” on page 210 (in version 7.6).
As to your question about which is better… that depends on whether the stored procedure minds being executed multiple times. If that is a problem, you should use a transaction that spans the JMS queue and the database both (Sonic has support for XA transactions). If you don’t mind executing multiple times, then I would go for not acknowledging the message and aborting the processing when you notice that the broker is down (when you attempt to acknowledge the message, most likely). This way, another processor is able to handle the message if the first one is unable to do so after a connection failure.
If the messages take variable time to process, you may also want to look at the
SINGLE_MESSAGE_ACKNOWLEDGEmode of the Sonic JMS Session. Normally, callingacknowledge()on a message also acknowledges all messages that came before it. If you’re processing them out of order, that’s not what you want to happen. In single message acknowledge mode (which isn’t in the JMS standard),acknowledge()only acknowledges the message on which it is called.