Message Queuing and Asynchronous Inter Process Communication - PowerPoint PPT Presentation

1 / 27
About This Presentation
Title:

Message Queuing and Asynchronous Inter Process Communication

Description:

How to make your applications appear to be really snappy when they're ... Credit Check, Stock Control and Order Despatch components to deal with the order. ... – PowerPoint PPT presentation

Number of Views:197
Avg rating:3.0/5.0
Slides: 28
Provided by: rich80
Category:

less

Transcript and Presenter's Notes

Title: Message Queuing and Asynchronous Inter Process Communication


1
Message Queuing and Asynchronous Inter Process
Communication
  • An exposition on why and how to use .Net to
    introduce Message Queuing into your applications
  •  
  •  
  •  

2
Sub-title
  • How to make your applications appear to be really
    snappy when theyre actually dog-slow.

3
What is Message Queuing?
  • Message Queuing is a technique for implementing
    Asynchronous Inter Process Communication
  • Its an abstraction of a file-based persistence
    and network communication layer.

4
What is Inter Process Communication?
  • IPC is communication between two discrete
    processes, typically one of which provides some
    service to the other (but they could be equal
    partners, servicing each other).

5
So what then is Synchronous Inter Process
Communication?
  • Synchronous IPC is what we usually refer to as a
    Remote Procedure Call (RPC), examples being a
    call to a dll function or an MTS object, or
    executing a SQL query.

6
Okay, what then is Asynchronous Inter Process
Communication?
  • Asynchronous IPC means that the process
    requesting the service doesnt wait for
    confirmation that the service has been carried
    out.

7
Why would I want to use this malarky when I can
use good old RPCs?
  • Lots of reasons, but mainly
  • Your calling process wants to get on with things
    and doesnt care when the service is carried out,
    as long as its assured that it will be
    eventually, guaranteed, no questions, no excuses.

8
Like when??
Example an order processing system When a
customer places an order, the Order Placing
component doesnt want to wait for the Credit
Check, Stock Control and Order Despatch
components to deal with the order. MQ is one way
to accomplish this, in a way which allows parts
of an application to continue functioning even if
other parts are out of service.
9
How does it work?
  • One process acts as a client and posts a message
    to a named queue.
  • The other process acts as a server and retrieves
    the message from the named queue and processes
    it. The message contains everything it needs to
    perform the required service.
  • The Message Queue system takes care of everything
    in between

10
  • If required, notification of completion of the
    service could be posted back to the client as
    another message in a separate queue

11
What exactly is a message?
  • A message is a container for whatever you like.
  • It can contain some ASCII text, or a large chunk
    of binary data to be stored in a database, a
    spreadsheet, or anything in between. The MQ
    system doesnt care about the contents, or impose
    any formats.
  • Both processes (ie the programmers) must have
    agreed beforehand on the format of the message
    body no XML-type dtds, WSDL or any of that
    stuff.)

12
  • Typically there will be a single queue for
    each IPC, ie between each client and the server
    providing the service. A componentised
    application could, overall, use many queues.
  • Queues are managed by the MQ Service. The MQ
    Service guarantees that the messages are
    persisted, delivered once only, and retrieved in
    FIFO order.
  •  
  • Messages can be grouped as a transaction (so
    that they are all successfully processed, or none
    are.)

13
  • This demo uses MSMQ2, which is part of
    Windows2000, but there are other cross-platform
    MQ systems available.
  • Its called MSMQ2 because its the first version
    that works properly.

14
Whats it look like?
  • Single server model (ie single-machine model)
  • Multi-server model

15
Single server model (ie single-machine model)
  • Simple to setup and administer
  • Has the advantages of AIPC without much
    complexity
  • BUT
  • Is limited to processes running on the same
    machine.

16
Multi-server model
  • More complex to setup.
  •  
  • Can be across the motherboard, across the room or
    Across The Universe.
  • (over MSII the Microsoft Intergalactic Internet
    real soon now)
  •  
  • Can provide multiple routes for messages, and is
    therefore very robust.

17
  • Has lots of TLAs (MQIS, PEC, BSC, PSC, RS, IC,
    DC and the list goes on. its TLA Heaven. eg
    a BSC may also be a RS, but you must install a
    PEC or PSC before you install a BSC, whether you
    use an IC or a DC)
  •  
  • These all work together to guarantee that a
    message is delivered once, and once only,
    wherever it is sent.

18
  • A Primary Enterprise Controller (PEC) manages the
    entire MQ system across servers. It is the
    foundation of the MQ infrastructure.
  • The Primary Site Controller (PSC) is the No. 2IC,
    controlling one site in the infrastructure. The
    PEC also serves as the PSC for its own site.

19
  • A Backup Server Controller (BSC) provides load
    balancing and failure recovery support. It takes
    over control if the PEC or PSC fail.
  • The Routing Server (RS) supports dynamic routing,
    load balancing and intermediate store-and-forward
    message processing. RSs allow multiple routes to
    be set up between source to destination, with
    cost-based routing policies.PEC, PSC and BSC all
    act as RSs.

20
Either way, to process the messages you can use.
  •  Sequential server
  •   The server process waits for a message to
    arrive at the top of the named queue. It pops the
    message off the queue and processes it. This is
    repeated, one message at a time. Each message has
    to wait for the previous message to be processed
    before it is dealt with.

21
  • Alternatively the process can respond to
    OnMessage (?) events, using separate threads to
    process each message.

22
  • Message Queuing is complementary to binary
    remoting.

23
Heres One I Did Earlier
24
Now for some Code examples.
25
  • .Net provides classes that tidy up a lot of the
    detail (System.Messaging namespace)
  • but not all so I did my own to finish the job
  •  

26
MSMQ.cs contains a class for opening a local
queue for reading or writing, first creating it
if necessary, and posting or retrieving messages
to and from it. This class abstracts most of the
details of using the message queue, including
serializing the message object.MSMQSender and
ProcCall code which posts messages to the queue
using the above class.MSMQReceiver for an
application client which pops messages from the
queue, using the above class.ProcCallHandler a
processing server, which retrieves procedure call
messages from the queue in sequence and executes
the requested procedure. A sort of disconnected
RPC processor.
27
ReferencesMSMQ from Scratch (Crane, Crummer,
Miller)Visual Studio.Net Help MSDN
Write a Comment
User Comments (0)
About PowerShow.com