RabbitMQ Message Queuing

Source: Internet
Author: User
Tags rabbitmq

A: Introduction

RABBITMQ is an enterprise messaging system that is complete and can be taken on a standard based on the AMQP protocol. He follows the Mozilla Public License open source agreement. An industrial-grade Message Queuing (MQ) server implemented with Erlang.

Official station of RABBITMQ: http://www.rabbitmq.com/
AMQP (Advanced Message Queuing Protocol) is an application-layer protocol specification used by asynchronous messaging as a line-layer protocol, rather than an API (such as JMS), where AMQP clients can send and receive information regardless of the source of the message. The original purpose of AMQP is simply to provide the financial community with a message protocol that can collaborate with one another, and now the goal is to provide common building tools for the common Message Queuing architecture. Therefore, message-oriented middleware (MOM) systems, such as publish/subscribe queues, are not implemented as basic elements. Instead, by sending simplified AMQ entities, users are given the ability to build such entities. These entities are also part of the specification, forming a hierarchy at the top of the line layer protocol: the AMQP model. This model unifies the message pattern, such as the previously mentioned publish/subscribe, queue, transaction, and streaming data, and adds additional features such as easier to scale, content-based routing.

1. Download Erlang

Http://www.erlang.org/download.html

Choose from 32-bit and 64-bit versions, download the appropriate version according to your individual needs, and install Erlang first.

2. Download the RABBITMQ server installation file

Http://www.rabbitmq.com/install-windows.html

After installing the RABBITMQ server-side environment, the RABBITMQ will reside on the server as a service, which is enabled by default

http://localhost:15672, enter the user name in the login interface: Guest, Password: Guest, you can go to the management interface to view various information

Two: RabbitMQ Example

Send Message End

  class program    {        staticvoid Main (string[] args)        {            =new  Userhelp ();              while (true)            {                var result = mes.} Getusermessage ();                Console.WriteLine (result);     }}}

  Public stringGetusermessage () {Try            {                varConfactory =NewConnectionFactory (); Confactory.hostname="localhost"; Confactory.username="Wangdongsheng"; Confactory.password="123456"; Confactory.virtualhost="/"; using(varConnect =confactory.createconnection ()) {                    //RABBITMQ Service Side                    using(varChannel =Connect. Createmodel ()) {//defines a persistent queue on MQ, which is not created repeatedly if the same nameChannel. Queuedeclare ("Testqueue",true,false,false,NULL); // //Enter 1, and if you receive a message but no answer, the client will not receive the next messageChannel. Basicqos (0,1,false); //define a consumer on the queue                        varConsumer =NewQueueingbasicconsumer (channel); //consumption queue, and set the answer mode for the program to respond proactivelyChannel. Basicconsume ("Testqueue",false, consumer);  while(true)                        {                            //blocking functions to get messages in the queue                            varEA =(Basicdelivereventargs) consumer.                            Queue.dequeue (); byte[] bytes =ea.                            Body; stringstr =Encoding.UTF8.GetString (bytes); varmsg = jsonconvert.deserializeobject<requestmsg>(str); //Recovery ConfirmationChannel. Basicack (ea. Deliverytag,false); return "the data received:"+"Sending Person-"+msg. name+"; Send Content-"+Msg.                        Code; }                    }                }            }            Catch(Exception ex) {returnEx.            Message; }        }
    Public class requestmsg    {        publicstringgetset;}          Public string Get Set ; }    }

Receive Message End

 classProgram {Private Static voidMain (string[] args) {Sendhelp Help=NewSendhelp ();  while(true) {Console.WriteLine ("Please enter the content:"); varWrite =Console.ReadLine (); if(!string. Isnullorwhitespace (write)) {varresult =Help .                    SendMessage (write); Console.foregroundcolor=Consolecolor.darkyellow;                    Console.WriteLine (result); Console.foregroundcolor=Consolecolor.white;        }} console.readkey (); }    }
         Public stringSendMessage (stringmsg) {            Try            {                varConfactory =NewConnectionFactory (); Confactory.hostname="localhost"; Confactory.username="Wangdongsheng"; Confactory.password="123456"; Confactory.virtualhost="/"; using(Iconnection connect =confactory.createconnection ()) {                    //RABBITMQ Service Side                    using(varChannel =Connect. Createmodel ()) {//defines a persistent queue on MQ, which is not created repeatedly if the same nameChannel. Queuedeclare ("Testqueue",true,false,false,NULL);  while(true)                        {                            varRequetmsg =Newrequestmsg (); Requetmsg.name="Dongsheng"; Requetmsg.code=msg; stringJsonstr =Jsonconvert.serializeobject (requetmsg); byte[] bytes =Encoding.UTF8.GetBytes (JSONSTR); Ibasicproperties Pro=Channel.                            Createbasicproperties (); Pro. DeliveryMode=2; Channel. Basicpublish ("","Testqueue", Pro, bytes); return "Send Message Successful: Sender-"+requetmsg.name+"; message Content-"+Requetmsg.code; }                    }                }            }            Catch(Exception ex) {return "the message sent is:"+Ex.            Message; }        }

RabbitMQ Message Queuing

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.