We know rabbitmq It's a professional MQ product , And it's also a strict adherence to AMQP Protocol stuff , But to be coquettish , There must be something highly available , I'm going to tell you

once cluster The concept of ,rabbitmq yes erlang A finished product , So know how to build erlang Of node Cluster is ok 了 , He needs a unified cookie Mechanism ... The test environment of this article is as follows :



The screenshot is as follows :

One :cookie Mechanism

I just said , If you want to achieve cluster colony , It is necessary to ensure that all machines are equipped with cookie The content of the document is the same , That's the question ...cookie Where to? ? from rabbitmq You can find this on our website

In a word , Here's the picture :

ok, The official website is very clear , Now let's take a look at $HOME Where does the variable point to ...

[root@rabbitmq1 Desktop]# echo $HOME
[root@rabbitmq1 Desktop]#

Then I'll go and have a look (Centos1 .147) This is the best one /root Can I find , Here's the picture :

It's amazing , Hey , Now what we're going to do , Is to put Centos2 Of cookie Replace the contents of the file with Centos1 Of cookie Content .

Two : Use host mapping erlang node

Now? cookie The value is the same , Then it needs to be in /etc/hosts Add in host reference , convenient erlang Nodes discover each other , And then there's the 2 platform centos Add the same host Address :

3、 ... and :rabbitmqctl cluster command

Okay , We're all ready , You can restart the machine , Open our rabbitmq, There will be a surprise at this time ...

From the original localhost Change to the present rabbitmq2 了 , See? ~~~ Next, you can put two rabbitmq Open the .

1. stay centos1 Upper use rabbitmqctl cluster_status Look at the current state of the cluster

[root@rabbitmq1 Desktop]# rabbitmqctl cluster_status
Cluster status of node rabbit@rabbitmq1 ...
[root@rabbitmq1 Desktop]#

You can see , Current running-nodes There's only one of them , It just happens to be this machine erlang Node itself , Next let's see if we can connect to rabbit@rabbitmq2 Up ...

2. join_cluster command

Before this order , You need to transfer the rabbitmq close , Then proceed join operation , As you can see from the following figure , We've connected to centos2 Upper rabbitmq 了 ...

[root@rabbitmq1 Desktop]# rabbitmqctl stop_app
Stopping node rabbit@rabbitmq1 ...
[root@rabbitmq1 Desktop]# rabbitmqctl join_cluster rabbit@rabbitmq2
Clustering node rabbit@rabbitmq1 with rabbit@rabbitmq2 ...
[root@rabbitmq1 Desktop]# rabbitmqctl start_app
Starting node rabbit@rabbitmq1 ...
[root@rabbitmq1 Desktop]#

3. Use webui Take a look at the final effect

See no , Now our rabbitmq The cluster has been built successfully , If you have more machines , You can use this join Order to join , Very simple. ~~~

Four :mirror queue

As can be seen from the name , It means mirror queue , in other words queue It's synchronized across our machines , It can also be set in a simple way , Only need webui Of policy It can be set above ...

This setting indicates that if it is mytest The beginning of the queue is “ Image queue ”, Of course, it can also be implemented in code , And realize the function of automatic synchronization , as follows :

rabbitmqctl set_policy ha-all "^mytest" '{"ha-mode":"all","ha-sync-mode":"automatic"}'

5、 ... and : Use C# Drive connection

No matter how good cluster Finally, we need to use language driven connection , Only in this way can we really land , The driver I chose was official , You can nuget Download it from above :

Next I need to demonstrate to queue=mytest1 Push data in the queue , The highlight is that I'm CreateConnection The method is crammed with multiple ip Address ... The following code :

 class Program
static void Main(string[] args)
ConnectionFactory factory = new ConnectionFactory()
UserName = "datamip",
Password = "datamip",
AutomaticRecoveryEnabled = true,
TopologyRecoveryEnabled = true
}; // First step : establish connection
var connection = factory.CreateConnection(new string[] { "", "" }); // The second step : Create a channel
var channel = connection.CreateModel(); var result = channel.QueueDeclare("mytest1", true, false, false, null); for (int i = ; i < int.MaxValue; i++)
channel.BasicPublish(string.Empty, "mytest1", null, new byte[]); Console.WriteLine("{0} Push successful ", i);
} Console.Read();

Finally, let's take a look webui, You can see clearly that the news has entered rabbitmq Cluster ...

Okay , So much for this article , I hope it will help you ~~~

Build highly available rabbitmq colony + Mirror Queue + Use C# More articles about driving connections

  1. Fast grasp RabbitMQ( 5、 ... and )—— Build highly available RabbitMQ colony

    RabbitMQ Cluster is dependent on erlang Clustered , and erlang Clustering is through .erlang.cookie File for communication authentication , So we use RabbitMQ When clustering, you only need to configure .erlang.cookie file ...

  2. rabbitmq colony + Mirror Queue + Use C#

    Build highly available rabbitmq colony + Mirror Queue + Use C# Drive connection We know rabbitmq It's a professional MQ product , And it's also a strict adherence to AMQP Protocol stuff , But to be coquettish , You have to come up with high ...

  3. keepalived Working principle and configuration description Tencent cloud VPC Pass inside keepalived Build a high availability primary and standby cluster

    keepalived Working principle and configuration description Tencent cloud VPC Pass inside keepalived Build a high availability primary and standby cluster All intranet routes use mac Address One mac Address binding multiple ip There can only be one network card mac Address , and mac The address can't be changed , but ...

  4. Build highly available redis colony , avoid standalone The suffering of patterns

    Now it's used in the project redis Words , It is rarely said that there is no cluster , After all, if there's only one in production redis There will be great risks , For example, if the machine fails , Or the memory goes out , Like our production environment This has happened to me , Lead to redis There is not enough memory to hang up ...

  5. Build highly available MongoDB colony

    http://www.csdn.net/article/2014-04-09/2819221-build-high-avialable-mongodb-cluster-part-1/1 In the era of big data ...

  6. Redis Cluster Build high availability Redis Server cluster

    One .Redis Cluster Introduction of the cluster Redis Cluster yes Redis Officially available distributed solution , stay 3.0 Version after the release , Effectively solved Redis Distributed requirements , When a node is down, you can quickly switch to another node ...

  7. Manually build highly available kubernetes colony

    Before the deployment step by step with me kubernetes Step by step, the cluster is successfully installed in binary mode kubernetes colony , Based on this document, the latest v1.8.2 edition , Realized kube-apiserv ...

  8. Redis summary ( 8、 ... and ) How to build highly available Redis colony

    I used to summarize Redis Some basic installation and use of , You can check it here Redis Series articles :https://www.cnblogs.com/zhangweizhong/category/771056.html ...

  9. MyCAT+MySQL Build a high availability enterprise database cluster video course

    Original address :https://www.guangboyuan.cn/mycatmysql%E6%90%AD%E5%BB%BA%E9%AB%98%E5%8F%AF%E7%94%A8%E4%BC%81%E4% ...

Random recommendation

  1. iOS----- The basic syntax of regular expressions

    Regular expression simple syntax summary One . What is regular expression Conceptually speaking , Regular expressions are also a small and refined language , It can be used to simplify retrieving specific strings , Replace specific characters and other functions , There are many development language tools , Support for regular expressions . So a positive ...

  2. T-SQL Recipes And Separating elements

    Separating elements Separating elements is a classic T-SQL challenge. It involves a table called Arr ...

  3. Solve click cell when ,UILabel The problem of the background color disappearing

    -(void)setSelected:(BOOL)selected animated:(BOOL)animated{ [super setSelected:selected animated:anim ...

  4. Use Quartz.net Dynamic setting timing time problem

    About use Quartz.net There's no need to explain .. In response to customer needs .. Need to do an interface to set the timing time . So I'm at Baidu .. use CronExpression Class can set the time ... I know that this class has well-defined fields .. No ...

  5. [LintCode] Length of Last Word Find the length of the last word

    Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...

  6. C# change win7 Code for system time , And why the change didn't work

    I am using C# change win7 The time of the system ( You must use the administrator's permission , Click to run the program , Right mouse button “ Run with administrator privileges ”), The following is listed 3 A picture , The code execution using the first one was unsuccessful , Use the second picture to perform successfully , The third picture is to explain why ...

  7. linux add to somebody To group

    add to xiluhua To group :test_group usermod -a test_group  xiluhua

  8. UVALive 5713 Qin Shi Huang&#39;s National Road System Qin Shihuang built roads (MST, The least bottleneck )

    The question : Qin Shihuang will be in n Building roads between two cities , And Xu Fusheng can use magic to repair the first emperor of Qin for free 1 Strip road , Each city has its own population , Now, the sum of the population of the two cities where Xu Fusheng built the road A As big as possible , And make n There is a long road to be built between two cities B Try to be as short as possible , Thus making A/B most ...

  9. Linux VIM python Auto completion plug-in :pydiction

    Pydiction It can be used by us Tab Key auto completion Python Code in Vim, Is a very good plug-in . Pydiction No installation required , All without any dependency package problems ,Pydiction It mainly contains three files . pyth ...

  10. RabbitMQ Study -1

    Reprinted from :http://blog.csdn.net/anzhsoft/article/details/19563091. 1. history RabbitMQ It's a by erlang Developed AMQP(Advanced ...