Skip to Main Content
C# Cookbook, 2nd Edition
book

C# Cookbook, 2nd Edition

by Jay Hilyard, Stephen Teilhet
January 2006
Intermediate to advanced content levelIntermediate to advanced
1184 pages
43h 23m
English
O'Reilly Media, Inc.
Content preview from C# Cookbook, 2nd Edition
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Using Message Queues on a Local Workstation
|
1093
20.4 Using Message Queues on a Local Workstation
Problem
You need a way to disconnect two components of your application (like a web ser-
vice endpoint and processing logic) so that the first component has to worry about
only formatting the instructions and the bulk of the processing occurs in the second
component.
Solution
Use the MQWorker class shown here in both the first and second components to write
and read messages to and from a message queue.
MQWorker uses the local message-
queuing services to do this. The queue pathname is supplied in the constructor, and
the existence of the queue is checked in the
SetUpQueue method.
class MQWorker
{
private string _mqPathName;
MessageQueue _queue = null;
public MQWorker(string queuePathName)
{
if (string.IsNullOrEmpty(queuePathName)
throw new ArgumentNullException("queuePathName");
_mqPathName = queuePathName;
SetUpQueue( );
}
SetUpQueue creates a message queue of the supplied name using the MessageQueue
class if none exists. It accounts for the scenario in which the message-queuing ser-
vices are running on a workstation computer. In that situation, it makes the queue
private, as that is the only type of queue allowed on a workstation.
private void SetUpQueue( )
{
// See if the queue exists, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# Cookbook

C# Cookbook

Joe Mayo
C# Cookbook

C# Cookbook

Stephen Teilhet, Jay Hilyard
Head First C#, 4th Edition

Head First C#, 4th Edition

Andrew Stellman, Jennifer Greene

Publisher Resources

ISBN: 0596100639Supplemental ContentCatalog PageErrata