Because the use of MSMQ need to constantly check whether the queue has new messages, so it is generally combined with Windows services, of course, you can also use a non-closed WinForm program, but the former better, not afraid of being mistaken.
After you complete the Windowsservice project for MSMQ, add the service project to the Windows service.
① If you are accessing a queue that already exists, you will be reporting an error when you start it "stops after the XXXX service on the local computer starts. Some services will stop automatically when they are not being used by other services or programs.
This is because no permissions are assigned.
How to: Right-click the queue you want to access, security
Check the full control of Everyone and ANONYMOUS LOGON separately
② sending a message to a remote queue
The path format and use of the queue when accessing local queues
var @" . \PRIVATE$\MYMQ " ; MessageQueue _mq; if (Messagequeue.exists (Mqpath)) { new MessageQueue (Mqpath);} Else { = messagequeue.create (mqpath);}
When accessing a remote queue, the code is slightly different:
1. path format for remote queues:string path = @ "formatname:direct=tcp:192.168.1.11\private$\mymq " ; Keyword is case insensitive
2.MSMQ method for determining whether a queue exists (messagequeue.exists (string path)) and creating a queue (messagequeue.create ( String path), is not supported for remote queues.
1. An error occurs using the Exists method " Unable to determine whether a queue with the specified format name exists. "
2. The error " unable to create a queue with path Formatname:direct=tcp:192.168.1.11\private$\mymq " appears with the Create method
3. Due to the limitations of the first two, if you want to access a remote private queue, you must ensure that the queue is present on the remote machine beforehand.
var @" FORMATNAME:DIRECT=TCP:192.168.1.11\PRIVATE$\MYMQ " New MessageQueue (QueuePath);
4. When sending a message to a remote queue, the system creates a temporary queue under the native's outgoing queue, with each message being sent with a temporary queue, which is intended to prevent the loss of a message because the remote queue is inaccessible.
It is important to note, however, that if the remote machine does not connect successfully, the message is kept in the temporary queue, and if the connection is successful, the message sender does not get an error even if the queue to be accessed does not exist, and the message in the temporary queue is deleted.
so make sure you build the queue on the remote server first. Outgoing queue specific information such as:
5. If the transactional properties do not match, the message cannot be delivered. The system does not return any errors, but the message is discarded.
MSMQ denied access error
How to successfully publish a Windows service for MSMQ