Message Queue Introduction and Its Use

xiaoxiao2021-03-14  215

use

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

versus

XML Web SERVICES

with

.NET Remoting

Like, it is a distributed development technology. But use

XML Web SERVICES

or

.NET Remoting

When assemblies,

Client

Did need and

Server

Didually exchange information in real time,

Server

Need to keep online.

MSMQ

Can

Server

Work offline, will

Message

Temporary preservation

Client

In the end of the message queue, send it to the next time.

Server

End processing.

Obviously,

MSMQ

Not suitable for

Client

need

Server

This situation in time in time,

MSMQ

Asynchronously and

Server

End interactions, don't worry

Server

The long-term process of end.

although

XML Web SERVICES

with

.NET Remoting

All offer

[Oneway]

Attributes to process asynchronous calls to solve

Server

Termatic method call for a long time

Client

end. But can't solve a lot

Client

Load problem, at this time

Server

Accepted requests are faster than the request.

Under normal circumstances,

[Oneway]

Attributes are not used in specialized messaging services.

1.

Basic terminology and concept (

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, it is installed any

Microsoft Windows

In a computer combination, the message processing and message queue function is provided for any application, regardless of whether the computers are on the same network or whether it 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 (

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. Specify hope

MessageQueue

The management queue used by the component (if any).

The Response Queue contains a response message to send an application when the target application receives a message. Specify hope

MessageQueue

The response queue used by the component (if any).

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 any given queue

BeginReceive

Method, then continue other tasks immediately 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.

Interact 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.

in

.NET

Simple in the environment

Message Queue

program

(

1

)

Message Queuing Services

by

Control Panel

,

"Add / Remove Programs" - "Add / Remove Windows Components"

Step installation

MSMQ

.

MSMQ

It 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

) Configuration

MSMQ

turn on

Computer Management - Message Queuing

,in

Private queues

Create

MSMQDemo

queue

(

3

Writing code - Simple Demo

MSMQ

Object

MessageQueue

Class is the packaging around the "Message Queue".

MessageQueue

Category provides references to the "Message Queue" queue. allowable

MessageQueue

The constructor specifies a path to an existing resource or creating a new queue on the server. In call

Send

,

PEEK

or

Receive

Before, you must

MessageQueue

A new instance of a class is associated with an existing queue.

MessageQueue

Support two types of message retrieval: synchronous and asynchronous. Synchronous

PEEK

with

Receive

The method allows the process thread to wait for a new message to reach the queue with the specified interval. Asynchronous

Beginpeek

with

BeginReceive

The method allows the primary application task to continue executing in a separate thread before the message arrives at 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 btnreceiveMessage_Click (Object Sender, System.EventArgs E)

{

// Open Queue

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

// Receive Message,

Synchronous

Receive

Method blocks the current execution thread until one

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:

******

on

MSMQ

Message queue introduction text comes from

MSDN.

References:

1, MSDN,

message queue(

Message Queue

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

New Post(0)