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 » Get the queue current length

Post new topic  Reply to topic Goto page 1, 2  Next
 Get the queue current length « View previous topic :: View next topic » 
Author Message
jadaaih
PostPosted: Tue Sep 16, 2008 10:51 pm    Post subject: Get the queue current length Reply with quote

Apprentice

Joined: 10 Sep 2008
Posts: 25

Hi All,

I am trying to read from a queues current depth using the getCurrentDepth() method in the Java API, I am getting the following exception
MQJE001: Completion Code 2, Reason 2038

My open options is as follows,
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT ;

I also tried changing it to,
int openOptions = MQC.MQOO_INPUT_EXCLUSIVE | MQC.MQOO_BROWSE;

Still does not work.

I want to read all the messages in a queue iteratively and process it, and thats why I was using getCurrentDepth(). Is there is any other way of doing it or should I use any other openOption?

TIA,
Jade
Back to top
View user's profile Send private message
Mr Butcher
PostPosted: Tue Sep 16, 2008 11:30 pm    Post subject: Reply with quote

Padawan

Joined: 23 May 2005
Posts: 1716

well, did you look up the 2038 returncode? it tells you which open option to use.....

however.... messages could be added to the queue after the inquiry, so your program would not pick them up. why dont you just loop on the queue untill you get the 2033 - no message available (which is like an EOF)?
_________________
Regards, Butcher
Back to top
View user's profile Send private message
jadaaih
PostPosted: Wed Sep 17, 2008 12:02 am    Post subject: Reply with quote

Apprentice

Joined: 10 Sep 2008
Posts: 25

Mr Butcher wrote:
well, did you look up the 2038 returncode? it tells you which open option to use.....

however.... messages could be added to the queue after the inquiry, so your program would not pick them up. why dont you just loop on the queue untill you get the 2033 - no message available (which is like an EOF)?


I am sorry, I did check the reason code which says this,

RC2038
(2038)
Explanation:

An MQINQ call was issued to inquire object attributes, but the object had not been opened for inquire.
Completion Code:

CCFAIL
Programmer Response:

Specify OOINQ when the object is opened.

I was unable to inpret it in terms of program, I did not know which open option has to be used

I agree I could do read till I get 2033, however is it the widely used way or I could do it some other way?
Back to top
View user's profile Send private message
Mr Butcher
PostPosted: Wed Sep 17, 2008 12:10 am    Post subject: Reply with quote

Padawan

Joined: 23 May 2005
Posts: 1716

.... but the object had not been opened for inquire

if you dont know which open option to use, why did you not check the manual for the options you have?

to read until 2033 is the common way, unless you need to know in advance the number of messages in the queue, but in most cases you do not need that.
please keep things like unit of work, commits etc. in mind when processing a large number of messages....
_________________
Regards, Butcher
Back to top
View user's profile Send private message
jadaaih
PostPosted: Wed Sep 17, 2008 1:05 am    Post subject: Reply with quote

Apprentice

Joined: 10 Sep 2008
Posts: 25

Yes got it...Works with
openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT | MQC.MQOO_INQUIRE ;

Couple of questions,

- Is there a way to maintain whatever messages are read in the queue itself? instead of consuming?

- Assuming there is a clog in the queue which happened couple of times when I was working, like the message from local queue did not go to remote queue until manual clearing and sending process again - How do we identify these situations and rectify or notify users?
Back to top
View user's profile Send private message
jadaaih
PostPosted: Wed Sep 17, 2008 1:43 am    Post subject: Reply with quote

Apprentice

Joined: 10 Sep 2008
Posts: 25

I am unable to loop based on the getCurrentDepth()

The following is the code,

logger.debug("Entering");
MQEnvironment.hostname = properties.get(MQSConstants.STR_LOCAL_HOST_NAME);
MQEnvironment.channel = properties.get(MQSConstants.STR_LOCAL_CHANNEL);
MQEnvironment.port = Integer.parseInt(properties
.get(MQSConstants.STR_LOCAL_PORT));
openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT | MQC.MQOO_INQUIRE ;
logger.debug("[Open Options : "+openOptions+"]");
MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY,
MQC.TRANSPORT_MQSERIES);

qManager = new MQQueueManager(properties
.get(MQSConstants.STR_LOCAL_QUEUE_MANAGER));
queue = qManager.accessQueue(properties
.get(MQSConstants.STR_LOCAL_QUEUE_NAME), openOptions);
message = new MQMessage();
gmo = new MQGetMessageOptions();

logger.debug("[Current Queue Depth : "+queue.getCurrentDepth()+"]");
for(int index = 0 ; index < queue.getCurrentDepth() ; index++){
queue.get(message);
b = new byte[message.getDataLength()];
message.readFully(b, 0, b.length);
}
queue.close();
qManager.disconnect();
logger.debug("[BIS Write complete]");

I see in the logs, the current depth as 27. But as soon as reading the first message in the queue the code throws 2033 exception and quits execution. And I also see from MQ explorer that there are 27 messages in the queue...Whys this?
Back to top
View user's profile Send private message
jadaaih
PostPosted: Wed Sep 17, 2008 1:47 am    Post subject: Reply with quote

Apprentice

Joined: 10 Sep 2008
Posts: 25

The second issue is cleared...

I had to create new objects for MQMessage when I iterate through the current depth.

But I did not get answers for last couple of questions yet
Back to top
View user's profile Send private message
jadaaih
PostPosted: Wed Sep 17, 2008 2:56 am    Post subject: Reply with quote

Apprentice

Joined: 10 Sep 2008
Posts: 25

There still happens to be problems

I pump in 25 MQ messages and when I read, I just get 13 of them after which the application terminates

I am not sure why..Could you please help?
Back to top
View user's profile Send private message
bower5932
PostPosted: Wed Sep 17, 2008 4:10 am    Post subject: Reply with quote

Jedi Knight

Joined: 27 Aug 2001
Posts: 3023
Location: Dallas, TX, USA

I'd strongly suggest (as have other in various appends) that you don't write any code to get messages based on the current depth of the queue. You should get messages until WMQ tells you there are no more messages (2033).

As far as your particular problem is concerned, my advice is to always run the amqsbcg sample against the queue and see how many messages it returns. You can also see what messages your program didn't get, and this might shed light on why you didn't get them.
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger
gbaddeley
PostPosted: Wed Sep 17, 2008 6:16 pm    Post subject: Reply with quote

Jedi Knight

Joined: 25 Mar 2003
Posts: 2538
Location: Melbourne, Australia

bower5932 wrote:
I'd strongly suggest (as have other in various appends) that you don't write any code to get messages based on the current depth of the queue. You should get messages until WMQ tells you there are no more messages (2033).


Agree 100%. The current depth includes uncommitted messages and expired messages, which won't be visible to the program when you loop to get messages.

ALWAYS loop until ReasonCode 2033 is encountered. You should also trap all other ReasonCodes and handle them appropriately, even if it just spits out an error message and terminates the loop.
_________________
Glenn
Back to top
View user's profile Send private message
premji
PostPosted: Fri Jul 12, 2013 2:16 am    Post subject: Hi jadaaih Reply with quote

Acolyte

Joined: 01 Jul 2013
Posts: 64

Can you please post your code
Back to top
View user's profile Send private message
hughson
PostPosted: Fri Jul 12, 2013 2:29 am    Post subject: Re: Hi jadaaih Reply with quote

Padawan

Joined: 09 May 2013
Posts: 1959
Location: Bay of Plenty, New Zealand

premji wrote:
Can you please post your code

I suspect after 5 years he's solved his problem, and possibly doesn't even have access to the code anymore.

Were you asking to see it so that you could help him, or because you wanted to learn how he solved his problem?

If the latter, might be better to start a new post describing your problem, and let people help you out. You could always reference that you have read this post and think your problem is similar?

Cheers
Morag
_________________
Morag Hughson @MoragHughson
IBM MQ Technical Education Specialist
Get your IBM MQ training here!
MQGem Software
Back to top
View user's profile Send private message Visit poster's website
premji
PostPosted: Fri Jul 12, 2013 2:36 am    Post subject: Reply with quote

Acolyte

Joined: 01 Jul 2013
Posts: 64

Hi hughson

Thanks for prompt response, just now I have started work on this I got current queue depth and I have retrieved one message from queue but I want to copy message from one queue to another queue. Could u give any suggestion...
Back to top
View user's profile Send private message
hughson
PostPosted: Fri Jul 12, 2013 2:42 am    Post subject: Reply with quote

Padawan

Joined: 09 May 2013
Posts: 1959
Location: Bay of Plenty, New Zealand

premji wrote:
I want to copy message from one queue to another queue.

So you've done an MQGET and now you want to do an MQPUT of the same message to a different queue? And you'd want this to be an atomic action, so you have done the destructive MQGET inside a Syncpoint, and so you're going to do the MQPUT also inside a Syncpoint and then do an MQCMIT?

Edit: Notice you say "copy" so I guess you want to MQGET with browse rather than destructive MQGET, so then you're not concerned with SyncPoint?
_________________
Morag Hughson @MoragHughson
IBM MQ Technical Education Specialist
Get your IBM MQ training here!
MQGem Software
Back to top
View user's profile Send private message Visit poster's website
mqjeff
PostPosted: Fri Jul 12, 2013 5:37 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

premji wrote:
I got current queue depth

And between when you get it, and when you try and read the first message off the queue, 100 new messages have arrived, so the depth you got is now wrong.

Don't worry about the depth of the queue.

Worry about the return code from the MQ Get.

Also, there are a whole big pile of sample applications that come with well documented source code that ship as part of MQ, in many different programming languages.

You will save yourself a lot of time and a lot of heartache by reading those and experimenting with them until you understand them, instead of trying to ask very basic questions here.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Goto page 1, 2  Next Page 1 of 2

MQSeries.net Forum Index » IBM MQ Java / JMS » Get the queue current length
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.