471,570 Members | 1,007 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,570 software developers and data experts.

Monitoring a Messaging Queue

I am trying to use the Microsoft Messaging Queue for an application I am
writing. I am able to create, push and pull messages with this app. The
problem right now though is: my "pull / pop" of the messages is based upon a
click of a button by the user. What I would like to do is automate the
process in which when an item is entered in the queue: a process is called /
spawned to will handle the item. Or perhaps every couple seconds: check the
queue for items (get the count) and perform a loop until that count is 0.

I am unsure how to go about "automating" the pop / pull of hte messages.

Would anyone be able to give me some pointers or advice?

Thanks
Andy
Feb 9 '06 #1
1 2503
You never really automate the posting of a message, an action such as clicking the button or uploading a file nearly always fires the event / calls the code. Reading the queue, we've set up a windows service that creates an object containing the following code (note: I've removed / change certain bits have been removed to make it generic - but it should give you a good starting point). As the windows service starts ProcessMessageQueue on a separate thread, it carries on processing the queue until the flag is set to false (normally on shutting down the service).

public override void ProcessMessageQueue()
{
MyObject emptyObj = new MyObject()
while (flag) // Property of class, set to false by calling object to terminate processing queue
{
try
{
MyObject myObject;
myObject = (MyObject)GetMessage(emptyObj.GetType());
if (myObject != null)
ProcessMessage(myObject);
}
catch(Exception e)
{
LogError(e);
}
}
}

private object GetMessage(Type objectType)
{
MessageQueue msmqQueue;
if( MessageQueue.Exists( msgQueue))
msmqQueue = new MessageQueue( msgQueue);
else
msmqQueue = MessageQueue.Create( msgQueue);

msmqQueue.UseJournalQueue = true;

Type[] targetTypes = new Type[1];
targetTypes[0] = objectType;
msmqQueue.Formatter = new XmlMessageFormatter( targetTypes);

Message message;
try
{
message = msmqQueue.Receive(new TimeSpan(0,0,3));
return (object)message.Body;
}
catch (MessageQueueException e)
{
if (e.MessageQueueErrorCode == MessageQueueErrorCode.IOTimeout)
{
return null;
}
else
throw e;
}
}
"Andy" <An**@discussions.microsoft.com> wrote in message news:8E**********************************@microsof t.com...
I am trying to use the Microsoft Messaging Queue for an application I am
writing. I am able to create, push and pull messages with this app. The
problem right now though is: my "pull / pop" of the messages is based upon a
click of a button by the user. What I would like to do is automate the
process in which when an item is entered in the queue: a process is called /
spawned to will handle the item. Or perhaps every couple seconds: check the
queue for items (get the count) and perform a loop until that count is 0.

I am unsure how to go about "automating" the pop / pull of hte messages.

Would anyone be able to give me some pointers or advice?

Thanks
Andy

Feb 9 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Sarah Wang | last post: by
1 post views Thread by Peter Ang | last post: by
1 post views Thread by Hai Nguyen | last post: by
3 posts views Thread by Webbee | last post: by
7 posts views Thread by =?Utf-8?B?Q2FybG8gRm9saW5p?= | last post: by
5 posts views Thread by wink | last post: by
1 post views Thread by Craig Buchanan | last post: by
2 posts views Thread by mirin | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.