Author |
Message
|
Prasi |
Posted: Tue Nov 05, 2013 7:08 pm Post subject: Exclusive access to Queue |
|
|
Apprentice
Joined: 03 Aug 2011 Posts: 42
|
Hi,
I have a requirement of getting an exclusive access to a queue, put the message to that queue. Also, make sure that no other thread is accessing it. I am using MQQSO_EXCLUSIVE option,but still I am not able to succeed in it. Is there any other option that I need to in my java. Any help is greatly appreciated.
Thanks,
Prasi |
|
Back to top |
|
 |
calanais |
Posted: Wed Nov 06, 2013 1:25 am Post subject: |
|
|
Apprentice
Joined: 12 Mar 2010 Posts: 32
|
Could you explain how you have not been able to succeed? Also is this via JMS or the WMQ Base Java API?
Also why do you only want a single thread to access a queue at one time? Do you have some strict message ordering requirements? |
|
Back to top |
|
 |
PaulClarke |
Posted: Wed Nov 06, 2013 1:42 am Post subject: |
|
|
 Grand Master
Joined: 17 Nov 2005 Posts: 1002 Location: New Zealand
|
Are you sure you mean MQQSO_EXCLUSIVE and not MQOO_INPUT_EXCLUSIVE ? Perhaps this is some use of MQQSO_EXCLUSIVE in the JMS world I was unaware of.
Cheers,
Paul. _________________ Paul Clarke
MQGem Software
www.mqgem.com |
|
Back to top |
|
 |
Prasi |
Posted: Wed Nov 06, 2013 7:28 am Post subject: |
|
|
Apprentice
Joined: 03 Aug 2011 Posts: 42
|
I am using WMQ Base Java API. When I use MQOO_INPUT_EXCLUSIVE I am getting 2042 error which is MQRC_OBJECT_IN_USE which my object is not. When I accessing the queue for the first time, I want my queue to be exclusive for this process and put the message to the queue.
Yes there is a strict message orfering requirements. |
|
Back to top |
|
 |
PaulClarke |
Posted: Wed Nov 06, 2013 8:00 am Post subject: |
|
|
 Grand Master
Joined: 17 Nov 2005 Posts: 1002 Location: New Zealand
|
Ok, well at least you are using MQOO_INPUT_EXCLUSIVE which makes more sense. If you are getting MQRC_OBJECT_IN_USE then it suggests that someone is already using the queue. What do you see if you issue:
dis qstatus(QUEUENAME) type(handle)
Does it look like someone already has the queue?. Bear in mind that if you kill an application (or it dies without closing/disconnecting) then it can take quite a few seconds before the QM notices and releases the lock on the queue.
Cheers,
Paul _________________ Paul Clarke
MQGem Software
www.mqgem.com |
|
Back to top |
|
 |
RogerLacroix |
Posted: Sun Nov 10, 2013 9:19 pm Post subject: |
|
|
 Jedi Knight
Joined: 15 May 2001 Posts: 3264 Location: London, ON Canada
|
Hi,
You keep talking about exclusive access and putting a message which made me think you are on the wrong track. You cannot have exclusive access to a queue for putting messages to the queue. When you open a queue with MQOO_OUTPUT (for output only) then it is opened as shared.
Code: |
MQQueue queue = qMgr.accessQueue( outputQName,
MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING,
null,
null,
null ); |
Regards,
Roger Lacroix
Capitalware Inc. _________________ Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter |
|
Back to top |
|
 |
Prasi |
Posted: Thu Dec 12, 2013 11:35 am Post subject: |
|
|
Apprentice
Joined: 03 Aug 2011 Posts: 42
|
Sorry for the late reply. I am doing the below coding in my Java Compute node.
MQQueueManager qMgr = new MQQueueManager(qManager);
int openOptions=CMQC.MQOO_INPUT_EXCLUSIVE ;
MQMessage msg= new MQMessage();
MQQueue locQueue=qMgr.accessQueue(statusQueue, openOptions);
MQGetMessageOptions gmo=new MQGetMessageOptions();
locQueue.get(msg,gmo);
locQueue.close();
String msgText=msg.readStringOfCharLength(msg.getMessageLength());
System.out.println("The message in queue is"+msgText);
if(msgText.equalsIgnoreCase("AVAILABLE"))
{
int openOptions1 = CMQC.MQOO_OUTPUT;
locQueue = qMgr.accessQueue(statusQueue,openOptions1);
MQMessage msgtoput = new MQMessage();
MQPutMessageOptions pmo = new MQPutMessageOptions();
String msgtowrite =("LOCKED");
msgtoput.writeString(msgtowrite);
locQueue.put(msgtoput, pmo);
locQueue.close();
}
qMgr.disconnect();
My problem is when I am putting 4 messages continuously, only the first message gets processed. The rest of them fails telling that 2042 (Object in Use) error. When i do dis qstatus(queuename) type (handle) I can see the dataflowengine is holding the process. But I am using debugger when I am starting the flow. Is there any issues with the code? Can someone please explain? |
|
Back to top |
|
 |
Prasi |
Posted: Thu Dec 12, 2013 11:37 am Post subject: |
|
|
Apprentice
Joined: 03 Aug 2011 Posts: 42
|
Type on my previous post. I am not using debugger while putting messages to the queue. What is holding it and what can I do to avoid this problem? |
|
Back to top |
|
 |
Vitor |
Posted: Thu Dec 12, 2013 11:43 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Prasi wrote: |
Sorry for the late reply. I am doing the below coding in my Java Compute node. |
Why are you accessing a queue with a Java Compute Node? What's wrong with the supplied nodes?
It also doesn't work all that well, as you've discovered.You get problems with threading and transaction scope (as you've discovered) _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
Prasi |
Posted: Thu Dec 12, 2013 11:47 am Post subject: |
|
|
Apprentice
Joined: 03 Aug 2011 Posts: 42
|
I am using a global cache and the requirement is to use JCN. Is there any other way or is there any bug in my logic? |
|
Back to top |
|
 |
JosephGramig |
Posted: Thu Dec 12, 2013 1:30 pm Post subject: |
|
|
 Grand Master
Joined: 09 Feb 2006 Posts: 1244 Location: Gold Coast of Florida, USA
|
Since this is a WMB JCN, then I would think this topic belongs in the WMB Forum... |
|
Back to top |
|
 |
Vitor |
Posted: Fri Dec 13, 2013 5:31 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
JosephGramig wrote: |
Since this is a WMB JCN, then I would think this topic belongs in the WMB Forum... |
So Moved _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
Vitor |
Posted: Fri Dec 13, 2013 5:33 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Prasi wrote: |
I am using a global cache and the requirement is to use JCN. |
How does that extend to including queue access in the JCN?
Your design is flawed. Rethink. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
|