Author |
Message
|
abhishek |
Posted: Mon May 10, 2010 3:04 am Post subject: Exculsive access to MQ queue using java code |
|
|
Newbie
Joined: 10 May 2010 Posts: 3
|
Hi,
I have a java program which process messages and put into a MQ queue.some times i get some extra messages in that queue,which could be because of some other program might be using that queue and pushing some messages in that.
I just want to know is there any way by which i can check which else program is trying to access the queue during my program run.Do I have any way by which I
can get exclusive access to the MQ queue while my program execution, which in turn will ensure that there would not be any extra messages in that queue.
I am using IBM mq 5.3 and java 1.6.
I need to do this using java program as I don't have access to MQ.
Regards,
Abhishek |
|
Back to top |
|
 |
mvic |
Posted: Mon May 10, 2010 3:07 am Post subject: Re: Exculsive access to MQ queue using java code |
|
|
 Jedi
Joined: 09 Mar 2004 Posts: 2080
|
abhishek wrote: |
some times i get some extra messages in that queue |
Please explain, why is that a problem?
You can inspect the connections etc. using
DISPLAY CONN
DISPLAY QSTATUS |
|
Back to top |
|
 |
abhishek |
Posted: Mon May 10, 2010 3:54 am Post subject: Exculsive access to MQ queue using java code |
|
|
Newbie
Joined: 10 May 2010 Posts: 3
|
I have a program which processes the messages and gives me count of all the messages from a specific MQ queue. Say I run that and expect 10 messages in response, I use to get 10.Now if do a test for a huge data and I expect 10,000 messages, I used to get 10,027 (say). Now I don’t know where are these extra messages from so, I need to know is there any other program which has accessed to that particular queue while my program was executing. If so, how would I restrict that program to access the same queue in my java code? |
|
Back to top |
|
 |
mvic |
Posted: Mon May 10, 2010 4:04 am Post subject: Re: Exculsive access to MQ queue using java code |
|
|
 Jedi
Joined: 09 Mar 2004 Posts: 2080
|
abhishek wrote: |
I have a program which processes the messages and gives me count of all the messages from a specific MQ queue. Say I run that and expect 10 messages in response, I use to get 10.Now if do a test for a huge data and I expect 10,000 messages, I used to get 10,027 (say). Now I don’t know where are these extra messages from so, I need to know is there any other program which has accessed to that particular queue while my program was executing. If so, how would I restrict that program to access the same queue in my java code? |
This sounds like a non-optimal use of MQ.
In the best-case use of MQ, each message should stand alone. The app should get a message, process it, and move to the next.
Admittedly there are other patterns of usage that are valid, but not many.
You don't say why the app needs to count the messages, but I doubt it is a very useful thing for the app to know how many messages are on the queue.
If you want to group messages and process them as if they were a single piece of information, there is GroupId and CorrelId to help you do this. |
|
Back to top |
|
 |
abhishek |
Posted: Mon May 10, 2010 4:28 am Post subject: |
|
|
Newbie
Joined: 10 May 2010 Posts: 3
|
Sorry, let me try again.
I have a java program which process messages from a MQ queue. Some times i don't get all of the messages that I'm expecting from that queue, which could be because of some other program reading from that queue and pulling my messages off of it.
I just want to know is there any way by which i can check which else program (or at least which machine the program is running on) is trying to access the queue during my program run. Alternatively, do I have any way by which I can get exclusive access to the MQ queue while my program is executing?
Thank you very much. |
|
Back to top |
|
 |
mvic |
Posted: Mon May 10, 2010 4:41 am Post subject: |
|
|
 Jedi
Joined: 09 Mar 2004 Posts: 2080
|
abhishek wrote: |
I just want to know is there any way by which i can check which else program (or at least which machine the program is running on) is trying to access the queue during my program run. |
You can inspect the connections etc. using
DISPLAY CONN
DISPLAY QSTATUS
Quote: |
Alternatively, do I have any way by which I can get exclusive access to the MQ queue while my program is executing? |
Yes, you can use MQOO_INPUT_EXCLUSIVE. |
|
Back to top |
|
 |
Vitor |
Posted: Mon May 10, 2010 9:38 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
abhishek wrote: |
Alternatively, do I have any way by which I can get exclusive access to the MQ queue while my program is executing?
|
Not if another application is already connected to the queue and reading messages.
If no other application should be reading messages off this queue, then the user id your application runs under should be the only one granted authority to read messages. This is the most efficient way of solving your problem, and doesn't require a single line of code be changed!  _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
fjb_saper |
Posted: Mon May 10, 2010 11:19 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Vitor wrote: |
abhishek wrote: |
Alternatively, do I have any way by which I can get exclusive access to the MQ queue while my program is executing?
|
Not if another application is already connected to the queue and reading messages.
If no other application should be reading messages off this queue, then the user id your application runs under should be the only one granted authority to read messages. This is the most efficient way of solving your problem, and doesn't require a single line of code be changed!  |
And remember in a Unix environment all authorizations are made at the group id level. There is no such thing as setting the authorisations at a userid level in Unix...  _________________ MQ & Broker admin |
|
Back to top |
|
 |
|