280 likes | 1.08k Views
Microsoft Message Queues MSMQ. Brian Francis NCR Corporation WROX Press. Agenda. What is Messages Queuing Why use Message Queuing Working with Queues and Messages. What is Messages Queuing. Message queuing is a system that allows different applications to communicate with each other.
E N D
Microsoft Message QueuesMSMQ Brian Francis NCR Corporation WROX Press
Agenda • What is Messages Queuing • Why use Message Queuing • Working with Queues and Messages
What is Messages Queuing • Message queuing is a system that allows different applications to communicate with each other. E-mail for Applications
Message Queues • Message Content • Message Data - Application Specific • Sender, Receiver, Timestamp, Expiration • Message Queue • Like a Post Office Box
Why use Message Queuing • Distributed Systems • Communication Speed • MSMQ vs. COM
Distributed Systems • Network-centric Applications • Non-permanent connections • Disconnected users
Communication Speed • TCP is faster, but the connection HAS TO BE reliable… • Faster connections => more expensive connections
MSMQ vs. COM • Synchronous Operations • All systems connected via fast links • Familiar programming model
When to use MSMQ • If the application you are communicating with is not running at the same time as your application, use message queuing… • If the message is important and will cause problems if it is lost, use message queuing… • If your application is not always connected to receiver application, but still needs to be functional, use message queuing... • And if you perform many communication tasks with other application asynchronously, and may or may not care about their response, use message queuing…
Working with Queues and Messages • MSMQ Object Model • MSMQ from ASP Pages • MSMQ from ASP VB Components
MSMQ for ASP Pages • Declare our variables • Loop through the queues • Peek at the first message • Display its label • Peek for any more messages • Move onto the next queue
Declare our variables • Declare Variables and Create Obejcts <% Option Explicit Dim query Set query = Server.CreateObject("MSMQ.MSMQQuery") Dim qinfos, qinfo, queue, msg Dim arQueues arQueues = Array("OrderReady", "PackingSlip", _ "PendingOrder", "OrderPicking") Dim strQueueName
Loop through the queues • For each queue, create a table and populate with list of contained messages Response.Write "<TABLE WIDTH="95%"><TR>" For Each strQueueName In arQueues Response.Write "<TD valign=top><TABLE BORDER=1>_ <TR><TH>" & strQueueName & "</TH></TR>" & vbCrLf set qinfos = query.LookupQueue(,,strQueueName) qinfos.Reset Set qinfo = qinfos.Next If IsObject(qinfo) Then
Peek at the first message • Check to see if there is a message in the queue – PeekCurrent to set cursor position • If not, display Queue Empty message Set queue = qinfo.Open(MQ_PEEK_ACCESS, MQ_DENY_NONE) Set msg = queue.PeekCurrent(100, False, False) If msg Is Nothing Then Response.Write "<TR><TD>Queue Empty</TD></TR>" _ & vbCrLf Else Do While Not (msg Is Nothing)
Display its label • The Order Number is stored in the label field, so display it. Response.Write "<TR><TD>“ & msg.Label & _ "</TD></TR>" & vbCrLf
Peek for any more messages • Use the PeekNext to check for the next message in the queue Set msg = queue.PeekNext(50, False, False) Loop End If End If
Move onto the next queue • End the table for the current queue, then move on to the next queue Response.Write "</TABLE></TD>" & vbCrLf Next Response.Write "</TR></TABLE>" & vbCrLf %>
MSMQ for ASP VB Components • Create the Project • Set References • Implement ObjectControl • Common Helper Functions • Posting to a queue • Retrieving from a queue • Use in ASP
Building the VB Component - Show Example -
References • Professional ASP Components • Professional ASP 3.0 • http://www.asptoday.com
Q & A • Questions? • Email - bfrancis@mindspring.com