热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

rabbitmq实战(五)——RabbitMQ集群(镜像集群)

可查看rabbitmq官方集群方案架构图Thisguidecoversmirroring(queuecontentsreplication)ofclassicqueues--摘自

可查看 rabbitmq官方集群方案

架构图


This guide covers mirroring (queue contents replication) of classic queues --摘自官网

By default, contents of a queue within a RabbitMQ cluster are located on a single node (the node on which the queue was declared). This is in contrast to exchanges and bindings, which can always be considered to be on all nodes. Queues can optionally be made mirrored across multiple nodes. --摘自官网

镜像队列机制就是将队列在三个节点之间设置主从关系,消息会在三个节点之间进行自动同步,且如果其中一个节点不可用,并不会导致消息丢失或服务不可用的情况,提升MQ集群的整体高可用性。

在这里插入图片描述

集群类型:


  1. 主从副本集群
  2. 镜像集群(常用)

上一章已经介绍主从副本集群

点击可查看: rabbitmq实战(十)——RabbitMQ集群(主从副本集群)

本章介绍一下常用的镜像集群


镜像集群是基于主从副本集群的

# 0.策略说明rabbitmqctl set_policy [-p <vhost>] [--priority <priority>] [--apply-to <apply-to>] <name> <pattern> <definition>-p Vhost&#xff1a; 可选参数&#xff0c;针对指定vhost下的queue进行设置Name: policy的名称Pattern: queue的匹配模式(正则表达式)Definition&#xff1a;镜像定义&#xff0c;包括三个部分ha-mode, ha-params, ha-sync-modeha-mode:指明镜像队列的模式&#xff0c;有效值为 all/exactly/nodesall&#xff1a;表示在集群中所有的节点上进行镜像exactly&#xff1a;表示在指定个数的节点上进行镜像&#xff0c;节点的个数由ha-params指定nodes&#xff1a;表示在指定的节点上进行镜像&#xff0c;节点名称通过ha-params指定ha-params&#xff1a;ha-mode模式需要用到的参数ha-sync-mode&#xff1a;进行队列中消息的同步方式&#xff0c;有效值为automatic和manualpriority&#xff1a;可选参数&#xff0c;policy的优先级# 1.查看当前策略rabbitmqctl list_policies# 2.添加策略rabbitmqctl set_policy ha-all &#39;^hello&#39; &#39;{"ha-mode":"all","ha-sync-mode":"automatic"}&#39; 说明:策略正则表达式为 “^” 表示所有匹配所有队列名称 ^hello:匹配hello开头队列# 3.删除策略rabbitmqctl clear_policy ha-all# 4.测试集群

我们在node1上用命令执行&#xff0c;可以看到node2上同步了策略

在这里插入图片描述


推荐阅读
author-avatar
博饼薄饼
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有