RabbitMQ Concept and Environment Construction (iv) RabbitMQ high availability

Source: Internet
Author: User
Tags rabbitmq

####################################################
RabbitMQ High Availability
####################################################
1. Highly Available queue
By default, queues in RABBITMQ cluster are located in separate nodes (queues nodes that are first declared), while exchanges and bindings exist in cluster nodes. Therefore, each node failure exchanges and bindings have no effect, burliness queues node failure will affect the existence of queues on the node. But. Queues can be mirrored on multiple nodes. Each mirrored queue contains one master and one or more slave. Wakahara Master fails the oldest slave is promoted to the new master.

The Publish to queue message is copied to each slave, consumers regardless of which node connection from cluster is connected to master, and slave is discarded for a message that has been acknowledged from master. Therefore, queue mirroring only enhances usability. Does not balance the load between the nodes.

This scenario requires RABBITMQ cluster, which is no longer cluster within the network partitions and is therefore not recommended for use in the WAN, only for LANs.

2. Configure mirroring
With policy, you can change at any time, changing the non-mirrored queue to mirrored queue, or vice versa. It is important to note that the non-mirrored queue is not the same as the queue without slave mirrore, which requires no additional mirroring architecture to run faster.
The Available policy
Ha-mode ha-params Behavior
The all queue is mirror to all nodes in cluster.
A new node is added to the cluster, and the queue is mirror to that node.
Exactly count queue is mirror to a specified number of nodes.
If count is greater than cluster, the queue is mirror to all nodes.
If count is less than the number of nodes in cluster, no new mirror will be built on the other node after a node with mirror is down (to avoid cluster queue migrating)
The Nodes node names queue is mirror to the nodes of the specified name.
Any name that does not exist in cluster does not raise an error.
If any of the specified nodes are not in the queue declaration, the queue is created on the node to which it is connected.

About the nodes type policy
setting or changing the policy for the nodes type may cause the original master to migrate. For example, when the original master does not appear in the new Lolicy node list. RABBITMQ's strategy is to maintain the original master until at least one new slave is synchronized, and the original master is automatically invalidated once it is synchronized. The original consumer connection is broken and needs to be re-connected.
For example, the original queue in node {A,b},a is master. To a new policy{c,d}, there will be a period of state {A,c,d}, after queue synchronization, the master on a is closed, the new mirror is {c,d}

Special Queue:exclusivequeues
Exclusive queues will not be mirrored (mirror) and will not be persisted (durable), even if it is declared as such. Because the node that holds the queue is down, the connection to the top will also be broken, and the queue associated with exclusive queues will be deleted immediately.

3. Image configuration Example (available in several ways)
The following example will "ha." Start of queue mirror to all nodes in cluster
Rabbitmqctl rabbitmqctl set_policy ha-all "^ha\." ' {' Ha-mode ': ' All '} '
HTTP API Put/api/policies/%2f/ha-all {"pattern": "^ha\.", "definition": {"Ha-mode": "All"}}
Web UI Navigate to Admin > Policies > Add/update a policy.
Enter ' Ha-all ' next to Name, ' ^ha\. ' next to Pattern, and ' ha-mode ' = ' all ' in the ' first line ' next to Policy.
Click ADD Policy.

The following example will "two." Queue Mirror starts with two nodes in cluster and is automatically synchronized
Rabbitmqctl rabbitmqctl set_policy ha-two "^two\." ' {' Ha-mode ': ' Exactly ', ' ha-params ': 2, ' ha-sync-mode ': ' Automatic '} '
HTTP API put/api/policies/%2f/ha-two {"pattern": "^two\.", "definition": {"Ha-mode": "Exactly", "Ha-params": 2, " Ha-sync-mode ":" Automatic "}}
Web UI Navigate to Admin > Policies > Add/update a policy.
Enter "Ha-two" next to Name and "^two\." Next to Pattern.
Enter "Ha-mode" = "exactly" in the first line next to Policy and then "ha-params" = 2 in the second line and then "Ha-sync-mode" = "Automatic" in the third, and sets the type on the second line to "number".
Click ADD Policy.


The following example will "nodes." The open queue mirror to the specific node in cluster
Rabbitmqctl rabbitmqctl set_policy ha-nodes "^nodes\." ' {"Ha-mode": "Nodes", "Ha-params": ["NodeA", "NodeB"]} '
HTTP API put/api/policies/%2f/ha-nodes {"pattern": "^nodes\.", "definition": {"Ha-mode": "Nodes", "Ha-params": ["NodeA" , "NodeB"]}
Web UI Navigate to Admin > Policies > Add/update a policy.
Enter "Ha-nodes" next to Name and "^nodes\." Next to Pattern.
Enter "Ha-mode" = "nodes" in the first line next to Policy, then "Ha-params" on the second line, set the second line ' s Typ E to ' List ', and then enter ' NodeA ' and ' NodeB ' in the sublist which appears.
Click ADD Policy.

4. Other precautions

Reference:
Http://www.rabbitmq.com/ha.html

RabbitMQ Concept and Environment Construction (iv) RabbitMQ high availability

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.