MSMQ (MicroSoft Message Queue, Microsoft Message Queue) is in a number of different applications to communicate between an asynchronous transfer mode, distributed applications can communicate with each other on the same machine can also be distributed connected to the network space in any location. It is the realization of the principle is: the sender of the message you want to send the information to put in a container (we call Message), then save it to a system of public space, message queue (Message Queue) in the ; local or remote message queue to receive program and then removed from the message sent to it for processing.
in the message transmission mechanism, there are two a more important concept. One is the message and a queue. Message is required by the parties to communicate the message, it can be a variety of media, such as text, sound, image and so on. The final way to understand the message, the message passing between the parties agreed in advance, the benefits of doing so, one equivalent to a simple data encryption, two by their own definition of the format of delivery can save the amount of traffic. Messages can be sent and the recipient containing the identity, so that only specified users can see only the information passed to him whether the operation was successful and the return receipt. Messages can also contain a timestamp to the receiver for some time and related applications for processing. Messages can also contain an expiry time, it shows that if the message has not been reached within the specified time is set aside, the main application of this more closely associated with the timing of the application.
message queue is to send and receive messages common storage space, which can exist in memory or a physical file. Messages can be sent in two ways, namely, courier (express) and recoverable mode (recoverable), their difference is that the fast courier delivery to the message, the message is placed in memory, and hold on the physical disk to obtain a higher capacity; recoverable mode in the transmission process, each step, a great message is written to physical disk in order to get a better disaster recovery capabilities. Message queue can be placed on the sender, the receiver where the machine can also be individually placed in another machine. It is precisely because the message queue on the flexibility of placement, the formation of the reliability of message delivery mechanism. When saving the message queue and restart the machine after the failure to restore mode to send the message can be restored to the state before the failure occurred, and to express the message sent is lost. On the other hand, the use of message passing, the sender need to worry about whether to activate the receiver, whether the failure of non-essential elements, etc., as long as the message is successfully sent out to that processing is complete, in fact, it probably did not even start, or actual completion of the transaction may be next day.
the benefits of using MSMQ are: Because it is asynchronous communication, whether sender or receiver do not have to wait for the other to return a success message to the rest of the code can perform, thus greatly improving the ability to handle things; when the information transmission process, the information delivery mechanism has a certain function resiliency; MSMQ messaging system allows messages to communicate with different physical platform for both parties as possible.
at Microsoft. net platform using MSMQ functionality it provides, you can easily create or delete the message queue, send or receive messages, even on the message queue management.
in. NET products, provided a MSMQ library It provides two classes of message objects, respectively, and the message queue object operation. Before you can use MSMQ feature, you must make sure your machine is installed MSMQ message queue components, and to ensure that service is running. Programming using ASP.NET, you should use in the head:
<% @ Assembly Name =
<% @ Import NameSpace = ;
the introduction of the ASP.NET file
MSMQ library
1. Create the message queue
; dim MsgQue as MessageQueue
; MsgQue = New MessageQueue (MsgPath)
including: MsgPath for local private queue, such as 777 $ MyQueue
2. Send a message
; dim MsgQue as MessageQueue
; MsgQue.Send (Msg)
; including: Msg for any object.
3. Receiver of the message
; message receiver is divided into two kinds of synchronous and asynchronous mode, synchronous to receive within the specified time out from the message queue received the first message, no message when the message queue, the program in a wait state; asynchronous receive mode is is to define an event handler, the message queue when the first message arrives immediately trigger the function.
1) Sync
dim Msg as Message
dim Fmt As XmlMessageFormatter
;
Fmt = CType (MsgQue.Formatter, XmlMessageFormatter)
;
Fmt.TargetTypeNames = new String () {; System.String Msg = MsgQue.receive (New TimeSpan (0,0,3))
First, the definition of receipt of the message should be converted to the format and within the specified time to receive messages
;
2) asynchronous
;
;
dim Fmt As XmlMessageFormatter
''to receive messages defined types
Fmt = CType (MsgQue.Formatter, XmlMessageFormatter)
Fmt.TargetTypeNames = new ; String () {''defined message processing function entry
AddHandler MsgQue.ReceiveCompleted, New ReceiveCompletedEventHandler
(AddressOf OnReceiveCompleted)
;
''defined message processing function
; Public Shared Sub OnReceiveCompleted (s As Object, asyncResult As ReceiveAsyncEventArgs) ;
Dim MsgQue As MessageQueue = CType (s, MessageQueue) ;
Dim Msg As Message = MsgQue.EndReceive (asyncResult.AsyncResult) ;
''is the time taken from the message object Msg.Body
MsgQue.BeginReceive ()
''redefine the way
asynchronous receiver End sub
Start asynchronous receive mode''
MsgQue.BeginReceive ;
Message Queue Configuration Properties
on the properties of the queue path attribute: it can determine the queue referenced in three ways, the path reference, reference format name, logo reference
;
category attribute: Identifies the type of the queue currently in use. Category is defined in the queue owner GUID value. The GUID value can be generated GUID generation tool or a user-defined number of values. GUID values are not unique, so that it can be under the same GUID value, the number of message queue is divided into different categories (category).
send data types associated with the properties ;
Formatter attributes: decision a queue to send and receive messages in the order, and can be sent in a message what kind of content.
and queue related attributes interact
DenyShareReceive properties: the decision at the same time is only one component can access the message queue the message.
CanRead and CanWrite property : Determine whether the queue can be read or written.
MaximumQueueSize and MaximumJournalSize property : in thousands of bytes to set up a queue (log queue) the maximum capacity of the message. Upon receiving the message reaches the capacity, new messages will no longer be received.
general, message queue message queue maximum set by the administrator, if this value does not control, then the default message queue maximum size will be unlimited.
UseJournalQueue properties:: Set whether to receive a copy of the message to the log message queue.
in the message transmission mechanism, there are two a more important concept. One is the message and a queue. Message is required by the parties to communicate the message, it can be a variety of media, such as text, sound, image and so on. The final way to understand the message, the message passing between the parties agreed in advance, the benefits of doing so, one equivalent to a simple data encryption, two by their own definition of the format of delivery can save the amount of traffic. Messages can be sent and the recipient containing the identity, so that only specified users can see only the information passed to him whether the operation was successful and the return receipt. Messages can also contain a timestamp to the receiver for some time and related applications for processing. Messages can also contain an expiry time, it shows that if the message has not been reached within the specified time is set aside, the main application of this more closely associated with the timing of the application.
message queue is to send and receive messages common storage space, which can exist in memory or a physical file. Messages can be sent in two ways, namely, courier (express) and recoverable mode (recoverable), their difference is that the fast courier delivery to the message, the message is placed in memory, and hold on the physical disk to obtain a higher capacity; recoverable mode in the transmission process, each step, a great message is written to physical disk in order to get a better disaster recovery capabilities. Message queue can be placed on the sender, the receiver where the machine can also be individually placed in another machine. It is precisely because the message queue on the flexibility of placement, the formation of the reliability of message delivery mechanism. When saving the message queue and restart the machine after the failure to restore mode to send the message can be restored to the state before the failure occurred, and to express the message sent is lost. On the other hand, the use of message passing, the sender need to worry about whether to activate the receiver, whether the failure of non-essential elements, etc., as long as the message is successfully sent out to that processing is complete, in fact, it probably did not even start, or actual completion of the transaction may be next day.
the benefits of using MSMQ are: Because it is asynchronous communication, whether sender or receiver do not have to wait for the other to return a success message to the rest of the code can perform, thus greatly improving the ability to handle things; when the information transmission process, the information delivery mechanism has a certain function resiliency; MSMQ messaging system allows messages to communicate with different physical platform for both parties as possible.
at Microsoft. net platform using MSMQ functionality it provides, you can easily create or delete the message queue, send or receive messages, even on the message queue management.
in. NET products, provided a MSMQ library It provides two classes of message objects, respectively, and the message queue object operation. Before you can use MSMQ feature, you must make sure your machine is installed MSMQ message queue components, and to ensure that service is running. Programming using ASP.NET, you should use in the head:
<% @ Assembly Name =
<% @ Import NameSpace = ;
the introduction of the ASP.NET file
MSMQ library
1. Create the message queue
; dim MsgQue as MessageQueue
; MsgQue = New MessageQueue (MsgPath)
including: MsgPath for local private queue, such as 777 $ MyQueue
2. Send a message
; dim MsgQue as MessageQueue
; MsgQue.Send (Msg)
; including: Msg for any object.
3. Receiver of the message
; message receiver is divided into two kinds of synchronous and asynchronous mode, synchronous to receive within the specified time out from the message queue received the first message, no message when the message queue, the program in a wait state; asynchronous receive mode is is to define an event handler, the message queue when the first message arrives immediately trigger the function.
1) Sync
dim Msg as Message
dim Fmt As XmlMessageFormatter
;
Fmt = CType (MsgQue.Formatter, XmlMessageFormatter)
;
Fmt.TargetTypeNames = new String () {; System.String Msg = MsgQue.receive (New TimeSpan (0,0,3))
First, the definition of receipt of the message should be converted to the format and within the specified time to receive messages
;
2) asynchronous
;
;
dim Fmt As XmlMessageFormatter
''to receive messages defined types
Fmt = CType (MsgQue.Formatter, XmlMessageFormatter)
Fmt.TargetTypeNames = new ; String () {''defined message processing function entry
AddHandler MsgQue.ReceiveCompleted, New ReceiveCompletedEventHandler
(AddressOf OnReceiveCompleted)
;
''defined message processing function
; Public Shared Sub OnReceiveCompleted (s As Object, asyncResult As ReceiveAsyncEventArgs) ;
Dim MsgQue As MessageQueue = CType (s, MessageQueue) ;
Dim Msg As Message = MsgQue.EndReceive (asyncResult.AsyncResult) ;
''is the time taken from the message object Msg.Body
MsgQue.BeginReceive ()
''redefine the way
asynchronous receiver End sub
Start asynchronous receive mode''
MsgQue.BeginReceive ;
Message Queue Configuration Properties
on the properties of the queue path attribute: it can determine the queue referenced in three ways, the path reference, reference format name, logo reference
;
category attribute: Identifies the type of the queue currently in use. Category is defined in the queue owner GUID value. The GUID value can be generated GUID generation tool or a user-defined number of values. GUID values are not unique, so that it can be under the same GUID value, the number of message queue is divided into different categories (category).
send data types associated with the properties ;
Formatter attributes: decision a queue to send and receive messages in the order, and can be sent in a message what kind of content.
and queue related attributes interact
DenyShareReceive properties: the decision at the same time is only one component can access the message queue the message.
CanRead and CanWrite property : Determine whether the queue can be read or written.
MaximumQueueSize and MaximumJournalSize property : in thousands of bytes to set up a queue (log queue) the maximum capacity of the message. Upon receiving the message reaches the capacity, new messages will no longer be received.
general, message queue message queue maximum set by the administrator, if this value does not control, then the default message queue maximum size will be unlimited.
UseJournalQueue properties:: Set whether to receive a copy of the message to the log message queue.
No comments:
Post a Comment