Asynchronous Processing and COM - PowerPoint PPT Presentation

1 / 27
About This Presentation
Title:

Asynchronous Processing and COM

Description:

Client waits for server response. Synchronous Processing. Request. Client. Server ... Sender need not wait for a response from the receiver ... – PowerPoint PPT presentation

Number of Views:66
Avg rating:3.0/5.0
Slides: 28
Provided by: sac670
Category:

less

Transcript and Presenter's Notes

Title: Asynchronous Processing and COM


1
Chapter 8
  • Asynchronous Processing and COM

2
Objectives
  • Explain asynchronous processing
  • Identify the need for asynchronous processing
  • Discuss different ways of implementing
    asynchronous processing
  •    MSMQ
  •    COM Queued Components

3
Types of Processing
4
Reasons for Asynchronous Processing
5
Ways of Implementing Asynchronous Processing
Develops asynchronous message-oriented Windows-
based applications
MSMQ
Follows a Recorder-Listener-Player architecture
COM Queued Components
Based upon loosely coupled events and models the
Publisher-Subscriber architecture
COM Events
6
Messaging
Sender
Receiver
7
Messaging (1)
Advantages
8
Messaging (2)
Drawbacks
9
Elements of Message-Oriented Middleware
10
MSMQ MMC snap-in
MSMQ is an example of a MOM. It makes loosely
coupled asynchronous communication possible
between application components.
11
Parts in MSMQ Application
Object that stores the message temporarily
Application component that sends the message
Application component that receives the message
12
Object Types in MSMQ
13
Parts of MSMQ Messages
14
Queues in MSMQ
Queue Temporary storage area for messages until
they reach their destination
15
Queue Types in MSMQ
16
Application using MSMQ
Server Component (MSMQServer.cs)
using System.Messaging . pu
blic static void Main (String args) string
mqPath ".\\" args 0   / If Message Queue
does not exist, create it / if
(MessageQueue.Exists (mqPath) false)
MessageQueue.Create (mqPath)   / Create
a MessageQueue Object for that Queue
/ MessageQueue mq new MessageQueue
(mqPath)   / Send the Message to this Queue
/ mq.Send (args 1)
17
Application using MSMQ (1)
Client Component (MSMQClient.cs)
using System.Messaging   public static
void Main (String args) string mqPath
".\\" args 0   / If such a Message Queue
does not exist, give an error Message and Exit
/ if (MessageQueue.Exists (mqPath) false)
return   / Create a
Queue / MessageQueue mq new MessageQueue
(mqPath)   / Set the formatter for a
message read from the queue. / mq.Formatter
new XmlMessageFormatter(new String"System.Str
ing,mscorlib")

18
Application using MSMQ (2)
Client Component (MSMQClient.cs) contd.
  / Set a Message Handler for this Queue
/ mq.ReceiveCompleted new ReceiveCompletedEve
ntHandler(MessageArrived) mq.BeginReceive
() ..   / The Message Handler
for receiving Messages Asynchronously
/ public static void MessageArrived (Object
obj, ReceiveCompletedEventArgs asyncRcvd)
MessageQueue mq (MessageQueue) obj Message
msg mq.EndReceive(asyncRcvd.AsyncResult)
19
Application using MSMQ (3)
Client Component (MSMQClient.cs) contd.
   / Display the Received Message
/ Console.WriteLine ("The Message Received
Reads " (string)msg.Body) mq.BeginReceive
()
20
MMC snap-in after executing the Server Component
21
COM Queued Components
Listener
Picks up message from queue and forwards it to
player
Invokes methods on server
MSMQ Queue
Player
Plays message to server component
Message is put in queue
Recorder
Call is recorded and the message is passed
22
Application using COMQC
Server Component (QCserver.cs)
using System.EnterpriseServices ..   //
Two types for application activation, library and
server assembly ApplicationActivation(Activatio
nOption.Server)   // Strong name key
file assembly AssemblyKeyFile("d\\QCDemo.snk")
  // Enables queuing support for the COM
component. assembly ApplicationQueuing(Enabledt
rue, QueueListenerEnabledtrue)
23
Application using COMQC (1)
Server Component (QCserver.cs) contd.
 / This application only requires an MSMQ
workgroup installation and is not set up to work
with a domain controller. / assembly
ApplicationAccessControl(Valuefalse,
AuthenticationAuthenticationOption.None)  names
pace QCDemo / InterfaceQueuing enables
queuing support for the IQComp interface. Calls
on the interface will be queued using MSMQ /
InterfaceQueuing public interface IQComponent
void DisplayMessage(string msg)
24
Application using COM QC (2)
Server Component (QCserver.cs) contd.
public class QComp ServicedComponent,
IQComponent public void
DisplayMessage(string msg) MessageBox.Show(
msg, "Component Processing Message")
25
Application using COM QC (3)
Client Component (QCclient.cs)
using System.Runtime.InteropServices . p
ublic static void Main(string args)
IQComponent iQC . /
invoke an instance of the queued component using
a queue moniker this provides a client reference
that is called in as if it were an actual
instance of the server component / iQC
(IQComponent) Marshal.BindToMoniker("queue/newQC
Demo.QComp") / If we're not connected to an
activated server object, this will place a
packaged message in the qcserver queue.
/ iQC.DisplayMessage (args0)
26
Application using COM QC (4)
Client Component (QCclient.cs) contd.
 / appropriate method for releasing our queued
component / Marshal.ReleaseComObject(iQC)

27
MMC snap-in displaying QCserver
Write a Comment
User Comments (0)
About PowerShow.com