aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes JMS -  Achieving gaurateed sending of  messages in the Queue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "JMS -  Achieving gaurateed sending of  messages in the Queue" Watch "JMS -  Achieving gaurateed sending of  messages in the Queue" New topic
Author

JMS - Achieving gaurateed sending of messages in the Queue

Chetan M
Ranch Hand

Joined: Dec 18, 2002
Posts: 43
I am working with Weblogic 7.1 and using JMS.
I have a component which populates the Queue with messages and a MDB which send messages to the client. Now the problem am facing is,
One Component puts messages in queue, and mdb (onMessage()) called and it tries to send mail. Now suppose smtp(mail) server is down for some reason. So no message delivary takes place. Now when the mail server is up again, unsent messages (which i suppose are recollected by messengin service and kept in queue)are to be sent again.Sending of unsent messages is not happenning. How do we achieve this.
Hope anyone has usefull hint for this issue.
Thanks in advance


No matter how much you know today, you will have to know more tomorrow.<br /> Hakunamatata !!!
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
How is your MDB handling the situation where the mail server is not running? If you're simply swallowing any exceptions and returning from onMessage(), the message you just read from the queue won't be put back. You need to throw an exception...
[ February 03, 2004: Message edited by: Lasse Koskela ]

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Chetan M
Ranch Hand

Joined: Dec 18, 2002
Posts: 43
Originally posted by Lasse Koskela:
..the message you just read from the queue won't be put back. You need to throw an exception...

Well Lasse, i am throwing an exception, but doing nothing with the message. How do i populate queue with the unsent message?.
Sergiu Truta
Ranch Hand

Joined: Dec 16, 2003
Posts: 121
If inside onMessage() you are throwing an exception, the message should be automatically put back into the queue.
If you are throwing an exception, than something else is wrong...show us some code; from it we might figure out what the problem is.


...watch me...as I'm walking the path...
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
My question is...
What type of transactioning is configured for your MDB?
Chetan M
Ranch Hand

Joined: Dec 18, 2002
Posts: 43
Chris , MDB is configured as Container managed one.
Chetan M
Ranch Hand

Joined: Dec 18, 2002
Posts: 43
Sergui, am not throwing any exception instead, loging msg to file n console in the case as shown below.
public void onMessage(Message msg)
{
....
Transport.send(message);
}
catch(JMSException ex)
{
LogTrace.info(ex.getMessage(),ex);
}
catch(SendFailedException sfex)
{
LogTrace.severe(sfex.getMessage(),sfex);

}....
}
If inside onMessage() i throw an exception, are you sure that message is put back into the queue? and any specific exception to be thrown ?
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
Originally posted by Chetan M:
Sergui, am not throwing any exception instead, loging msg to file n console in the case as shown below.

That is your problem... since you are not throwing a system exception and you are not explicitly rolling back the transaction then the message is essentially being discarded.
Originally posted by Chetan M:
If inside onMessage() i throw an exception, are you sure that message is put back into the queue? and any specific exception to be thrown?

Yes, the container is required to place the message back on the Queue if your transaction is marked for rollback. An EJB Container will only automatically mark a transaction to rollback if you throw a system exception (pretty much anything extending from RuntimeException).
FYI, this may not solve your problem completely because the message will just get put back on the Queue and immediately consumed again. Most JMS Providers allow a configurable delay time before the message is resent to deal with these types of situations. Check your JMS Provider's documentation for more details.
Sergiu Truta
Ranch Hand

Joined: Dec 16, 2003
Posts: 121
Chetan, I have also posted this on your other topic:

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JMS - Achieving gaurateed sending of messages in the Queue
 
Similar Threads
JMS queries
JMS - Effect on Message queue on exception in message consumer.
I am befuffled by this behaviour!
component informs other component
Help required on how to use JCA with JMS.