Using PHP to Open MSMQ Queues

↘锁芯ラ 提交于 2019-12-07 09:51:44

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/10400676/using-php-to-open-msmq-queues

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!