5 Practical Web site Crash (BIG5) (iii)

Source: Internet
Author: User
How does a quick Web site join the message queue function?

How do you add the asynchronous processing capabilities of the message queue to your Web site?

In the Windows NT Option Pack, including MSMQ (Microsoft message Queue Server), features that are not "synchronized" are provided.

The internet may be slow and unstable, and the repository may also be available, and MSMQ (Microsoft message Queue Server) provides a non "synchronous" processing that lowers the dependency of synchronization.

Don't understand? No relationship.

The key to MSMQ is "link Up" (online) and "Free" (available). Since all applications on the Internet are not necessarily connected to the same 100%-line (online), some applications may still be on the computer. The application may not be free (available) to work with other applications even if it is connected to a thread.

What is called "sync", for example, when a Web application wants to send messages to a B application, it has to wait for the response of the application to continue, and that is to "sync".

However, the B application may still not be connected to the line (online), or it may not be available (available) to deal with the work of the application.

MSMQ (Microsoft message Queue Server) provides error-tolerant features for multiple applications on the Internet in a decentralized environment. Applications that do not require immediate response are handled in an asynchronous manner. MSMQ saves the message of a application to the MSMQ, and when an application is available, it is also free to obtain information about the application stored in MSMQ.

Therefore, the MSMQ Support row motion (Mobile Computing), for example, the notebook computer has no internet connection in its normal state, and the message to be sent can be stored in the queue of the user's notebook computer, then connected to the Internet and then uploaded to the server side.

MSMQ is tightly integrated with IIS (Internet information Server) and is used by ASP to control message Queue in Web applications.

MSMQ is also tightly integrated with MTS (Microsoft Transaction Server), and the message can be "Live and Die" (Transaction) in conjunction with the data library.

You can use an ASP program to develop MSMQ Web applications, or you can use languages such as Visual Basic or Visual C + + to develop MSMQ network applications.

Send Message to MSMQ

How do you send message to MSMQ?

To perform an example of an MSMQ message, first install the Microsoft Message Queue Server for the Windows NT Option Pack, and then add a new queue column (Queue) in the message queue's [File tube] , called Test.

method to right-click on the [file] 's computer in message queue and select [Queue column] in [New file].

The named queue column name is test.

Use the browser on the client side to browse the results of the run.

In the [file] of message queue, a message sent to MSMQ is displayed under the Queue test's journal, showing the gist of the message.

With this message quickly pressed two, you can see the text part of the message in [this article].

In the ASP program, how do I send message to MSMQ?

Method first uses Server.CreateObject ("MSMQ"). MSMQQueueInfo ") to call MSMQ's components, and then set the following:

Queueinfo.pathname: The name of the queue column (queue) to which the message is sent.

You can use Queueinfo.open (2, 0) to start the queue column.

Then Server.CreateObject ("MSMQ. MSMQMessage ") call MSMQ's message symbol, and then set the text and thrust of the following message:

Msg.label: Set the gist of the message.

Msg.body: Set the inner part of the message.

After the last Msg.send queue, the message is sent to the queue column of MSMQ.

The ASP program is as follows:

<%

Set queueinfo = Server.CreateObject ("MSMQ". MSMQQueueInfo ")

Queueinfo.pathname = ". \test"

Set Queue = Queueinfo.open (2, 0)

Set MSG = Server.CreateObject ("MSMQ". MSMQMessage ")

Msg.body = "This is message body" & Now

Msg.label = "This is message Label" & Now

Msg.delivery = 1

Msg.send Queue

Queue.close

%>

Send message to MSMQ's Test queue column.

Receive Message from MSMQ

How do I receive messages from MSMQ?

If you are in a hurry to receive a message from MSMQ and use the browser to perform it on the client side, you will be denied access because it is not the end of full control.

Therefore, you must first modify the settings. In the message queue's [File tube], press the right button on the Queue column test, select [content], select [Security Settings], press the [Use Rights] button, and make the Everyone's access type [Full Control].

You can then receive the message you just sent from MSMQ, and use the browser to perform it using the client.

In the ASP program, how do you receive MESSAG from MSMQ?

Method first uses Server.CreateObject ("MSMQ"). MSMQQueueInfo ") calls MSMQ components, and then queueinfo.pathname the name of the queue column (Queue) to which the message will be received.

You can use set q = Queueinfo.open (1,0) to open this queue column. And then the next Q. After receiving, the message is started. Msg.label and Msg.body can read the text and the gist of the message.

The ASP program that receives messages from MSMQ (Microsoft message Queue Server) is as follows:

<%

Set queueinfo = Server.CreateObject ("MSMQ". MSMQQueueInfo ")

Queueinfo.pathname = ". \test"

Set q = Queueinfo.open (1,0)

Set MSG = q.receive

If not Msg are nothing Then

Response.Write "<BR> received message Label:" & Msg.label

Response.Write "<BR> received message Label:" & Msg.body

End If

%>

Did you learn?

Message Queue Plus transaction function

As I mentioned earlier, MSMQ is also tightly integrated with MTS (Microsoft Transaction Server), and the message can be shared with the data library with a "Live and Die" (Transaction) function.

When the data library is more successful, the message is communicated to other applications, and the information is not sent when the library is more defeated, which is called the Queue (transactional queue).

For example, when you enter a subscription to a data library, if the library is more successful, it will send messages to inform the stock room, if the library's more dynamic failure, it will not be sent to inform the library room.

How does the message queue add transaction functionality to the ASP program?

First of all, add transaction=required to the first line of the ASP program and tell IIS that this ASP program uses the Transaction function.

Msg.delivery = 1 is set as a way to restore the transfer (recoverable Delivery).

If all of the programs in this ASP program are successful, including updating the message of the data library and message queue, you will call the OnTransactionCommit () applet. If a failure is performed, such as updating any of the library failures, the OnTransactionAbort () program will be called.

Message Queue plus transaction functionality, the ASP program is as follows:

<%@ transaction=required Language=vbscript%>

...

<%set queueinfo = Server.CreateObject ("MSMQ. MSMQQueueInfo ")

Queueinfo.pathname = ". \test"

Set Queue = Queueinfo.open (2, 0)

Set MSG = Server.CreateObject ("MSMQ". MSMQMessage ")

Msg.body = "



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.