home *** CD-ROM | disk | FTP | other *** search
-
- <!-- #include virtual="/quickstart/howto/include/header.inc" -->
-
- <h4>How Do I...Receive a message from a message queue?</h4>
-
- <div class="indent" style="width:660">
- <p style="margin-right: 0; margin-top: 6; margin-bottom: 5"><font face="Tahoma" size="1">Message queuing makes
- it easy for application developers to communicate with application programs quickly and reliably by sending and
- receiving messages. Messaging provides you with guaranteed message delivery and a robust, fail-safe way to carry
- out many of your business processes.<br>
- <br>
- The MessageQueue component allows you to easily incorporate message-based communication into your applications.
- Using this component and its associated language features, you can send and receive messages, explore existing
- queues, create and delete queues, and perform a variety of other operations using a simple programming model.<br>
- <br>
- The sample illustrates how to use the MessageQueue component to receive a
- message from a message queue. To run the sample you have to have Message Queuing
- installed on your system. The sample is a command line application that takes
- one command line argument. The argument is the name of a public message queue on
- your local machine. For example you can run it as follows (first send a message
- to the queue using the MQSend sample):</font>
- <p style="margin-right: 0; margin-top: 6; margin-bottom: 5"><font face="Tahoma" size="1"><br>
- </font><font face="Courier New" size="2" color="#0000FF"> </font><font face="Tahoma" size="1">
- </font><font face="Courier New" size="2" color="#0000FF">> MQReceive.exe MyQueue</font><font face="Tahoma" size="1"><br>
- <br>
- The sample application will receive and output to the console the first message
- from the queue.<br>
- </font></p>
- <p style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; WORD-SPACING: 0px"><font face="Tahoma" size="1">In
- its simplest form, receiving a message from a message queue involves:</font></p>
- <p style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; WORD-SPACING: 0px"> </p>
- <p style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; WORD-SPACING: 0px"><font face="Tahoma" size="1">1.
- Creating an instance of the MessageQueue component and setting its Path
- property:</font></p>
- <p style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; WORD-SPACING: 0px"> </p>
- <blockquote>
- <p style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; WORD-SPACING: 0px"><font face="Courier New" color="#0000ff" size="2">MessageQueue
- mq = new MessageQueue(".\\MyQueue");</font></p>
- </blockquote>
- <p style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; WORD-SPACING: 0px"> </p>
- <p style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; WORD-SPACING: 0px"><font face="Tahoma" size="1">2.
- Calling Receive to receive the message:</font></p>
- <p style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; WORD-SPACING: 0px"> </p>
- <blockquote>
- <p style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; WORD-SPACING: 0px"><font face="Courier New" color="#0000ff" size="2">Message m = mq.Receive(1000);<br>
- Console.WriteLine((string)m.Body);</font></p>
- </blockquote>
- <p style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; WORD-SPACING: 0px"><font face="Tahoma" size="1">Have
- a good time MessageQueue'ing!</font>
- </div>
-
- <h4>Example</h4>
-
- <p>
- <div class="indent">
- <a target="_blank" href="/quickstart/howto/samples/Services/MessageQueue/MQReceive">
- <img style="border-color:black" border=1 src="/quickstart/images/genicon.gif"><br>
- </a>
- <div class="caption">MQReceive.exe</div><br>
- [<a target="_blank" href="/quickstart/howto/samples/Services/MessageQueue/MQReceive">View Sample</a>] |
- [<a target="_blank" href="/quickstart/util/srcview.aspx?path=/quickstart/howto/samples/Services/MessageQueue/MQReceive/MQReceive.src">View Source</a>]<p>
- </div>
-
- <h4>Source Code</h4>
-
- <div class="code">
- <xmp>
- <!-- #include virtual="/quickstart/howto/samples/Services/MessageQueue/MQReceive/MQReceive.cs" -->
- </xmp>
- </div>
-
- <!-- #include virtual="/quickstart/howto/include/footer.inc" -->