Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JMS - Effect on Message queue on exception in message consumer.

 
Chetan M
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose a process puts a message in queue and say a mdb receives it and sends a mail to say client.
Now if during mdb is sending message, any exception occurs, message is not sent. Then what will happen to the message. What will be the queue state, Will the unsent message be sent back to the queue, If not how can that be achieved.
 
Sergiu Truta
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you throw an exception from inside onMessage(), the container will know that it has to put the message back into the Queue.
 
Chetan M
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sergiu truta:
If you throw an exception from inside onMessage(), the container will know that it has to put the message back into the Queue.

which exception should be thrown. throwing JMSException will do??
of any other exception has to be thrown.
 
Sergiu Truta
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Throw a system exception or rollback the transaction. For example:
inside your MDB you have:
private MessageDrivenContext ctx;
public void onMessage(Message msg){
....
//if you want to put the message back into the queue
ctx.setRollbackOnly();

Try these options.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic