Author |
Message
|
tisaroo55 |
Posted: Fri Nov 08, 2013 7:32 am Post subject: Java code to access a Topic |
|
|
Novice
Joined: 05 Nov 2012 Posts: 12
|
Hello MQ people who are way smarter than I:
I need to get a message off of a topic, this application would be run only occasionally. I have setup subscriptions in MQ Explorer so I am fairly certain my topic and topic string parameters are correct here. When I run this I get a 2033: message not found. Help?
MQEnvironment.hostname = "iaamsg02";
MQEnvironment.port = 1415;
MQEnvironment.channel = "AIO.SVRCONN";
MQQueueManager qMgr = new MQQueueManager("IAAMSGB2.WMB");
MQTopic subscriber = qMgr.accessTopic("$SYS/Broker/IAAMSGB2.BRK/ResourceStatistics/DPM/#", "SYSTEM.BROKER.MB.TOPIC", CMQC.MQTOPIC_OPEN_AS_SUBSCRIPTION, CMQC.MQSO_CREATE);
MQMessage TopicMessage = new MQMessage();
MQGetMessageOptions get_message_options = new MQGetMessageOptions();
subscriber.get(TopicMessage, get_message_options);
String msg = TopicMessage.readString(TopicMessage.getMessageLength());
System.out.println("Here comes the message: " + msg);
Thanks for your attention. |
|
Back to top |
|
 |
Vitor |
Posted: Fri Nov 08, 2013 7:37 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
What version of WMQ?
When you run the code, what assurance do you have that there's actually a published message waiting for you? Is it retained? How do you know that the 2033 is not legitimately telling you there's nothing currently published on that topic but if you hang around one might show up?
You already said the publishing application only runs occassionally. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
tisaroo55 |
Posted: Fri Nov 08, 2013 9:09 am Post subject: |
|
|
Novice
Joined: 05 Nov 2012 Posts: 12
|
Very true. Now, this code does return a message:
while (true) {
try {
MQEnvironment.hostname = "iaamsg02";
MQEnvironment.port = 1415;
MQEnvironment.channel = "AIO.SVRCONN";
MQQueueManager qMgr = new MQQueueManager("IAAMSGB2.WMB");
MQTopic subscriber = qMgr.accessTopic("$SYS/Broker/IAAMSGB2.BRK/#", "", CMQC.MQTOPIC_OPEN_AS_SUBSCRIPTION, CMQC.MQSO_CREATE);
MQMessage TopicMessage = new MQMessage();
MQGetMessageOptions get_message_options = new MQGetMessageOptions();
MQMessage myMessage = new MQMessage();
subscriber.get(TopicMessage);
subscriber.get(TopicMessage, get_message_options);
String msg = TopicMessage.readString(TopicMessage.getMessageLength());
System.out.println("Here comes the message: " + msg);
qMgr.close();
Thread.sleep(300);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
And I get this message up many times:
"Here comes the message: <Broker uuid="fde56333-2301-0000-0080-9167eb83202c" label="IAAMSGB2.BRK" version="1"><StatusChange new="Started"/></Broker>"
I have tried different Topic and TopicString values...to no avail. If anyone has an idea of how to access the ResourceStatistics Topic messages that are available on MQ when ResourceStatistics are enabled on a Message Broker Execution Group I would appreciate hearing an opinion.
I got Java code, that got a Message off of a queue, working when I created a Subscription to the Topic that pointed at a Queue but now I have a queue that fills up with messages that do not expire: the queue will fill up.
Thanks again. |
|
Back to top |
|
 |
tisaroo55 |
Posted: Fri Nov 08, 2013 9:25 am Post subject: WMQ = 7.0.1.9 |
|
|
Novice
Joined: 05 Nov 2012 Posts: 12
|
|
Back to top |
|
 |
Vitor |
Posted: Fri Nov 08, 2013 9:28 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
tisaroo55 wrote: |
If anyone has an idea of how to access the ResourceStatistics Topic messages that are available on MQ when ResourceStatistics are enabled on a Message Broker Execution Group I would appreciate hearing an opinion. |
Well you could try using a tighter topic string, the one shown in the resource statistics section of the InfoCenter here. The topic string you're using will work but the wild card is too far up so you're getting all of the broker produced messages (the example you posted is an accounting statistics message).
You could also leave the topic string as you have it, and put code to identify what kind of message you're received. Pros and cons to both methods. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
tisaroo55 |
Posted: Fri Nov 08, 2013 10:41 am Post subject: |
|
|
Novice
Joined: 05 Nov 2012 Posts: 12
|
I have tried everything and read the link you sent. I am able to subscribe and get only the messages I want when I use a subscriber, I make on MQ Explorer, that points at a queue.
Can you give me your opinion: is there anything I can do, the MQ configuration, to make it so these messages that are piling up in said queue (coming from said subscription) expiry? The subscription is putting them on the queue with no expiration time as of now.
thanks. |
|
Back to top |
|
 |
Vitor |
Posted: Fri Nov 08, 2013 12:18 pm Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
tisaroo55 wrote: |
is there anything I can do, the MQ configuration, to make it so these messages that are piling up in said queue (coming from said subscription) expiry? The subscription is putting them on the queue with no expiration time as of now. |
So if you only want resource statistics when this application of yours runs:
- Why? Why don't you care about broker resource usage the rest of the time
- Only enable resource statistics when you run the application
What exactly do you plan to use these resource statistics for? What you're describing is a very odd use case, and I wonder if some of the other WMB statistic messages might not suit you better. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
fjb_saper |
Posted: Sat Nov 09, 2013 1:46 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
tisaroo55 wrote: |
Very true. Now, this code does return a message:
Code: |
while (true) {
try {
MQEnvironment.hostname = "iaamsg02";
MQEnvironment.port = 1415;
MQEnvironment.channel = "AIO.SVRCONN";
MQQueueManager qMgr = new MQQueueManager("IAAMSGB2.WMB");
MQTopic subscriber = qMgr.accessTopic("$SYS/Broker/IAAMSGB2.BRK/#", "", CMQC.MQTOPIC_OPEN_AS_SUBSCRIPTION, CMQC.MQSO_CREATE);
MQMessage TopicMessage = new MQMessage();
MQGetMessageOptions get_message_options = new MQGetMessageOptions();
MQMessage myMessage = new MQMessage();
subscriber.get(TopicMessage);
subscriber.get(TopicMessage, get_message_options);
String msg = TopicMessage.readString(TopicMessage.getMessageLength());
System.out.println("Here comes the message: " + msg);
qMgr.close();
Thread.sleep(300);
} catch (InterruptedException e) {
e.printStackTrace();
}
} |
And I get this message up many times:
"Here comes the message: <Broker uuid="fde56333-2301-0000-0080-9167eb83202c" label="IAAMSGB2.BRK" version="1"><StatusChange new="Started"/></Broker>"
I have tried different Topic and TopicString values...to no avail. If anyone has an idea of how to access the ResourceStatistics Topic messages that are available on MQ when ResourceStatistics are enabled on a Message Broker Execution Group I would appreciate hearing an opinion.
I got Java code, that got a Message off of a queue, working when I created a Subscription to the Topic that pointed at a Queue but now I have a queue that fills up with messages that do not expire: the queue will fill up.
Thanks again. |
Why oh why do you guys think that setting a loop around existing code solves your problem? you're just compounding as shown by the results.
You need to set your subscription and close qmgr outside of the loop.
Closing the qmgr just kills your current subscription...
In fact let me suggest a completely different approach.
Create an administrative subscription (using mqsc for creating a durable subscription) and have it delivered to some queue. All you need to do then is read/drain the queue specified in the administrative subscription...
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
tisaroo55 |
Posted: Mon Nov 11, 2013 10:09 am Post subject: |
|
|
Novice
Joined: 05 Nov 2012 Posts: 12
|
Thanks for your attention. I have implemented your idea of doing a subscription pointed to a queue then getting the message off the queue. The issue I have with that idea is now I have a queue that is filling up and eventually it will fill. I did not notice a way to have these messages have an expiry time, so they go away at some point. Any ideas on how to clean up this queue we are speaking of? The application that is accessing this queue is a status web application: it may be executed once an hour or once in a month so I was hoping that the solution that deals with the old messages on the queue was not dealt with by the application in question.
So, I guess my question has changed: what is the best way to have the messages that get put on this QLOCAL from the subscription get an expiry time put on them?
Thanks. |
|
Back to top |
|
 |
smdavies99 |
Posted: Mon Nov 11, 2013 12:54 pm Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
Allowing Publications to a Queue to have an expiry is something that I have asked for several times. There may even be an RFE on the subject. _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Nov 11, 2013 9:20 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
tisaroo55 wrote: |
So, I guess my question has changed: what is the best way to have the messages that get put on this QLOCAL from the subscription get an expiry time put on them?
Thanks. |
Have an always on app running saving the data to a DB. Offload old data from the DB as needed. Have the web app query the DB.
Typically this is how monitoring software does it...  _________________ MQ & Broker admin |
|
Back to top |
|
 |
PeterPotkay |
Posted: Tue Nov 12, 2013 4:24 am Post subject: |
|
|
 Poobah
Joined: 15 May 2001 Posts: 7722
|
smdavies99 wrote: |
Allowing Publications to a Queue to have an expiry is something that I have asked for several times. There may even be an RFE on the subject. |
I looked on the RFE page and could not find one. It seems like such a basic thing it makes me wonder why Expiry wasn't implemented on Day one with Pub Sub. I'm thinking it would be nice for a Publisher and/or a Subscriber to be able to set Expiry. It might get confusing when they both set it to different values, but if there were clear rules on what happened in that case it should aceptable. _________________ Peter Potkay
Keep Calm and MQ On |
|
Back to top |
|
 |
|