Message Queue Introduction and Its Use

xiaoxiao2021-03-17  215

Message Queue Introduction and Its Use

Using MSMQ (Microsoft Message Queue), application developers can easily communicate quickly and reliable communications with the application by sending and receiving messages. Message Processing provides you with secure messaging and a reliable security method for performing many business processes.

MSMQ is the same as XML Web Services and .Net Remoting, MSMQ is a distributed development technology. But when using XML Web Services or .Net Remoting components, the Client side needs to exchange information with Server, and Server needs to keep online. MSMQ can work in the case where Server is offline, and the Message is temporarily saved in the message queue of the Client side, and then it is sent to the Server terminal when online.

Obviously, MSMQ is not suitable for the Client that requires a SERVER side to respond in a timely response, and MSMQ interacts asynchronously, and does not have to worry about the long-term processing of the Server end.

Although XML Web Services and .NET Remoting provide [Oneway] properties to process asynchronous calls to resolve the Server end length method call for a long time hinder the client. But you can't solve a large number of Client loads, and the request for Server is faster than the processing request.

In general, [Oneway] attribute is not used in a special message service.

1. Basic Terms and Concepts

"Message" is a data unit transmitted between two computers. The message can be very simple, such as only a text string; it is more complicated, which may contain embedded objects.

The message is sent to the queue. "Message Queue" is a container that saves a message during the transmission of the message. Message Queue Manager acts as an intermediary when returning messages from its source. The main purpose of the queue is to provide routing and guarantee the delivery of messages; if the recipient is not available when sending a message, the message queue retains the message until it can be successfully delivered.

"Message Queue" is Microsoft message processing technology, which provides message processing and message queue feature for any application in any application, whether or not the computers are on the same network or whether they online.

The Message Queue Network is any set of computers that can send messages to each other. Different computers in the network play different roles in the process of ensuring the smooth processing of messages. They provide routing information to determine how to send messages, some of which are important information for the entire network, and some only send and receive messages.

During the "Message Queue" installation, the administrator determines which servers can communicate with each other and set special roles of a particular server. Computers constituting this "Message Queue" network are called "sites", they are connected to each other by "Site Link". Each site link has an associated "overhead", which is determined by the administrator, indicating the frequency of the message passing through this site.

The Message Queue administrator also sets one or more computers that are "routing servers" in the network. The routing server views the overhead of each site link to determine the fastest and most effective way to pass the messages through multiple sites to determine how to deliver messages.

2. Queue Type

There are two main queue types: queues and system queues created by other users in you or network.

The queue created by the user may be any of the following queues:

"Public Square" is copied throughout the "Message Queue" network and is possible to access all sites connected by the network.

"Special queue" is not released throughout the network. Instead, they are only available on the resident local computer. A dedicated queue can only be accessed by an application that knows the full path name or tag of the queue.

The Manage Query contains messages that confirm the message receipt of the message sent in a given "Message Queue" network. Specifies the management queue you want to use by the MessageQueUE component (if any). The Response Queue contains a response message to send an application when the target application receives a message. Specifies the response queue (if any if any) you want the MessageQue component.

The queue generated by the system is generally divided into the following categories:

"Diary Queue" optionally stores a copy of the send message and a copy of the message removed from the queue. A single diary queue on each "Message Queue" client stores the message replica sent from the computer. A separate diary queue is created for each queue on the server. This diary tracks the message removed from the queue.

"Dead Letter Queue" stores a copy of the message that cannot be passed or expired. If the message expired or unable to pass is a transactional message, it is stored in a special dead letter queue, called "transactional dead letter queue". Dead letter is stored on a computer where expired message is located. For more information on timeout periods and expiration messages, see the default message properties.

The Report Queue contains messages that indicate the route passage through the message to the target, and can also contain test messages. There can only be a report queue on each computer.

"Special System Query" is a special queue for the management and notification messages required by a series of storage systems to perform message processing operations.

Most of the work conducted in the application involves accessing public queues and their messages. However, depending on the application's diary record, confirmation, and other special processing needs, several different system queues are likely to use in daily operations.

3. Synchronous and asynchronous communication (Synchronous vs. asynchronous communication)

Queue communication is born asynchronous because sending messages to queue and receive messages from the queue are done in different processes. In addition, the reception operation can be performed asynchronously because people to receive the message can call the BeginReceive method for any given queue, and then immediately continue other tasks without waiting for a reply. This is very different from "synchronous communication" understanding.

In synchronous communication, the requested sender must wait for a response from a predetermined receiver before performing other tasks. The time of the sender waits for time depends entirely on the time used by the recipient processing request and the transmit response.

4. Interaction with message queue (Interacting with message queues)

Message handling and messages provide a powerful and flexible mechanism for process communication between server-based application components. Direct calls between the same assembly have several advantages, including:

Stability - Component failure to messages is far less than the direct call between components, because the message is stored in the queue and stay there, until it handles. Message processing is similar to transaction processing, because message processing is guaranteed.

Message priority - more emergency or more important messages can be received before relatively unimportant messages, so you can guarantee sufficient response time for critical applications.

Offline Ability - When you send a message, they can be sent to the temporary queue and stay there until successfully passed. When any reason is not available to the required queue, the user can continue to perform the operation. At the same time, other operations can continue, as the message has been processed, because the message delivery is guaranteed when the network connection is recovered.

Transactional Message Processing - couples multiple associated messages as a single transaction, ensuring that the message is passed sequentially, only once and can be successfully retrieved from their target queues. If you have any errors, you will cancel the entire transaction.

Safety - MessageQueue component based message queue technology uses Windows security to protect access control, provide an audit, and encrypt and verify messages sent and received.

5. Write a simple Message Queue program in the .NET environment.

(1) Install Message Queuing Services first

Install MSMQ through the Control Panel, "Add / Remove Programs" - "Add / Remove Windows Components" step. MSMQ can be installed as a workgroup mode or domain mode. If the installer does not find a server running a message queue that runs a directory service, you can only be installed as a workgroup mode. The "Message Queue" on this computer only supports the creation of a private queue and creates a computer that runs "Message Queue" with other running "Message Queues". Direct connection.

(2) Configure MSMQ

Open Computer Management - Message Queuing, create a MSMQDemo queue under Private Queues

(3) Write code - Simple Demo MSMQ Object

The MessageQueue class is the package around the "Message Queue". The MessageQueue class provides references to the Message Queue queue. You can specify a path to an existing resource in the MessageQueue constructor, or you can create a new queue on the server. The new instance of the MessageQueue class must be associated with an existing queue before calling Send, PEEK, or Receive.

MessageQueue supports two types of message retrieval: synchronous and asynchronous. Synchronous PEEK and Receive methods allow the process thread to wait for a new message to reach the queue with the specified interval. Asynchronous BeginPeek and BeginReceive methods allow the primary application task to continue executing in a separate thread before the message reaches the queue. These methods operate by using the callback object and the status object to communicate between the thread.

// send Message

Private void btnsendMessage_Click (Object Sender, System.EventArgs E)

{

// Open Queue

System.Messaging.MessageQueue Queue = New System.Messaging.MessageQueue (".// Private $ // msmqdemo");

// Create Message

System.Messaging.Message Message = new system.Messaging.Message ();

Message.body = txtMessage.Text.trim ();

Message.formatter = new system.Messaging.xmlMLMESSAGEFORMATTER (New Type [] {typeof (string);

// Put Message Into Queue

Queue.send (Message);

}

// Receive Message

Private Void BtnRecEceptage_Click (Object Sender, System.EventArgs E)

{

// Open Queue

System.Messaging.MessageQueue Queue = New System.Messaging.MessageQueue (".// Private $ // msmqdemo");

// Receive Message, synchronized Receive method blocks the current execution thread until a message can get

System.Messaging.Message Message = queue.Receive ();

Message.formatter = new system.Messaging.xmlMLMESSAGEFORMATTER (New Type [] {typeof (string);

TXTRECEIVEMESSAGE.TEXT = message.body.toString ();

}

Demo interface:

******

About the MSMQ message queue introduction text comes from MSDN.

References:

1, MSDN, Message Queue

Posted on 2004-11-16 12:41

Rickie Read (5777)

Comments (14)

edit

Collect

Collection to 365Key Categories:

C. Message Queue

comment

Good!

God Bless you and me, haha

Reply

#

Re: Message Queue Introduction and Its Use

2005-01-14 17:24

Apndy

Please save help:

I tried it with C # (in private queue)

1000 records in a time, only four or fifty articles can be seen in the message queue

There is no time to receive these.

I don't know how to do it.

Apndy@163.com

Reply

#

Re: Message Queue Introduction and Its Use

2005-01-15 00:52

Rickie

Maybe You Limited Message Storage to a Specified Size.

*

You can check the property of message queue. About message.

Reply

#

Re: Message Queue Introduction and Its Use

2005-01-15 09:43

Apndy

To rickie

The message queue can store millions of records, but cannot determine the specific location stored in the disk, which format storage, if the system crashes still find records? .

Reply

#

Re: Message Queue Introduction and Its Use

2005-01-15 09:46

Apndy

To rickie:

How much is the news in the statistics message queue?

Reply

#

Re: Message Queue Introduction and Its Use

2005-01-15 10:56

Rickie

1. In order to avoid the computer restart of the message queue, the message can be lost by setting the recoverable property of the message object to True, saving the message to the disk to the disk to ensure the delivery of the message, default is false.

2, you can use Transactional Message Queues, Message Are Durable - Persisted to Disk.

******

Message in the statistics message: There are many ways to be at least through Foreach:

Foreach (System.Messaging.Message Message In Queue)

There should be other methods of higher efficiency.

Reply

#

Re: Message Queue Introduction and Its Use

2005-07-18 17:41

Elijia

MSMQ can only be there. Is it used under NET? How do I use MFC to implement this SAMPLE how to modify it!

Reply

#

Re: Message Queue Introduction and Its Use

2005-07-19 17:42

Elijia

I tried it in the C #, but why don't he identify system.mesaging? What kind of library is needed?

Reply

#

Re: Message Queue Introduction and Its Use

2005-07-25 14:43

Tony_LAU

Hello, can I use a message queue under Win2000 Profressional?

I installed, but I can't build a queue. It said what to install a computer for Workgroup, the operation is not supported. .

Do you know what is the reason?

Reply

#

problem

2005-09-20 10:56

TF

"MSMQ can work in the case where Server is offline, temporarily saving Message in the message queue of the Client side, and then send it to the Server-side processing when online."

I want to submit an order, you must submit it on a computer with MSMQ components? In reality, MSMQ is not installed on the operating system.

Reply

#

Re: Message Queue Introduction and Its Use

2005-11-05 08:54

Long

Help:

I have established a queue named myorder in the column, I want to see the queue message inside and

Log message. As a result, I can't access it, prompt "I can't read the message, error: Access is rejected"

Who can help me, thank you

Reply

#

Re: Message Queue Introduction and Its Use

2005-12-12 09:10

Billqi

Rickie Lee, Hello, ask a question,

Can the client read messages on the remote message queue server?

If you can, how do you have to achieve it? How to protect permissions and security?

Reply

#

The front code is C # read, can you read with VC?

2006-02-21 14:23

Lee0623

The front code is C # read, can you read with VC? I can't read it accurately, always garbled

Reply

#

Re: Message Queue Introduction and Its Use

2006-03-09 11:16

Mashal

I have been looking for a long time about serialization. Finally, I found a clear answer from here. Thank you

Reply

#

Re: Message Queue Introduction and Its Use

2005-01-12 11:11

Abit

转载请注明原文地址:https://www.9cbs.com/read-129660.html

New Post(0)