ASP 3.0 The Complete Reference
Chapter 22
Working with MSMQ (Outline and Notes)
Microsoft Message Queue Server (MSMQ) allows for the
creation of asynchronous messaging applications, which employ a store and
forward data handling capability. The
advantages of this are added reliability, and decreased dependence on a server
response as synchronous messaging applications face.
- When
you have disconnected userssuch as when your sales force is working
remotely.
- When
guaranteed delivery is importantstockbrokers, for example, may lose
millions of dollars if their order entry applications lose even a single
order.
- When
you need concurrent executionwhen you want to fire off lots of requests
for work without dealing with difficult tasks like thread management.
- When
you need to log Activityyour actions through MSMQ are automatically
journaled; that's good for maintaining audit trails and recovering data.
Transactions that do not require feedback for the user or
a lengthy processing time.
Other Properties
Message Queuing Concepts
Provides Threading capabilities for ASP
Allowing procedures to be carried out be in separate process
Synchronous vs. Asynchronous Communication
Communications are synchronous when the sender of a
request must wait for a response from the receiver of the request before
performing other tasks. The time that the sender must wait is completely
dependent on the time it takes for the receiver to process the request and
return a response.
With asynchronous communicationsavailable through
MSMQsenders make requests to receivers and can then move on to other tasks
immediately. If a response is expected back from the receiver, it is up to the
original sender to decide when it will actually look for and process the
response. Most important, there is no need for a guarantee that receivers will
process requests within any particular period of time. In fact, with
asynchronous communications, there are no requirements that receivers even be
running in order for a sender to initiate a request.
A Message Queuing Analogy
Comparing telephone conversations and electronic mail
exchanges provides a good analogy. With a telephone conversation, callers can
exchange information immediately and quickly. The telephone is much less
useful, however, when one of the two parties cannot be contacted. The telephone
line may have been severed, or the other party may be busy doing other tasks or
simply out to lunch. In any case, the calling party must continue to dial the
receiving party periodically in order to deliver an important message.
In the case of electronic mail, on the other hand, the
calling party could simply send an e-mail message and move on to other tasks,
knowing that the receiver will eventually get the message and act
appropriately. Of course, what makes e-mail a viable alternative to the
telephone is the knowledge that messages will be delivered reliably and
receivers will eventually read their mail and perform required actions. Message
queuing is like electronic mail, except senders and receivers are application
programs instead of peopleand messages are data instead of electronic letters.
Queueing Scenarios
Benefits of Queued Applications
Figure 1:
Diagram of Queued Application Architecture
Types of Queues
Outgoing
Public
Private
System
The MSMQ Object Model
Show All
Figure 2:
Object Hierarchy
|
MSMQApplication
|
Provides methods and properties for the application
object, including MSMQ version properties.
|
|
MSMQCoordinatedTransactionDispenser
|
Obtains an MS DTC transaction object.
|
|
MSMQEvent
|
Implements a single event handler that can support
multiple queues.
|
|
MSMQMessage
|
Provides the message properties used to specify the
behavior of the message and a method for sending the message to the queue.
|
|
MSMQQuery
|
Allows you to query the directory service for existing
public queues.
|
|
MSMQQueue
|
Represents an open instance of an MSMQ queue.
|
|
MSMQQueueInfo
|
Represents an MSMQ queue.
|
|
MSMQQueueInfos
|
Represents a set of MSMQ public queues.
|
|
MSMQTransaction
|
Represents a transaction object obtained externally, or
created internally.
|
|
MSMQTransactionDispenser
|
Creates a new MSMQ internal transaction
|
Choosing Server Side or Client Side Queues
MSMQ provides COM components that can be used to create
Web-based applications using server and client-side scripting.
Server-side Scripting with Queues
MSMQ COM components can be used in Active Server Pages
(ASP) scripts using VBScript. When using this type of scripting, MSMQ must be
installed on the server where the ASP pages are stored, not on the client
machines where the browser is running.
The following programming considerations should be kept
in mind when developing your application
Only local queues can be created when using ASP pages.
Queues cannot be created on a remote computer.
Your script must be in a text file that has an .asp
suffix (for example, mq.asp). It can be stored in the InetPub\Scripts folder on
your web server or any other folder that has execute script privileges.
For more information about using server-side scripting
with ASP, see http://msdn.microsoft.com/workshop/server/asp/aspover.asp.
Client-side Scripting with Queues
MSMQ COM components can be used in any HTML page using
the <OBJECT> tag in VBScript. When using this type of scripting, MSMQ
must be installed on an all client machines.
Designing Applications with MSMQ
Using ASP and MSMQ together to create asynchronous applications
Challenges of MSMQ applications
WARNING: MSMQ messages are restricted to 4 MB
Interoperability
Level 8
What You Need
Installing MSMQ
NT 4.0
Windows 2000
Choosing your options
Overview of the options
Synchronous or Asynchronous connection to the queue
Store and Forward optin
Setting Up a Primary Enterprise Controller
Figure 3:Screen
Shot
Setting Up an Independent Client
Figure 4:
Screen Shot
Building an Order processing Queue
Figure 5:
Diagram the relation between entities
|
|
Request Page
|
|
1
2
3
4
5
6
7
8
9
10
|
|
Figure 6:
Response Page
|
|
Response Page
|
|
1
2
3
4
5
6
7
8
9
10
|
|
Creating a Queue
|
|
VBScript
|
|
1
2
3
4
5
6
7
8
9
10
|
|
Opening A Queue
|
|
VBScript
|
|
1
2
3
4
5
6
7
8
9
10
|
|
Finding a Queue
|
|
VBScript
|
|
1
2
3
4
5
6
7
8
9
10
|
|
Creating a Message
|
|
VBScript
|
|
1
2
3
4
5
6
7
8
9
10
|
|
Types of Data
Overcoming Limits of Data size
Passing Components
Passing components that support IDispatch and IPersist
ADO Objects
Word Objects
refer to COM chapter
Sending a Message
|
|
VBScript
|
|
1
2
3
4
5
6
7
8
9
10
|
|
Reading from a Queue
Using Receive
|
|
VBScript
|
|
1
2
3
4
5
6
7
8
9
10
|
|
Using PeekCurrent
Cursors
PeekNext
|
|
VBScript
|
|
1
2
3
4
5
6
7
8
9
10
|
|
Filtering Messages
Message Class Filter
|
|
VBScript
|
|
1
2
3
4
5
6
7
8
9
10
|
|
Application Specific Filter
|
|
VBScript
|
|
1
2
3
4
5
6
7
8
9
10
|
|
Requesting Acknowledgement after Sending a Message
Setting up the Admin Queue
|
|
VBScript
|
|
1
2
3
4
5
6
7
8
9
10
|
|
Requesting a Response from the Processer
Setting up the Response Queue
|
|
VBScript
|
|
1
2
3
4
5
6
7
8
9
10
|
|
Configuring the Other Side
getting the Response Queue
sending the Response Message
Monitoring Queues
Viewing Queue Activity
Figure 7:
Screen Shot of MSMQ Admin
Setting a Journal Queue
Figure 8:
Screen Shot
|
|
VBScript
|
|
1
2
3
4
5
6
7
8
9
10
|
|
Handling Errors with MSMQ
|
|
VBScript
|
|
1
2
3
4
5
6
7
8
9
10
|
|
Handling Transaction with MSMQ
Single Message Transaction
|
|
VBScript
|
|
1
2
3
4
5
6
7
8
9
10
|
|
Transaction Dispensers
MSMQTransactionDispenser
|
|
VBScript
|
|
1
2
3
4
5
6
7
8
9
10
|
|
MSMQCoordinatedTransactionDispenser
|
|
VBScript
|
|
1
2
3
4
5
6
7
8
9
10
|
|
A Word about COM+ Queued Components