Some of the previously collected data---use MSMQ to resolve process deadlock issues in ASP.

Source: Internet
Author: User
Tags message queue msmq
Resolve | process | Problems using MSMQ in ASP
When an ASP program takes too long for a process to expire on the client,
When a visitor has abandoned a visit to your site and left for another site.
Or if you have a large number of dead queues blocked on your server, the error "Server is too Busy"
It happened.
When you are in the process of designing a website to encounter these problems, one solution is to use
Microsoft message Queue (MSMQ) to end these processes.

Basic Introduction to Microsoft message Queue:
MSMQ (code-named "Falcon") is a service running in Windows NT, which provides application between programs
of asynchronous communication. You can find it in the NT4 Option pack.
The basic concept of MSMQ is simple: it can be viewed as an email between applications.
A message is packaged into a particular type of container, and the message is saved to a particular
Role in the queue until the recipient accepts the message.
These queues ensure the delivery of MSMQ regardless of the current network connection status.
Like all e-mails, MSMQ messages have a sender and a recipient, the receiver of which
should be able to access the queue. A separate message in a single queue that has
Multiple recipients such as Respinder. The sender of the message is typically web Server (IIS).

MSMQ can also communicate with other messaging systems. For example:
Sun Solaris, HP-UNIX,OS/2, VMS, as/400 platform
Like other BackOffice services, MSMQ has a COM API (Mqoa.dll) for developers to develop
Program. The three most commonly used classes are: MSMQQueueInfo, MSMQQueue, MSMQMessage.

Msqmqueueinfo
MSMQQueueInfo allows you to create new, open, and delete messages in the queue. To establish contact with a queue first you need to set up
PathName, which is the property of a named queue, tells msqm which machine is the queue.
<%
Dim objQueueInfo
Dim Objqueue
Set objqueueinfo=server.createobject ("MSMQ. MSMQQueueInfo ")
Objqueue.pathname = ". \MyQueue"
Set objqueue = Objqueueinfo.open (mq_send_access, Mq_deny_none)
%>
The code above opens a local queue called Myqueue. If the queue is on another server, the code should be like this
Objqueue.pathname = "Someothercomputer\myqueue"
There are two parameters in the open queue: Access and ShareMode. Access indicates what action will be performed on the queue.
There are generally three operations:
Mq_peek_access, Mq_receive_access (1), mq_send_access (2).
Mq_peek_access is used to find messages in a particular queue. However, no action is performed on the message.
Mq_receive_access is used to delete a message in the queue after it is read.
Mq_send_access is used to send messages in queues, but not to receive messages.
Note that a MSMQQueue object is returned after using the open operation.
The following is a typical new and delete operation:
<%
Dim Objqueue
Set objqueue = Server.CreateObject ("MSMQ". MSMQQueueInfo ")
Objqueue.pathname = ". \MyQueue"
Objqueue.create
%>

<%
Dim Objqueue
Set objqueue = Server.CreateObject ("MSMQ". MSMQQueueInfo ")
Objqueue.pathname = ". \MyQueue"
Objqueue.delete
%>

MSMQQueue
The MSMQQueue class is used to describe a queue that is opened in an MSMQ service. This class provides a
The ability to loop messages in the pointer queue. You can't open a queue that uses the MSMQQueue class
To do this, you can only use Msqmqueueinfo.
Although many ASP applications typically use MSMQ to send messages, many times it is necessary for ASPs to display the details of the message.
There are two ways to get a message: synchronous, asynchronous, but the ASP can only use synchronous methods.
This is because the ASP is not able to declare a WithEvents variable on the server side.
Here is an example of using MSMQ in an asynchronous Way (VB only)
Option Explicit
Dim M_objqueueinfo as New msmqqueueinfo
Dim M_objqueue as MSMQQueue
Dim WithEvents M_objmsmqevent as MSMQEvent

Private Sub Form_Load ()
M_objqueueinfo.pathname = ". \MyQueue"
M_objqueueinfo.label = "My Sample Queue"
On Error Resume Next
M_objqueueinfo.create
On Error GoTo 0
Set m_objqueue = M_objqueueinfo.open (mq_receive_access, Mq_deny_none)

Set m_objmsmqevent = New msmqevent
M_objqueue.enablenotification m_objmsmqevent, mqmsg_current, 1000
End Sub

Private Sub m_objmsmqevent_arrived (ByVal Queue as Object, ByVal Cursor as Long)
Dim M_objmessage as MSMQMessage
Set m_objmessage = queue.peekcurrent
MsgBox "message Received:" & M_objmessage.label
M_objqueue.enablenotification m_objmsmqevent, Mqmsg_next, 10000
End Sub

Private Sub M_objmsmqevent_arrivederror (ByVal Queue as Object, ByVal errorcode as Long, ByVal Cursor as Long)
MsgBox "Error accorded:" & ErrorCode
End Sub
This code first establishes a queue (if it does not yet exist).
The M_objmsmqevent object is then connected to the MSMQQueue object by calling EnableNotification.
Once connected to the MSMQEvent object, the next thing you need to do is to complete the arrived and Arrived_error (optional) events.
Arrived event is triggered when a new message arrives in the queue
The event returns two pointers, one pointing to where the message should never be read in the queue, and the other is the current location.
If an error occurs, the Arrivederror event is triggered
When a message is synchronously fetched, the program is not suspended until the message is available or the timeout occurs.
The code is as follows:



Related Article

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.