Using PHP to Open MSMQ Queues
Asked Answered
V

1

4

I have a sample php script to connect to MSMQ on windows. I can create queues and send messages to the queues, however when i try and open the queue to read the messages I keep getting an Access denied exception. the code is here: http://pastebin.com/S5uCiP2Z

I think the main problem is the

$READ = $MSMQInfo->Open(2,0);

line as i am unsure what the 2, 0 options stand for (i cannot find an reference to those any where - i got that code form another example.) Looking at the docs for MSMQQueueInfo.open at http://msdn.microsoft.com/en-us/library/windows/desktop/ms707027%28v=vs.85%29.aspx I can see a few options but not any numeric options..

Any help would be vastly appreciated. And the reason for integrating with MSMQ is to provide an interim solution whilst moving between systems, our old system uses MSMQ so i need to have this interface.

Thanks

Vshaped answered 1/5, 2012 at 16:16 Comment(0)
L
3

From here, you already know the parameters are:

Function Open(Access, ShareMode)

and they also say that

Access can be set to one of the following:

MQ_PEEK_ACCESS: Messages can only be looked at. They cannot be removed from the queue.

MQ_SEND_ACCESS: Messages can only be sent to the queue.

MQ_RECEIVE_ACCESS: Messages can be retrieved (read and removed) from the queue, peeked at, or purged. See the description of the ShareMode argument for information on limiting who can retrieve messages from the queue.

MQ_PEEK_ACCESS | MQ_ADMIN_ACCESS: Messages in the local outgoing queue can only be peeked at (read without being removed from the queue).

MQ_RECEIVE_ACCESS | MQ_ADMIN_ACCESS: Messages in the local outgoing queue can be retrieved (read and removed from the queue), peeked at (read without being removed from the queue), or purged (deleted).

In MSDN's docs for MQACCESS they give you the numerical values for the constants:

typedef  enum 
{
  MQ_RECEIVE_ACCESS = 1,
  MQ_SEND_ACCESS = 2,
  MQ_PEEK_ACCESS = 0x0020,
  MQ_ADMIN_ACCESS = 0x0080
} MQACCESS;

The second parameter, ShareMode:

ShareMode specifies who can access the queue. Set to one of the following:

MQ_DENY_NONE: Default. The queue is available to all members of the Everyone group. This setting must be used if Access is set to MQ_PEEK_ACCESS or MQ_SEND_ACCESS.

MQ_DENY_RECEIVE_SHARE: Limits those who can retrieve messages from the queue to this process. If the queue is already opened for retrieving messages by another process, this call fails and an MQ_ERROR_SHARING_VIOLATION (0xC00E0009) error is generated. Applicable only when Access is set to MQ_RECEIVE_ACCESS.

These constants are:

Const MQ_DENY_NONE = 0
Const MQ_DENY_RECEIVE_SHARE = 1

it's indeed a little harder to find, but you can get it for example here, which is not much a reliable source, but I believe it's correct.

Liripipe answered 1/5, 2012 at 16:27 Comment(1)
I can now read the first message in the queue, thanks :) no just to iterate through the receive() to get each messageVshaped

© 2022 - 2024 — McMap. All rights reserved.