user1407668
user1407668

Reputation: 617

How to check message sending to a JMS queue was unsuccessful?

I have a requirement where I have to log an error message if the JMS messsage has not been sent to the queue.

How can I check whether the message has not been sent?

Code:

...
...   
QueueSender send = session.createSender(queue);
TextMessage tm = session.createTextMessage(message);

send.send(tm);
log.debug("Sent text=" + tm.getText());
...
...

Thanks in advance

Upvotes: 2

Views: 6397

Answers (3)

Yasir Shabbir Choudhary
Yasir Shabbir Choudhary

Reputation: 2578

The Oracle documentation says:

For more flexibility, Message Queue lets you customize the JMS client-acknowledge mode. In client-acknowledge mode, the client explicitly acknowledges message consumption by invoking the acknowledge() method of a message object.

Upvotes: 0

Shashi
Shashi

Reputation: 15283

Catching exception from the send call is enough. No need to set the delivery mode as PERSISTENT as this option makes all messages as persistent even when you want the message to be non-persistent.

try
{
  qsender.Send(msg);
}
catch(JMSException je)
{
}

Upvotes: 1

mcfinnigan
mcfinnigan

Reputation: 11638

use DeliveryMode.PERSISTENT to ensure it will be persisted and delivered, and catch the JMSException which is raised if send() fails?

Upvotes: 1

Related Questions