1. WHAT IS MSMQ?
2. WHY WE NEED MSMQ?
2.1. PURPOSE
2.2. WHERE APPLICABLE
2.3. DEVELOPER AUDIENCE
3. MSMQ REMOVES MACHINE DEPENDENCY.
4. HOW TO INSTALL MSMQ ON WINDOWS 7 OR VISTA?
5. UNDERSTANDING MSMQ THROUGH SAMPLE PROGRAM
6. SYSTEM.MESSAGING (MSMQ) VS WCF QUEUING
7. PROBLEM WITH MSMQ IN REAL LIFE:
8. REFERENCES
1.
What is
MSMQ?
MSMQ is
essentially a messaging protocol that allows applications running on separate
servers/processes to communicate in a failsafe manner. A queue is a temporary
storage location from which messages can be sent and received reliably, as and
when conditions permit.
2.
Why we need
MSMQ?
Message Queuing (MSMQ) technology enables applications running
at different times to communicate across heterogeneous networks and systems
that may be temporarily offline. Applications send messages to queues and read messages from
queues
2.1. Purpose
Let’s
understand this by following example. Suppose there are two applications;
Application
1: Agent application - Create policy and sends policy ID to Examiner for review.
Application
2: Examiner application review and process the policy Id.
Approach
1: Agent sends the policy id. Examiner process the request
once received.
Examiner
may take time to review the policy; meanwhile agent can submit multiple
requests asynchronously.
Challenges:
i.
System must be capable
of handling asynchronous request.
ii.
What if both the
applications are made up of different technologies. They may not talk with each
other directly.
·
From Application 1 we
can invoke the functions in web services asynchronously.
Major
Challenge though:
Ø What if application 2 is temporarily down or examiner is not
present at that time?
·
Application 1 will get
an exception. - No Offline Capability.
Approach
2: Intermediate warehouse will resolve above issues.
Agent and Examiner will not communicate directly. Agent
submits the policy request to warehouse. If examiner started working will pick
one by one request from warehouse and process it. This intermediate warehouse
can be anything like database, excel file, notepad file etc.
Small challenge:
Ø Automatic prioritization.
It
might be the case that Umbrella policies have high priority to be reviewed due
to higher premium values then normal policies. Manually, we can append some
kind of flag or integer priority value to every policy id before sending it to intermediate
warehouse (bit complex to validate policies). Examiner will pick the high
priority request/policy to process.
Ø Warehouse Maintenance
We
have to also consider the limitation of warehouse, how to remove the processed
request, the correct format for dynamic request, managing priority index
etc.
Approach 3: Using MSMQ to overcome all above
problems.
MS Message Queuing is a windows component having enhanced
capabilities to handle asynchronous request. It also provides capabilities to
prioritize the request and handle its queue automatically.
2.2. Where Applicable
Message Queuing provides guaranteed message delivery,
efficient routing, security, and priority-based messaging. It can be used to
implement solutions to both asynchronous and synchronous scenarios requiring
high performance. The following list shows several places where Message Queuing
can be used.
·
Mission-critical
financial services: for example, electronic commerce.
·
Embedded and hand-held
applications: for example, underlying communications to and from embedded
devices that route baggage through airports by means of an automatic baggage
system.
·
Outside sales: for
example, sales automation applications for traveling sales representatives.
·
Workflow: Message queuing
makes it easy to create a workflow that updates each system. A typical design
pattern is to implement an agent to interact with each system. Using workflow-agent
architecture also minimizes the impact of changes in one system on the other
systems. With Message Queuing, the loose coupling between systems makes
upgrading individual systems simpler.
2.3. Developer Audience
Message Queuing applications can be developed using C++ APIs
or COM objects. Applications can be built in any of the popular development
environments: for example, Microsoft® Visual Basic®, Visual Basic® Scripting
Edition, Visual C++®, Visual Studio® .NET, Borland Delphi, and Power soft PowerBuilder.
This allows applications to be developed for the Internet as well, including
both server-side (Internet Information Server) and client-side (Internet
Explorer) applications. The .NET Framework offers a set of managed Message
Queuing objects.
3.
MSMQ removes
Machine Dependency.
By replacing the direct queue with Message queue client can
directly send messages to server even when the server goes down and server can
continuously send response even when client is unavailable. When any one of the
two goes down messages simple resides in queue and wait to get picked up. These
messages eventually get processed when the system come back online and start
pulling the messages from queue. So it removes the Machine Dependency but what
happen if the machine hosting the message went down or network went down?
In this case, the message wouldn’t even be able to reach to
Message queue.
MSMQ has a
very useful feature called as outgoing queue.
This feature allows the system sending a message to store the message on local
queue if it’s unable to send the message out due to network issues or the
remote location being offline. The MSMQ service will try to resend these
messages at a later time.
4.
How to
install MSMQ on windows 7 or Vista?
1.
Open Control Panel.
2.
Click Programs and then, under Programs
and Features, click Turn Windows Features on and off.
3.
Expand Microsoft Message Queue (MSMQ) Server, expand Microsoft
Message Queue (MSMQ) Server Core, and then select the check boxes for the
following Message Queuing features to install:
o MSMQ
Active Directory Domain Services Integration (for computers joined to a
Domain).
o MSMQ
HTTP Support.
4.
Click OK.
5.
If you are prompted to restart the computer, click OK to complete the installation.
5.
Understanding
MSMQ through Sample Program
It requires System.Messaging namespace provides classes that
allow you to connect to, monitor, and administer message queues on the network
and send, receive, or peek messages. Please refer this
link to see its class description.
Sender – Application 1 – Agent App. – Sends policy Id to
examiner for review. UM policies have higher priority.
Messages are queued in MSMQ service under computer Management
Receiver – Application 2 – Examiner – Process the UM policies on
priority others on FIFO basis. Priority can be one
of the below:
6.
System.messaging (msmq) vs
wcf queuing
System.Messaging (SM)
|
WCF Queuing
|
Why is this interesting?
|
At its core, is a wrapper around MSMQ’s APIs.
|
At its core, is a wrapper around MSMQ’s APIs.
|
Both technologies wrap MSMQ and benefits robust, stable, and time
tested reliable messaging platform no matter which way you go.
|
Enables an object-oriented view of your application’s asynchronous communication
plumbing.
|
Enables an object oriented view of your application’s business
processes.
|
The WCF programming model is centered on your business operations. With it, you can
stop managing your message transactions, setting message properties,
searching for messages in a queue, checking for NACKS, retrying messages,
etc. Instead you can start thinking of the world in terms of business
operations (e.g. CreatePurchaseOrder) and focus on your business logic.
Leave the tedium to WCF.
|
Enables you to write your own end-to-end message
encryption/authentication.
|
Provides end-to-end message encryption/authentication for free.
|
SM encrypts messages while they’re on the wire and will enforce a
queue’s ACL, which is great. If you want your messages encrypted on
disk, however, or any authentication besides who is allowed to send
to/receive from a queue, you need to write that yourself. With WCF
Queuing however, you can easily enable message level security, ensuring all data is encrypted, even when in
MSMQ’s store or traverses multiple hops. You can also decorate your
business operations to declare which user groups/roles are allowed to invoke
them.
|
Your only hosting option is to write your own
service/executable.
|
Host your service in a custom service/executable or let IIS
host it for you.
|
Need your application available all the time but still want to utilize
resources efficiently? Want your app to recover when it encounters a
critical failure? Host your service in IIS via Web Hosting and it will get activated when messages arrive in your queue and
will be recycled if it encounters a failure (configurable of course).
|
Enables you to write your own poison message handling
(but only if you’re down with PInvoking the MSMQ C API).
|
Provides poison message handling for free.
|
Ever had a message in stuck in a queue that you couldn’t process and
had to build some complex retry/reject logic in your app to accommodate
it? Or, worse yet, do you search for messages to receive from a queue
to avoid this problem altogether? If so, WCF Queuing supports poison message handling out of the box — a huge win in the fight
for robust distributed applications and against using a transport mechanism
as a data store.
|
Enables you to write your own message correlation
logic.
|
Provides message correlation for free.
|
So you’ve got a group of messages you want processed together or by
the same receiver? With SM, you’ve got access to a message’s
correlation ID but of course it’s up to you to do the correlating. With
WCF Queuing, you can group your messages in sessions and WCF will ensure those messages are
processed together.
|
Enables you to write your own transactional batching
logic.
|
Provides transactional batching for free.
|
Want performance and transactional reads? Batch your
reads together in large transactions and only abort in the relative few
instances you need to. Of course you’ll need to write that logic
yourself as well as the retry mechanism and make it configurable for tuning
purposes if you use SM. WCF on the other hand supports transactional batching and its configuration out of the box.
|
Can create, delete, and generally
manage MSMQ queues.
|
Cannot create, delete or manage
queues.
|
*WCF Queuing can’t do everything SM can do; you still want to use it
to create and manage your queues. So arguably you want to use WCF
Queuing with SM, as opposed to instead of, but
for the actual transmission of data, WCF is clearly the way to go.
|
7.
Problem with
MSMQ in real life:
Microsoft Message Queuing (MSMQ) is
powerful solution for asynchronous applications. However, things don't look so
good when MSMQ must be managed - supplied MSMQ management console (MMC) does
not cover many real life situations.
- I. Poison Messages
- II. Queued Components Messages
- III. Backup and restore MSMQ messages
- IV. Need to manage remote queues. – can’t be done by MMC.