RabbitMQ EASYNETQ Usage

Source: Internet
Author: User
Tags rabbitmq

EASYNETQ Help Class

public class Mqhelper {//<summary>////</summary> public static Voi            D Publish (Message msg) {////Creates a message bus IBus bus = Busbuilder.createmessagebus (); try {Bus. Publish (msg, x = X.withtopic (msg).            Messagerouter)); } catch (Easynetqexception ex) {System.Console.WriteLine ("Send message:" + ex.)                Message); Handle connection message Server exception} bus.        Dispose ();//Similar to database connection, remember to destroy bus objects after use}///<summary>///Receive messages//</summary>        <param name= "MSG" ></param> public static void Subscribe (Message msg, iprocessmessage ipro)            {////Create message bus IBus bus = Busbuilder.createmessagebus (); try {Bus. Subscribe<message> (Msg. Messagerouter, message = ipro. PROCESSMSG (message), x = X.withtopic (Msg.                Messagerouter));            System.Console.WriteLine ("Subscription message success"); } catch (Easynetqexception ex) {System.Console.WriteLine ("subscription message failed:" + ex.            Message); }//Similar to database connection, remember to destroy bus objects after use}}

public class Busbuilder    {public        static IBus Createmessagebus ()        {            //Message server connection string            var connectionString = configurationmanager.connectionstrings["RabbitMQ"];            if (connectionString = = NULL | | connectionstring.connectionstring = = string. Empty)            {                throw new Exception ("Messageserver connection string is missing or empty");            }            Return Rabbithutch.createbus (connectionstring.connectionstring);        }             }

    Public interface iprocessmessage    {        void processmsg (Message msg);        void Notice ();    }

    public class Message    {public        string MessageID {get; set;}        public string MessageTitle {get; set;}        public string MessageBody {get; set;}        public string Messagerouter {get; set;}    }

RabbitMQ EASYNETQ Usage

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.