Author |
Message
|
fredand44 |
Posted: Wed Apr 02, 2008 6:26 am Post subject: Is there a way to know if the message has received to a MQ? |
|
|
Acolyte
Joined: 14 Feb 2006 Posts: 63
|
Hello!
I 'm running in a bean-managed-transacted environment in WebLogic.
I got a MDB consuming messages from a queue inside WebLogic.
The MDB should forward this message to a MQ queue.
In the MDB I'm doing like this:
onMessage(Message m)
{
sendMessageForwardToMq(m)
}
sendMessageForwardToMq(Message m)
{
Properties properties = new Properties();
properties.setProperty("java.naming.factory.initial", "com.sun.jndi.fscontext.RefFSContextFactory");
properties.setProperty("java.naming.provider.url", "file:C://folder");
Context ctxNaming = new InitialContext(properties);
QueueConnectionFactory factory = (QueueConnectionFactory) ctxNaming.lookup("MY_QUEUE_CON_FACT");
QueueConnection connection = factory.createQueueConnection();
connection.start();
QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = (Queue) ctxNaming.lookup("MY_QUEUE");
QueueSender sender = session.createSender(queue);
BytesMessage responseMessage = session.createBytesMessage();
responseMessage.writeBytes("a message".getBytes());
sender.send(responseMessage);
session.close();
connection.close();
}
Now I wonder if I could find out if the message successfully has arrived to MQ, before the method "sendMessageForwardToMq" returns?
Most thankfull for any comments.
Best regards
Fredrik |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Apr 02, 2008 6:40 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
If sender.send doesn't thrown an exception, then the message is sent. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
fredand44 |
Posted: Wed Apr 02, 2008 10:40 am Post subject: But can I be sure... |
|
|
Acolyte
Joined: 14 Feb 2006 Posts: 63
|
Hello!
That came to me as well on the bus home!
No exception = No problems
Exception = Problems.
As you said ... message sent.
But can I be sure it arrived?
Best regards
Fredrik |
|
Back to top |
|
 |
bower5932 |
Posted: Wed Apr 02, 2008 11:29 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
If you need to check arrival, you could look into using COA/COD (confirmation of arrival/delivery). |
|
Back to top |
|
 |
fredand44 |
Posted: Wed Apr 02, 2008 12:22 pm Post subject: Hmm!! |
|
|
Acolyte
Joined: 14 Feb 2006 Posts: 63
|
|
Back to top |
|
 |
Vitor |
Posted: Wed Apr 02, 2008 12:46 pm Post subject: Re: Hmm!! |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
fredand44 wrote: |
Very interesting (COA)
|
Beware this slippery slope.
If you rely on COA messages to prove arrival, rather than relying on the years of patient research IBM have put into the product, then you need to code a mechanism for deailing with the situation where the message arrives ok, but the COA is delayed or lost.
This has been discussed before on the forum. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Apr 02, 2008 12:52 pm Post subject: Re: Hmm!! |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Vitor wrote: |
fredand44 wrote: |
Very interesting (COA)
|
Beware this slippery slope. |
 _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
|