First, the concept
AMQP, Advanced message Queuing Protocol, is an open standard for application-layer protocols designed for message-oriented middleware. Message middleware is mainly used for decoupling between components, the sender of the message does not need to know the existence of the message consumer, and vice versa.
The main features of AMQP are message-oriented, queue, routing (including point-to-point and publish/subscribe), reliability, and security.
RABBITMQ is an open-source AMQP implementation that is written in Erlang and supported by a variety of clients such as Python, Ruby,. NET, Java, JMS, C, PHP, ActionScript, XMPP, stomp, etc., and support Ajax. It is used to store and forward messages in distributed system, which is very good in ease of use, extensibility, high availability and so on. (A lot of information on the Internet, people can see for themselves)
Second, Linux installation RABBITMQ (based on CentOS7)
1. Erlang Installation
RPM-UVH Http://download.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-9.noarch.rpmyum Install Erlang
2, Installation RABBITMQ
wget Http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.8/rabbitmq-server-3.6.8-1.el7.noarch.rpmyum Install RABBITMQ-SERVER-3.6.6-1.EL7.NOARCH.RPM Service Rabbitmq-server Start
3. Configuring the RABBITMQ configuration file
Initial setup requires you to create your own configuration file
Cd/etc/rabbitmq/vim Rabbitmq.config
Write the following content:
[{rabbit, [{loopback_users, []}]}].
So that you can use the remote access to the guest, more detailed information, everyone's own Baidu Baidu, how can not access the words, you may try to shut down the firewall and try again
4. Open the Admin UI
Rabbitmq-plugins Enable Rabbitmq_management
After opening, visit the following address:
http://192.168.10.97:15672/#/
With this UI tool you can better manage RABBITMQ
Three. NET under development RABBITMQ
1. Configure Exchange and queue
Create a new Exchange as follows:
Create a new queue, as shown below;
To create the correspondence between Exchange and the queue:
2. Receive-Side code
private void Form2_load (object sender, EventArgs e) { var factory = new ConnectionFactory (); Factory. UserName = "Guest"; Factory. Password = "Guest"; Factory. HostName = "192.168.10.97"; Factory. Automaticrecoveryenabled = true; var connection = factory. CreateConnection (); var channel = connection. Createmodel (); var consumer = new RabbitMQ.Client.Events.EventingBasicConsumer (channel); Consumer. Consumertag = "11111111111"; Consumer. Received + = consumer_received; Channel. Basicconsume (queue: "Hello", noack:true, consumer:consumer); } private void Consumer_received (object sender, RabbitMQ.Client.Events.BasicDeliverEventArgs e) { MessageBox.Show (Encoding.UTF8.GetString (e.body)); }
PS: Special note that the automaticrecoveryenabled tree must be set to true, otherwise it will not receive data again after receiving the data again (by this pit for one day)
3. Send-side code
private void Button1_Click (object sender, EventArgs e) { var factory = new ConnectionFactory (); Factory. UserName = "Guest"; Factory. Password = "Guest"; Factory. HostName = "192.168.10.97"; using (var connection = factory. CreateConnection ()) { using (var channel = connection. Createmodel ()) { channel. Basicpublish ("Hello_e", "Hello", NULL, Encoding.UTF8.GetBytes (DateTime.Now.ToString ()));}}}
4. Program Operation effect
Click the button, pop up the MessageBox, to prove that the data monitor heard, some time there is a delay of a few seconds, but its own asynchronous processing is mainly to ensure eventual consistency, so it doesn't matter
Source: Https://pan.baidu.com/s/1nvhp0MH
If some documents are infringing, please contact: 568898448
Reference Document: Installation process reference http://www.cnblogs.com/uptothesky/p/6094357.html
. NET under RABBITMQ Publish subscription model practice