Author |
Message
|
jayk0120 |
Posted: Thu Dec 08, 2005 11:33 pm Post subject: Non Destructible Reads!! Pl Help! |
|
|
Novice
Joined: 08 Dec 2005 Posts: 12
|
Hi Guys
I m new to the Wesbphere MQ 6.0 world..I need to implement this scenario...I want to make sure that after I read off the queue in MQ I do NOT want the message to be deleted from the queue immediately. Once I have processed the message successfully, I want to explicilty go and delete the message, based on certian conditions. I am using JMS...Does anyone know how to do this? Can anyone point me to some samples which do this?
Also if you guys know any good books/websites/sources which go in real depth related to MQ, that would be a gr8 help. I have read Enterprise Messaging using JMS and Websphere by Kareem Yusuf, it was good for basics but I need some book or resource which goes deeper using good examples.
Do u guys know if there are any good books? Also some sites to download good sample programs that will help me further my knowledge?
Thanks in advance!!
Jay |
|
Back to top |
|
 |
hopsala |
Posted: Fri Dec 09, 2005 12:29 am Post subject: Re: Non Destructible Reads!! Pl Help! |
|
|
 Guardian
Joined: 24 Sep 2004 Posts: 960
|
jayk0120 wrote: |
I want to make sure that after I read off the queue in MQ I do NOT want the message to be deleted from the queue immediately. |
Well, i'm not what you call a grand JMS programmer, but it took me five seconds to find "QueueBrowser" class in the WMQ Java manual... I'm sure the answer to your other q is also there somewhere.
jayk0120 wrote: |
Also if you guys know any good books/websites/sources which go in real depth related to MQ, that would be a gr8 help. |
Well, as far as sites are concerned, I say without exaggeration that this site is the best there is; Post here and yee shall be answered (it it's not in the manuals, otherwise yee shall not be answered...)
Books? Well, there's the WMQ familiy manuals, which are quite good, there are the IBM Redbooks which are as in-depth as it gets.
Samples are best tracked through here (some on this page in "repository", some in capitalware inc site, others floating about the site). Also, after installing a Qmgr samples are installed in your /tools directory.
All these are quite easily tracked through google, please don't make me post redundantly  |
|
Back to top |
|
 |
zpat |
Posted: Fri Dec 09, 2005 12:46 am Post subject: |
|
|
 Jedi Council
Joined: 19 May 2001 Posts: 5866 Location: UK
|
Sounds like you should use transactional mode MQGET with SYNCPOINT and commit/rollback when ready.
You don't really want to browse a message, as this would prevent another instance of your adapter reading the same queue (since it might get the same message). |
|
Back to top |
|
 |
hopsala |
Posted: Fri Dec 09, 2005 6:24 am Post subject: |
|
|
 Guardian
Joined: 24 Sep 2004 Posts: 960
|
zpat wrote: |
Sounds like you should use transactional mode MQGET with SYNCPOINT and commit/rollback when ready.
You don't really want to browse a message, as this would prevent another instance of your adapter reading the same queue (since it might get the same message). |
To clarify - It's not that it would prevent another instance from reading the queue, it's just that both might receive the same message; this is not a problem, it merely requires a different design scheme - locks etc.
The commit/rollback design, on the other hand, isn't really appropriate for an administrative browsing application used for maintenance, as i'm sure you'll agree; other than the fact that it does not allow you to comfortably pick one message out of an entire batch, that's what browse is for - and you can always MQOPEN exclusively.
However, all this depends on what exactly this application is meant to do... jayk? |
|
Back to top |
|
 |
jayk0120 |
Posted: Fri Dec 09, 2005 7:43 am Post subject: |
|
|
Novice
Joined: 08 Dec 2005 Posts: 12
|
Thanks guys for the help..do you guys have any sample java code that i could look at?
Heres what we are trying to do:
We have 2 different application A and B which need to communicate using MQ. App A sends a document on a remote queue which App B is listening on. Once App B receives the document(message) it starts processing the doc. If the doc processes successfully within App B, then the document needs to get deleted from the queue. If not it should remain in the queue A message must be sent bck to the App A indicating the status of whether the doc processed or not. |
|
Back to top |
|
 |
jefflowrey |
Posted: Fri Dec 09, 2005 7:46 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Then you want to use a request/reply pattern, and a transaction.
And you should consider exactly why you want the reply, and whether it is really necessary or not.
If you are just sending back a "Everything worked" to a user, then you probably really don't need the reply.
If you are sending back new business data, then of course you need it. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
hopsala |
Posted: Sat Dec 10, 2005 4:12 am Post subject: |
|
|
 Guardian
Joined: 24 Sep 2004 Posts: 960
|
jayk0120 wrote: |
Thanks guys for the help..do you guys have any sample java code that i could look at? |
hopsala wrote: |
Samples are best tracked through here (some on this page in "repository", some in capitalware inc site, others floating about the site). Also, after installing a Qmgr samples are installed in your /tools directory. |
Onwards...
jayk0120 wrote: |
Once App B receives the document(message) it starts processing the doc. If the doc processes successfully within App B, then the document needs to get deleted from the queue. |
Then you should not use BROWSE but do what zpat said - use syncpoint, MQGET destructively, and if indeed the document was processed successfully MQCMIT it, otherwise MQBACK. Browse, as I had already mentioned, is best used in other scnearios. Just don't forget to use a backout queue.
jayk0120 wrote: |
If not it should remain in the queue A message must be sent bck to the App A indicating the status of whether the doc processed or not. |
As jeff said, you should serious reconsider this - why send a reply at all? What can the sending application do but re-send, which is entirely unnecessary when WMQ is concerned. Assured delivery is not a fantasy, you can and should design accordingly. |
|
Back to top |
|
 |
fjb_saper |
Posted: Sat Dec 10, 2005 11:52 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
When you create your JMS session make it transactional.
Code: |
Session session =conn.createSession(true, Session.AUTO_ACKNOWLEDGE);
// Here your normal code
// Than do not forget to commit or rollback
if (ok){
session.commit();
}else {
session.rollback();
} |
Enjoy  |
|
Back to top |
|
 |
jayk0120 |
Posted: Mon Dec 12, 2005 7:13 am Post subject: |
|
|
Novice
Joined: 08 Dec 2005 Posts: 12
|
Thanks again for all your help guys..
Session session =conn.createSession(true, Session.AUTO_ACKNOWLEDGE);
// Here your normal code
// Than do not forget to commit or rollback
if (ok){
session.commit();
}else {
session.rollback();
}
Question: In my case I am using an MDB to listen on the queue( ie on the App B side). In this case how do I use the above commit/rollback code, in case of the MDB. The OnMessage event just has a reference to the message :
public void onMessage(javax.jms.Message msg). How do I get an access to the session to do a commit/rollback.
Also when I rollback the transaction, does the sending Queue Manager automatically resend the message? Or do I need to take care of that? And if it does, will this not go into an infinite loop? How do I take care of this situation?
Sorry if my questions seem amateurish...I m just a beginner..so please bear with me  |
|
Back to top |
|
 |
hopsala |
Posted: Mon Dec 12, 2005 11:03 am Post subject: |
|
|
 Guardian
Joined: 24 Sep 2004 Posts: 960
|
jayk0120 wrote: |
Also when I rollback the transaction, does the sending Queue Manager automatically resend the message? Or do I need to take care of that? |
Commit/rollback are common industry terms usually related to databases which here apply to WMQ; it's something your going to have to learn someday so i'd suggest starting now - by reading the manuals.
jayk0120 wrote: |
And if it does, will this not go into an infinite loop? How do I take care of this situation? |
hopsala wrote: |
Just don't forget to use a backout queue. |
Search for "backout queue" or "poisoned message" on this site to learn more, I found Resubmitting backed-out messages, for example.
The moral of the story is that I appreciate the fact your a bit green, but that's no excuse not to hit the books or use the search button; in fact, quite the opposite... |
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Dec 12, 2005 2:28 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Check out the MDB manuals and the MDB deployment descriptors.
The transaction is either container or bean managed.
Enjoy  |
|
Back to top |
|
 |
jayk0120 |
Posted: Tue Dec 13, 2005 1:12 pm Post subject: |
|
|
Novice
Joined: 08 Dec 2005 Posts: 12
|
Hi Guys thanks for ur messages again..
Believe me, I m reading books on this subject and trying to look at all resources available..but have a very tight deliverable, so it really helps to get a jumpstart
I have configured the MDB,so that its Container managed. Also the Connection Factory and the JDBC Data Source is XA enabled.
From what I understood from stuff I read, if there are any exceptions raised in the OnMessage event(for ex,in my case I deliberately created a condition such that an update statment fails), the transaction which got initiated on the onMessage event, should automatically roll back. Also the sent message should automatically be retained in the queue, and the Listener port should try to send the message again, since I have set the max retry option for the Listener port to 5. Am I correct? But somehow this doesnt seem to be happening..the message is still being deleted from the queue, and there is no automatic re send. Is there any other setting that I am missing?
Would appreciate ur help as always...thanks in advance!! |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Dec 13, 2005 8:45 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
if your message is persistent and your queue has a backout threshold of less than the MDB retry count and > 0 check the back out queue. If the backout queue is not defined check the DLQ.
If your message is non persistent you will have to investigate what happens... I would expect the same as if it is persistent but would not guarantee it.
Otherwise your MDB should stop working after having hit the retry count and you have a poison message.
Enjoy  |
|
Back to top |
|
 |
|