RabbitMQ C # example-excerpt from the Web

Source: Internet
Author: User
Tags rabbitmq

  Just contact, if there is not the right to the public static void StartUp () {#region preparatory work connectionfactory F            Actory = new ConnectionFactory (); Factory.            Uri = "amqp://guest:[email protected]:5672/"; Frame the physical link iconnection conn = factory.            CreateConnection (); Create communication channel IModel CHANNEL = conn.             Createmodel ();            String exchangename = "I am the route 1 that is responsible for forwarding the signal";            String queuename = "I am the receiver of the signal 1"; Set up signals to route the channel.            Exchangedeclare (Exchangename, exchangetype.direct); Set up a signal receiver channel.            Queuedeclare (QueueName, False, False, false, NULL); Communicates the signal router and receiver channel.             Queuebind (QueueName, Exchangename, "", null);            #endregion byte[] messagebodybytes = System.Text.Encoding.UTF8.GetBytes ("Hello, world!"); Channel.            Basicpublish (Exchangename, "", null,messagebodybytes); Ibasicproperties props = Channel.      Createbasicproperties ();      Props.            ContentType = "Text/plain"; Props.            DeliveryMode = 2; Channel.              Basicpublish (Exchangename, "", props,messagebodybytes);             ConnectionFactory service = new ConnectionFactory (); using (conn = service. CreateConnection ()) {using (IModel SERVICECHANNLE = conn. Createmodel ()) {//ch.                    Queuedeclare (QueueName, False, False, false, NULL);                    The server receives Message Queuing bool Noack = false; Basicgetresult result = Servicechannle.                    Basicget (QueueName, Noack);                    if (result = = null) {Console.WriteLine ("no Message"); } else {Servicechannle. Basicack (result.                        Deliverytag, false); Console.WriteLine ("Receive Message succeeded:" + result.)                        Basicproperties.contenttype); Console.WriteLine ("Receive Message succeeded:" + result.) BasIcproperties.deliverymode); Console.WriteLine ("Receive Message succeeded:" + System.Text.Encoding.Default.GetString (Result).                    Body)); }}} conn.        AutoClose = true; }

  

RabbitMQ C # example-excerpt from the Web

Related Article

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.