MSMQ(MicroSoft Message Queue, MicroSoft Message Queue) is an asynchronous transmission mode for communication between multiple different applications. Applications that communicate with each other can be distributed on the same machine, it can also be distributed anywhere in the connected network space. Its implementation principle is: the Message sender puts the information he wants to send into a container (we call it Message ), then, it is saved to the Message Queue in a public space of the system. local or remote Message receiving programs then extract the messages sent to it from the Queue for processing.
There are two important concepts in the message transmission mechanism. One is a message, and the other is a queue. A message is the information that must be transmitted by both parties. It can be a variety of media, such as text, sound, and image. The final way to understand a message is agreed by both parties. The advantage of this is that data is encrypted simply, second, you can use your own defined format to save the amount of communication transferred. A message can contain the sender and receiver IDs, so that only the specified user can see the information that is passed to him and the receipt that is returned for successful operation. A message can also contain a timestamp, so that the receiver can process certain time-related applications. A message can also contain an expiration time. It indicates that a message is voided if it has not arrived within the specified time, which is mainly used for time-based applications.
A message queue is a public storage space for sending and receiving messages. It can exist in memory or physical files. Messages can be sent in two ways, express and recoverable. The difference between express and recoverable modes is that the express delivery mode enables fast delivery of messages, messages are stored in the memory instead of on the physical disk to obtain high processing capability. The recoverable mode is in each step of the transfer process, all messages are written to the physical disk for better fault recovery. Message queues can be placed on the sender and receiver, or separately on another machine. It is precisely because of the flexibility of message queues in the placement mode that the reliability of the message transmission mechanism is formed. When the machine that stores the Message Queue fails and restarts, messages sent in recoverable mode can be restored to the status before the fault occurs, and messages sent by express delivery are lost. On the other hand, using the message transmission mechanism, the sender must worry about whether the receiver is started, whether a fault occurs, and other non-essential factors. As long as the message is successfully sent, the processing can be considered complete, in fact, the other party may not even start the instance, or the next day may have actually completed the transaction.
The advantage of MSMQ is that, due to asynchronous communication, the sender and receiver can execute the remaining code without waiting for the other party to return a successful message, therefore, it greatly improves the processing capability of things. In the process of information transmission, the information transmission mechanism has a certain function of fault recovery; MSMQ's message transmission mechanism makes it possible for both parties to communicate with each other to have different physical platforms.
Using the MSMQ function provided by Microsoft's. net platform, you can easily create or delete message queues, send or receive messages, and even manage message queues.
In. NET products, a MSMQ class library "System. Messaging. dll" is provided ". It provides two classes to operate message objects and Message Queue objects respectively. Before using the MSMQ function, make sure that the MSMQ Message Queue component is installed on your machine and that the service is running. When using ASP. NET programming, you should use it in the header:
<% @ Assembly Name = "System. Messaging" %>
<% @ Import NameSpace = "System. Messsaging" %>
Introduce the MSMQ class library into the ASP. NET File