MessageQueue a simple Create and read

Source: Internet
Author: User

Create a queue and write the data

In the read out

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.messaging;usingSystem.Text;usingSystem.Threading.Tasks;namespaceQueue {classProgram {Static voidMain (string[] args) {            //Send to queue//determine if this queue exists (if it is created or does not exist, the new queue will be an error)            if(! Messagequeue.exists (". \\Private$\\MQDemo")) {//creates a queue at the specified locationMessageQueue Mynewprivatequeue =Messagequeue.create (". \\Private$\\TestPQueue"); } MessageQueue mqueue=NewMessageQueue (". \\private$\\MQDemo"); //create an entity for a messageSystem.Messaging.Message MSG =NewSystem.Messaging.Message (); //Assigning a value to the entity of a messageMsg.body ="QQQQQQQQQ"; Msg.formatter=NewSystem.Messaging.XmlMessageFormatter (NewType[] {typeof(string) }); //Send to Message queuemqueue.send (MSG); //--------------------------------------------------------            //reads data from the specified queue//Link this queueMessageQueue MQueue22 =NewMessageQueue (". \\private$\\MQDemo"); //get the first piece of data in the queue (the data pops up and disappears when it pops up)System.Messaging.Message Msg22 =mqueue22.receive (); //Deserialization of the messageMsg22.formatter =NewSystem.Messaging.XmlMessageFormatter (NewType[] {typeof(string) });            Console.WriteLine (Msg22.Body.ToString ()); ///MessageQueue queues can be cross-process, so the above code can be placed in two general handlers respectively///one to read///a fetchConsole.ReadLine (); }    }}

MessageQueue a simple Create and read

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.