Author |
Message
|
errorken |
Posted: Wed Nov 23, 2005 2:39 am Post subject: Accessing Dead Letter Queue with java client |
|
|
Newbie
Joined: 23 Nov 2005 Posts: 8
|
We are using websphere and the internal websphere jms server (which is a light version of MQ) . Now, when messages are written to the DLQ, how on earth can I get them back out using a java program?
I found many topics on internet how to do this with MQ tools, but for starters we do not have a full MQ series, so we also do not have all of those tools. Second, I want to read the queue with an ordinary java program (I want to extract messages from that queue like I do with other queues)
I read the manuals etc, they mention how to create the DLQ with MQ tools , how to specify a DLQ, but nowhere how to lookup and read messages from a DLQ.
If I create a queue I can specify a jndi name for it (jms/myQueue) however I can never see any DLQ deployed... its a mistery.
Thanks ! |
|
Back to top |
|
 |
bower5932 |
Posted: Wed Nov 23, 2005 3:35 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
The dead letter queue is just another WMQ queue. You can access it with any kind of program. The only thing that is special about it is the fact that the messages on it will have the dead letter queue handler (DLH). You'll need to skip over this to get to the 'actual message'. |
|
Back to top |
|
 |
hopsala |
Posted: Wed Nov 23, 2005 4:09 am Post subject: |
|
|
 Guardian
Joined: 24 Sep 2004 Posts: 960
|
Aside from what bower said, I would add: If you're going to write a dlq handler (btw, why?) first thing you should do is look up the internet and this site for samples; there's a good chance someone has already written it for you, or has at least written something similar you can use as a skeleton for your handler.
Second, in the beginning of your code MQINQ (use java equivalent) the QManager to see what the DLQ is, don't rely on a hard-coded standard. Also add the option to specify the DLQ name in the first parameter, for special cases. |
|
Back to top |
|
 |
errorken |
Posted: Wed Nov 23, 2005 4:09 am Post subject: |
|
|
Newbie
Joined: 23 Nov 2005 Posts: 8
|
Thanks for your reply. I allready know that the DLQ is an ordinary queue and that I should be able to access it as any other queue.
Let me explain how I access an ordinary queue:
1. I open my websphere admin console and go to the JMS part
2. I add a connection factory and add a location to it so I can access it over JNDI (ex. jms/myConnectionFactory)
3. I add a queue and add a location to it so I can access it over JNDI (ex. jms/myQueue)
Now I'm able to lookup the connetion factory and the queue fom jndi within my java code. I use the connection factory to create a session to which I pass a reference to the queue.
I know I should be able to do the same thing with the DLQ. But what is the queue NAME of the DLQ ??
When I look with the JNDI explorer I see that my queue and connection factory are there (jms/myConnectionFactory and jms/myQueue) but I don't see any other additional queues , such as jms/DLQ for example....
I need the JNDI name to be able to connect to that quueue, or another wy (using java) to get to that queue...there is NOWHERE information on this subject
(yes there are tons of information howto access the DLQ on a MQ series using some IBM tools. but I don't have/want those tools. I want to access it from java code)
Thanks. |
|
Back to top |
|
 |
errorken |
Posted: Wed Nov 23, 2005 4:15 am Post subject: |
|
|
Newbie
Joined: 23 Nov 2005 Posts: 8
|
hopsala wrote: |
Aside from what bower said, I would add: If you're going to write a dlq handler (btw, why?) first thing you should do is look up the internet and this site for samples; there's a good chance someone has already written it for you, or has at least written something similar you can use as a skeleton for your handler.
Second, in the beginning of your code MQINQ (use java equivalent) the QManager to see what the DLQ is, don't rely on a hard-coded standard. Also add the option to specify the DLQ name in the first parameter, for special cases. |
ex. our MDB receives messages and persists them in the db. When the db is out for a certain time, messages are not acknowledged and endup in the DQL after the specified retry count.
I'm writing a small program that should read the messages in the DLQ (at midnight for example) and inserts them into the db.
Can you give me some examples of using QueueManager ? We simply use the J2EE API for accessing the JMS, the QueueManager seems IBM properetary... |
|
Back to top |
|
 |
bower5932 |
Posted: Wed Nov 23, 2005 6:42 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
errorken wrote: |
Can you give me some examples of using QueueManager ? We simply use the J2EE API for accessing the JMS, the QueueManager seems IBM properetary... |
Your J2EE program should be using a QCF and a Q to access the IBM proprietary objects. The QCF and Q are not IBM proprietary. They just 'hide' what is - the queue manager and queue. |
|
Back to top |
|
 |
bower5932 |
Posted: Wed Nov 23, 2005 6:44 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
errorken wrote: |
I know I should be able to do the same thing with the DLQ. But what is the queue NAME of the DLQ ?? |
You mentioned that you are using the embedded JMS. If you were to use runmqsc, you could get the name of the DLQ and then put this in a 'WMQ JMS QCF and Q resource' that you could get at. However, the bottom line in your scenario is that there never were a lot of administration tools to deal with the underlying WMQ from the Admin Console. I think this is some of the struggle that you are dealing with. |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Nov 23, 2005 11:49 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
The typical default DLQ is SYSTEM.DEAD.LETTER.QUEUE.
Now as you are talking about backout queues you would have to check on each queue what the value of the backout queue is. See support pack MS0B. If a backout queue name is not specified WAS puts the messages on the DLQ. MS0B should allow you to find out the DLQ name as it is an attribute of the qmgr.
If you read messages from the DLQ you need to treat them as BytesMessages and interpret the DLQ header.
If you read messages from a backout queue they keep the format they had on the original queue.
Enjoy  |
|
Back to top |
|
 |
errorken |
Posted: Fri Nov 25, 2005 12:02 pm Post subject: |
|
|
Newbie
Joined: 23 Nov 2005 Posts: 8
|
Ok, I'm posting a follow up for this problem.
It seems that my problem was related to the fact that a DLQ is not visible in JNDI tree of websphere. The trick is to specify the name of the queue rather then passing it a remote instance of the queue looked up from JNDI.
So, I did this:
1. lookup the connection factory from JNDI
2. create a QueueSession from the QueueConnection retrieved from the QueueConnectionFactory
3. use the createQueue() on the session to get a reference to the queue, rather then looking it up from JNDI (in the case of a DLQ) so my code is :
Code: |
Queue queue = queueSession.createQueue("SYSTEM.DEAD.LETTER.QUEUE");
queueReceiver = queueSession.createReceiver(queue);
|
Then I was thinking why should I still bother looking up my own queues from jndi first ? Basicly I can just specify the name there rather then looking them up first. I tried this, but then the queue is not recognized... |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri Nov 25, 2005 6:07 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
You need to check the queue manager. The SYSTEM.DEAD.LETTER.QUEUE is not necessarily the DLQ. Do
Code: |
echo "dis qmgr deadq" | runmqsc <QMGRNAME> |
This will show you the name of the DLQ.
The other way you should try is using the uri:
Code: |
session.CreateQueue("queue:///SYSTEM.DEAD.LETTER.QUEUE"); |
If you need to go dynamic get the information on the qmgr from the qcf (You can cast it to an MQQueueConnectionFactory) and use MS0B.
The same way you can cast a queue to MQQueue and obtain the base information on it. Then use MS0B to get the backout queue and threshold...
Enjoy  |
|
Back to top |
|
 |
errorken |
Posted: Mon Nov 28, 2005 1:50 am Post subject: |
|
|
Newbie
Joined: 23 Nov 2005 Posts: 8
|
Yes, I've allready seen I can cast the CF to an MQCF, but I could not do anything more with it. What is the MS0B ??
About the DLQ: it is hard-coded in the websphere JMS configuration files, remember, I'm not using a REAL MQ here, so the DQL is actually not configurable. |
|
Back to top |
|
 |
bower5932 |
Posted: Mon Nov 28, 2005 7:41 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
MS0B is a SupportPac that provides the PCF (programmable command formats) support for java. It allows you to 'programmatically' do management of your WMQ system. |
|
Back to top |
|
 |
WingCommanderBadger |
Posted: Tue Dec 13, 2005 3:47 am Post subject: |
|
|
 Apprentice
Joined: 06 Sep 2005 Posts: 32 Location: London, UK
|
I don't think you can use SupportPac MS0B easily in conjunction with JMS though. I tried it when writing an MQ Event Monitor - the problem from what I recall is that the the PCFMessage contructor expects a MQMessage as a parameter and not a JMSMessage.
I found I had to use the Base MQ Java API instead.
If anyone figures out how to use MS0B easily in conjunction with JMS let me know though!  |
|
Back to top |
|
 |
|