ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ Java / JMS » Reading messages from a queue

Post new topic  Reply to topic
 Reading messages from a queue « View previous topic :: View next topic » 
Author Message
Prasi
PostPosted: Mon Dec 09, 2013 1:28 pm    Post subject: Reading messages from a queue Reply with quote

Apprentice

Joined: 03 Aug 2011
Posts: 42

Hi,

I am writing the below code in Java compute node: I am iterating to a collection of queues which have the status as either AVAILABLE/LOCKED.
When I see a queue to have a queue which has a message written as "LOCKED", I should read the message and update as "AVAILABLE". This is happening for some 10 tests. And after 12,13 test,the queue is not writing the "AVAILABLE" message to it. The queue is getting read and not writing "AVAILABLE" message to it. Is there any problem with the below code?

try
{
int openOptions=CMQC.MQOO_INPUT_SHARED | CMQC.MQOO_BROWSE;
MQQueue locQueue=qMgr.accessQueue(statusQueue, openOptions);
MQGetMessageOptions gmo=new MQGetMessageOptions();
locQueue.get(msg,gmo);
locQueue.close();
ch(MQException ex) {
System.out.println("An error occurred during the get operation:" + "CC = " + ex.completionCode + "RC = " + ex.reasonCode);
System.out.println("Cause exception:" + ex.getCause() );
}
String msgText=msg.readStringOfCharLength(msg.getMessageLength());
System.out.println("The message in queue is"+msgText);
if ((inUse==true) && (msgText.equalsIgnoreCase("LOCKED")))
{
s.setStatus(false);
int openOptions1 = CMQC.MQOO_INPUT_AS_Q_DEF | CMQC.MQOO_OUTPUT ;
MQQueue locQueue = qMgr.accessQueue(statusQueue,openOptions1);
MQMessage msgtoput = new MQMessage();
MQPutMessageOptions pmo = new MQPutMessageOptions();
String msgtowrite =("AVAILABLE");
msgtoput.writeString(msgtowrite);
locQueue.put(msgtoput, pmo);
locQueue.close();
}
Back to top
View user's profile Send private message
Prasi
PostPosted: Mon Dec 09, 2013 2:00 pm    Post subject: Reply with quote

Apprentice

Joined: 03 Aug 2011
Posts: 42

Also when it does so, it leaves a open input count as 1 and queue depth of 0.
Back to top
View user's profile Send private message
smdavies99
PostPosted: Mon Dec 09, 2013 2:05 pm    Post subject: Reply with quote

Jedi Council

Joined: 10 Feb 2003
Posts: 6076
Location: Somewhere over the Rainbow this side of Never-never land.

When an application issues an MQGET on a queue with no timeout it will sit there until a message arrives. The Input Count is =1. If there is no message on the queue (the QDepthe = 0) then THIS IS WORKING AS DESIGNED.

If you don't want to have a thread hanging there indefinitley then you need to specify a timeout on the read. Then you code has to handle 2033 errors.
_________________
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
View user's profile Send private message
Prasi
PostPosted: Mon Dec 09, 2013 2:10 pm    Post subject: Reply with quote

Apprentice

Joined: 03 Aug 2011
Posts: 42

I am getting the "LOCKED" message and writing "AVAILABLE" to it. So whenever the input comes, it should check the condition and write the "AVAILABLE" message. But why it is happening only for few messages and for the upcming messages, the queues doesnt write anything but updates the open input count.
Back to top
View user's profile Send private message
Vitor
PostPosted: Tue Dec 10, 2013 5:55 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

Prasi wrote:
I am getting the "LOCKED" message and writing "AVAILABLE" to it. So whenever the input comes, it should check the condition and write the "AVAILABLE" message. But why it is happening only for few messages and for the upcming messages, the queues doesnt write anything but updates the open input count.


So there's a bug in your code.

Also a bug in your design. It sounds a lot like you're using WMQ as a database and that never ends well.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » Reading messages from a queue
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.