|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
How To Check a MQ Q exists or not?? |
« View previous topic :: View next topic » |
Author |
Message
|
meriton |
Posted: Wed Jan 07, 2004 8:08 pm Post subject: How To Check a MQ Q exists or not?? |
|
|
Novice
Joined: 07 Aug 2002 Posts: 24
|
I am trying to move msgs from a queue to a list of dynamic queues. To do so, I need to check if the dynamic queue exists first, if yes, I open the queue and move the msgs, if not, I will create the dynamic queue then move the msg. I use accessQueue method to do the check, get an 2085 error every time if no such queue. Any efficient way to check if a dynamic queue exists ( queue name provided).
Follows the code I am using ..
boolean vExisting = false;
String dynamicQName = "CLK.G2B.PHY.DEVL.ISS." + pBatchId;
if (mQMgr != null) {
try {
int vOpenOptions = MQC.MQOO_BROWSE | MQC.MQOO_FAIL_IF_QUIESCING;
MQQueue DynamicQ =
mQMgr.accessQueue(
dynamicQName,
vOpenOptions,
null,
null,
null);
//testing...
if (DynamicQ != null)
vExisting = true;
//end testing...
} catch (MQException MQe) {
if (MQe.reasonCode != 2085)
throw MQe;
} catch (Exception e) {
throw e;
}
|
|
Back to top |
|
 |
bower5932 |
Posted: Thu Jan 08, 2004 6:27 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
|
Back to top |
|
 |
clindsey |
Posted: Thu Jan 08, 2004 6:53 am Post subject: |
|
|
Knight
Joined: 12 Jul 2002 Posts: 586 Location: Dallas, Tx
|
IMHO, if your intent is to write to the queue if it exists, then the most efficient check is to open the queue. If it exists, you have a valid handle and off you go. If it doesn't exist, then create it. Why spend cycles on a query function that still requires you to follow up with an open anyway?
Put a try/catch specifically around the queue open call and do the open in the catch block when 2085 is thrown. Then you can use the same code flow beyond that for either case.
Hope this helps,
Charlie |
|
Back to top |
|
 |
bower5932 |
Posted: Thu Jan 08, 2004 7:59 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
I definitely agree with Charlie's point. The only time the inquire might/would come in handy is if you have a large number of queues to try and you know that most of them aren't going to exist. You could get your list ahead of time to save on the opens of the non-existent ones. |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
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
|
|
|
|