Skip to main content

Past Blast

Featured Products

Windows Mobile Developer Controls
Windows Mobile Developer Controls
Stay in touch using the DEVBUSS RSS feeds.
 

News

Windows Mobile Developer Controls
Sapphire Soltuions

Designing an MSMQ Console Application - Part 1 of 2

Written by Brent Pinkley  [author's bio]  [read 43090 times]
Edited by Derek

Download the code

Page 1  Page 2  Page 3 

Just like our mailbox analogy, you do not have to be constantly waiting for a message to receive your messages. Whenever you are ready, you can retrieve any messages that have been sent to you and send out any messages you have been saving up.

Therefore, the first step in creating a functional MSMQ app is to understand how to create and work with both queues and messages. If you have not already done so, you will want to install Ken Rabold's MSMQ control. This control provides the foundation for the MSMQ Console to work, and will allow you to see the console in action. Likewise, you will want to include the MSMQInc.bas file that he has provided, into any eVB project you create to handle all of the MSMQ constants. With that in place, creating a local queue is as simple as this:

' Instantiate the queue information
Set objInfo = CreateObject("CE_MSMQ.MSMQQueueInfo")

' Establish the path to the queue
objInfo.PathName = ".\Private$\PocketPC"

' Create the queue if it does not already exist
objInfo.Create

You will only be able to create local, private queues on the Pocket PC, but you may reference both local and remote queues for sending messages. To create a message and send it to our new queue, requires only a few lines as well:

' Open the actual queue
Set objQueue = objInfo.Open(MQ_SEND_ACCESS, _
MQ_DENY_NONE)

' Instantiate the message
Set objMsg = CreateObject("CE_MSMQ.MSMQMessage")

' Configure the message
objMsg.Label = "Test Message"
objMsg.Body = "This is a test message."

' Send the message to the opened queue
objMsg.Send objQueue

' Close the queue
objQueue.Close

Sending a message to a remote queue follows the same process, but it requires some up-front configuration. You need to setup a reference to the remote server in the Pocket PC's host file, since MSMQ does not support the use of an Internet Protocol (IP) address in a queue's PathName. You can use Marc Zimmerman's Pocket Hosts utility, to cross-reference the server name and IP address in the host's file.

If you want to be fancy about how you work with messages you can specify such options as a journal, or a copy of your message that is maintained or sent to a deadletter queue when non-deliverable. You can also have acknowledgement messages sent to an administration queue when key events occur in the life of the message. This all comes back to accountability for delivery of the message.

As a final piece of insurance, you can also make the message transactional, which will guarantee a single delivery of the message to its target. For detailed information on any of these topics, I would suggest reading the Ken Rabold's eBook on the subject. It goes into detail on several of these topics and is a great read for those interested in developing their own MSMQ apps.

That said, you can add journaling to your messages like so:

' Send copy to journal queue
' and undeliverable to deadletter queue
objMsg.Journal = MQMSG_JOURNAL Or _
MQMSG_DEADLETTER

Likewise, you can arrange for administrative notifications this way:

' Instantiate admin queue info
Set objAdmin = objInfo.Open(MQ_SEND_ACCESS, _
MQ_DENY_NONE)

' Request an acknowledgement for the message
objMsg.Ack = MQMSG_ACKNOWLEDGEMENT_FULL_REACH_QUEUE _
Or MQMSG_ACKNOWLEDGEMENT_FULL_RECEIVE

' Specify the administrative queue
Set objMsg.AdminQueueInfo = objAdmin

These are just additional properties of a message, with the rest of the process for sending a message being the same as described earlier. Going back to the mailbox analogy, these options would be comparable to the use of registered mail as an acknowledgement, and a signature request for a transactional message.

Previous Page  Next Page