1. RabbitMQ
MQ is all called the message queue, and Message Queuing (MQ) is an application-to-application communication method. Applications communicate by writing and retrieving data (messages) for applications that enter and leave the queue, without requiring a private connection to link them. Message passing refers to the process of communicating between programs by sending data in a message, rather than by directly invoking each other, and directly invoking techniques such as remote procedure calls. Queuing refers to an application communicating through a queue. The use of queues removes the requirement that both the receiving and sending applications execute concurrently. Some of the more mature MQ products are MSMQ,ACTIVEMQ,RABBITMQ,IBM WEBSPHERE MQ and so on.
RABBITMQ is a full, reusable enterprise messaging system developed using Erlang, an open source, based on the Advanced Message Queuing Protocol (AMQP). He follows the Mozilla Public License open source agreement.
RABBITMQ supports most of the development languages you can think of such as Java,ruby,python,.net,c/c++,erlang and so on. Clients of various languages you can download from its official website.
2. Some concepts of RABBITMQ
-Connection (Connection), a connection established with RABBITMQ server, created by ConnectionFactory, Each Connection is connected to only one physical server, which is connected based on the socket, which can be similarly understood as a DB Connection. AMQP generally uses TCP links to guarantee the reliability of message transmission.
-channels (channel), in C # Client should be called model, other clients are basically called Channel. A channel built on connection, which is lightweight relative to connection. It's like a session in Hibernate. Channel is mainly related to definition, sending messages, getting messages, transaction processing and so on. The channel can be used in multiple threads, but only one thread must be guaranteed to execute the command at any time. A connection can have multiple channel. The client program is sometimes a multithreaded program, each thread wants to connect with RABBITMQ, but do not want to share a connection, this demand is still more common. Because a connection is a TCP link, RABBITMQ does not want to maintain multiple TCP connections with each client at design time, but this is really a requirement for some clients, so the concept of channel is introduced in the design and there is no link between each channel , is completely detached. Multiple channel to share a connection.
-Exchanger (Exchange), which is the entity that sends the message.
-Queue, which is the entity that receives the message.
-The Binder (BIND), which connects the exchanger and the queue, and encapsulates the routing information for the message.
3. Resource Files
4. Send a message
1 /// <summary>2 /// </summary>3 /// <param name= "DeptID" >Department ID</param>4 /// <param name= "Usercode" >User name</param> 5 /// <returns></returns>6 [Generated]7 protected OverrideString SENDMQ (LongDeptID,stringUsercode,stringClientIP)8 {9 varFactory =Newconnectionfactory ();TenFactory. HostName ="182.94.73.104";//MQ server-side IP OneFactory. Port =15673;//MQ Service-Side ports AFactory. UserName ="Login_mq_user"; -Factory. Password ="[email protected]"; - //Factory. HostName = "localhost"; the //Factory. UserName = "yy"; - //Factory. Password = "hello!"; - - + stringTicket = System.Guid.NewGuid (). ToString ();//the token parameter in the corresponding URL - + //Mqinfopoco mqobj = new Mqinfopoco (); A //mqobj.clientip = ClientIP; at //mqobj.section = DeptID; - //Mqobj.userid = Usercode; - //mqobj.logintime = Gettimestamp (); - //mqobj.timelive = 480; - //Mqobj.token = ticket; - varLogintime =Gettimestamp (); in - using(varConnection =Factory. CreateConnection ()) to { + using(varChannel =connection. Createmodel ()) - { theChannel. Queuedeclare ("Login_queue",false,false,false,NULL);//MQ queue name Login_queue * //String message = Objecttojson (mqobj); $StringBuilder message =NewStringBuilder (@"{"ClientIP " "":");Panax NotoginsengMessage. AppendFormat ("\ "{0}\"", ClientIP); -Message. AppendFormat (", \ "section\": \ "{0}\"", DeptID); theMessage. AppendFormat (", \ "userid\": \ "{0}\"", usercode); + //message. Append (", \" userid\ ": \" hxj\ ""); AMessage. AppendFormat (", \ "logintime\": {0}", logintime); theMessage. Append (", \ "timelive\": 480"); +Message. AppendFormat (", \ "token\": \ "{0}\"", ticket); -Message. Append ("}"); $ $ varProperties =Channel. Createbasicproperties (); -Properties. Setpersistent (true); - varBODY =Encoding.UTF8.GetBytes (message. ToString ()); theChannel. Basicpublish ("","Login_queue", properties, body); - }Wuyi } the - returnticket; Wu}
C # using RabbitMQ