ActiveMQ 07 集群配置

Active MQ 07

集群配置

官方文档

http://activemq.apache.org/clustering

主备集群

http://activemq.apache.org/masterslave.html

Master Slave TypeRequirementsProsCons
Shared File System Master SlaveA shared file system such as a SANRun as many slaves as required. Automatic recovery of old mastersRequires shared file system
JDBC Master SlaveA Shared databaseRun as many slaves as required. Automatic recovery of old mastersRequires a shared database. Also relatively slow as it cannot use the high performance journal
Replicated LevelDB StoreZooKeeper ServerRun as many slaves as required. Automatic recovery of old masters. Very fast.Requires a ZooKeeper server.
Shared File System Master Slave

基于共享存储的Master-Slave;多个broker共用同一数据源,谁拿到锁谁就是master,其他处于待启动状态,如果master挂掉了,某个抢到文件锁的slave变成master

启动后

在这里插入图片描述

Master宕机

在这里插入图片描述

Master重启

在这里插入图片描述

JDBC Master Slave

基于JDBC的Master-Slave:使用同一个数据库,拿到LOCK表的写锁的broker成为master.

性能较低,不能使用高性能日志

Replicated LeveDB Store

基于zookeeper复制LeveDB存储的Master-Slave机制

配置步骤

  1. 修改broker名称
  2. 修改数据源
    1. 如果使用kahadb,配置相同路径
    2. 如果使用mysql 使用同一数据源(同一数据库和表)

尝试

在这里插入图片描述

http://activemq.apache.org/failover-transport-reference.html

failover 故障转移协议

断线重连机制是ActiveMQ的高可用性具体体现之一。ActiveMQ提供failover机制去实现断线重连的高可用性,可以使得连接断开之后,不断的重试连接到一个或多个brokerURL。

默认情况下,如果client与broker直接的connection断开,则client会新起一个线程,不断的从url参数中获取一个url来重试连接。

配置语法

		ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("admin","admin","failover:(nio://localhost:5671,nio://localhost:5672)");

可配置选项

Transport Options
Option NameDefault ValueDescription
backupfalseInitialize and hold a second transport connection - to enable fast failover.
initialReconnectDelay10The delay (in ms) before the first reconnect attempt.
maxCacheSize131072Size in bytes for the cache of tracked messages. Applicable only if trackMessages is true.
maxReconnectAttempts`-10`
maxReconnectDelay30000The maximum delay (in ms) between the second and subsequent reconnect attempts.
nested.*nullFrom ActiveMQ 5.9: common URI options that will be applied to each URI in the list**.**
randomizetrueIf true, choose a URI at random from the list to use for reconnect.
reconnectDelayExponent2.0The exponent used during exponential back-off attempts.
reconnectSupportedtrueDetermines whether the client should respond to broker ConnectionControl events with a reconnect (see: rebalanceClusterClients).
startupMaxReconnectAttempts-1A value of -1 denotes that the number of connection attempts at startup should be unlimited. A value of >=0 denotes the number of reconnect attempts at startup that will be made after which an error is sent back to the client when the client makes a subsequent reconnect attempt. Note: once successfully connected the maxReconnectAttempts option prevails.
timeout-1From ActiveMQ 5.3: set the timeout on send operations (in ms) without interruption of re-connection process.
trackMessagesfalseKeep a cache of in-flight messages that will flushed to a broker on reconnect.
updateURIsSupportedtrueFrom ActiveMQ 5.4: determines whether the client should accept updates from the broker to its list of known URIs.
updateURIsURLnullFrom ActiveMQ 5.4: a URL (or path to a local file) to a text file containing a comma separated list of URIs to use for reconnect in the case of failure.
useExponentialBackOfftrueIf true an exponential back-off is used between reconnect attempts.
warnAfterReconnectAttempts10From ActiveMQ 5.10: a value >0 specifies the number of reconnect attempts before a warning is logged. A logged warning indicates that there is no current connection but re-connection is being attempted. A value of <=0 disables the logging of warnings about reconnect attempts.

backup

初始化的时候创建第二个连接,快速故障转移

initialReconnectDelay

第一次重试延迟

trackMessages

设置是否缓存(故障发生时)尚未传送完成的消息,当broker一旦重新连接成功,便将这些缓存中的消息刷新到新连接的代理中,使得消息可以在broker切换前后顺利传送。默认false

maxCacheSize

当trackMessage启动时,缓存的最大子字节数

maxReconnectAttempts

默认1|0,自5.6版本开始,-1为默认值,代表不限重试次数,0标识从不重试(只尝试连接一次,并不重连),5.6以前的版本,0为默认值,代表不重试,如果设置大于0的数,则代表最大重试次数。

maxReconnectDelay

最长重试间隔

randomize

使用随机连接,以达到负载均衡的目的,默认true

只配主备的情况下最好关闭

startupMaxReconnectAttempts

初始化时的最大重试次

“-1”表示在启动时连接尝试的次数是无限的。

’ >=0 '的值表示在启动时重新连接尝试的次数

一旦成功连接后续将使用“maxReconnectAttempts”选项

timeout

连接超时

updateURIsSupported

是否可以动态修改broker uri

updateURIsURL

指定动态修改地址的路径

useExponentialBackOff

重连时间间隔是否以指数形式增长

reconnectDelayExponent

指数增长时的指数

warnAfterReconnectAttempts

重连日志记录

负载均衡

官方文档

http://activemq.apache.org/networks-of-brokers.html

静态网络配置

在这里插入图片描述

在broker节点下配置networkConnectors

  • networkConnectors(网络连接器)主要用来配置ActiveMQ服务端与服务端之间的通信
  • TransportConnector(传输连接器)主要用于配置ActiveMQ服务端和客户端之间的通信方式
<networkConnectors><networkConnector duplex="true" name="amq-cluster" uri="static:failover://(nio://localhost:5671,nio://localhost:5672)"  />
</networkConnectors>

参与的节点都需要修改

注意如果单机启动多个节点,记得修改端口避免冲突

启动成功后Connections中会有其他节点

在这里插入图片描述

Network中也会显示桥接连接
在这里插入图片描述

负载均衡的环境下,broker上的消息优先给在本地连接的consumer

当networkerConnector与remote Broker建立链接之后,那么remote Broker将会向local Broker交付订阅信息,包括remote broker持有的destinations、Consumers、持久订阅者列表等;那么此后local Broker将把remote Broker做一个消息“订阅者”

Advisory

ActiveMQ提供了“Advisory”机制,通常ActiveMQ内部将某些事件作为“advisory”在全局广播,比如destination的创建、consumer的加入、DLQ的产生等,这将额外的消耗极小的性能;我们可以在ActiveMQ的监控页面上看到影响的消息,开发者也可以View这些消息(通道名称以“ActiveMQ.Advisory.”开头)。对于分布式网络中的broker,将严重依赖“Advisory”,特别是“dynamic network”,默认已开启

在一个broker上发生事件,都会以“通知”的方式发送给配置文件中指定的所有networkConnector

Dynamic networks

“动态网络”表明当remote Broker持有通道的消费者时,local Broker才会转发相应的消息;此时我们需要开启advisorySupport。当remote broker上有Consumer创建时,Advisory中将会广播消息,消息为ConsumerInfo类型,它将包括consumer所在的broker path,如果local broker与此path建立了networkConnector,那么此后local Broker将会启动响应的消息转发。

Static networks

相对于“动态网络”而言,“静态网络”将不依赖Advisory,在任何时候,即使remote Broker中没有相应的consumer,消息也将转发给remote Broker

将brokers作为简单代理并转发消息到远端而不管是否有消费者

可配置属性
URI的几个属性
propertydefaultdescription
initialReconnectDelay1000time(ms) to wait before attempting a reconnect (if useExponentialBackOff is false)
maxReconnectDelay30000time(ms) to wait before attempting to re-connect
useExponentialBackOfftrueincreases time between reconnect for every failure in a reconnect sequence
backOffMultiplier2multipler used to increase the wait time if using exponential back off
NetworkConnector Properties
propertydefaultdescription
namebridgename of the network - for more than one network connector between the same two brokers - use different names
dynamicOnlyfalseif true, only activate a networked durable subscription when a corresponding durable subscription reactivates, by default they are activated on startup.
decreaseNetworkConsumerPriorityfalseif true, starting at priority -5, decrease the priority for dispatching to a network Queue consumer the further away it is (in network hops) from the producer. When false all network consumers use same default priority(0) as local consumers
networkTTL1the number of brokers in the network that messages and subscriptions can pass through (sets both message&consumer -TTL)
messageTTL1(version 5.9) the number of brokers in the network that messages can pass through
consumerTTL1(version 5.9) the number of brokers in the network that subscriptions can pass through (keep to 1 in a mesh)
conduitSubscriptionstruemultiple consumers subscribing to the same destination are treated as one consumer by the network
excludedDestinationsemptydestinations matching this list won’t be forwarded across the network (this only applies to dynamicallyIncludedDestinations)
dynamicallyIncludedDestinationsemptydestinations that match this list will be forwarded across the network n.b. an empty list means all destinations not in the exluded list will be forwarded
useVirtualDestSubsfalseif true, the network connection will listen to advisory messages for virtual destination consumers
staticallyIncludedDestinationsemptydestinations that match will always be passed across the network - even if no consumers have ever registered an interest
duplexfalseif true, a network connection will be used to both produce *AND* Consume messages. This is useful for hub and spoke scenarios when the hub is behind a firewall etc.
prefetchSize1000Sets the prefetch size on the network connector’s consumer. It must be > 0 because network consumers do not poll for messages
suppressDuplicateQueueSubscriptionsfalse(from 5.3) if true, duplicate subscriptions in the network that arise from network intermediaries will be suppressed. For example, given brokers A,B and C, networked via multicast discovery. A consumer on A will give rise to a networked consumer on B and C. In addition, C will network to B (based on the network consumer from A) and B will network to C. When true, the network bridges between C and B (being duplicates of their existing network subscriptions to A) will be suppressed. Reducing the routing choices in this way provides determinism when producers or consumers migrate across the network as the potential for dead routes (stuck messages) are eliminated. networkTTL needs to match or exceed the broker count to require this intervention.
bridgeTempDestinationstrueWhether to broadcast advisory messages for created temp destinations in the network of brokers or not. Temp destinations are typically created for request-reply messages. Broadcasting the information about temp destinations is turned on by default so that consumers of a request-reply message can be connected to another broker in the network and still send back the reply on the temporary destination specified in the JMSReplyTo header. In an application scenario where most/all messages use request-reply pattern, this will generate additional traffic on the broker network as every message typically sets a unique JMSReplyTo address (which causes a new temp destination to be created and broadcasted via an advisory message in the network of brokers). When disabling this feature such network traffic can be reduced but then producer and consumers of a request-reply message need to be connected to the same broker. Remote consumers (i.e. connected via another broker in your network) won’t be able to send the reply message but instead raise a “temp destination does not exist” exception.
alwaysSyncSendfalse(version 5.6) When true, non persistent messages are sent to the remote broker using request/reply in place of a oneway. This setting treats both persistent and non-persistent messages the same.
staticBridgefalse(version 5.6) If set to true, broker will not dynamically respond to new consumers. It will only use staticallyIncludedDestinations to create demand subscriptions
userNamenullThe username to authenticate against the remote broker
passwordnullThe password for the username to authenticate against the remote broker

name

相同的名称会被添加到同一集群中

dynamicOnly

是否直接转发,设置成true的话 broker会在没有消费者的时候不去转发消息

decreaseNetworkConsumerPriority

如果为true,网络的消费者优先级降低为-5。如果为false,则默认跟本地消费者一样为0.

networkTTL messageTTL consumerTTL

消息和订阅在网络中被broker转发(穿过)的最大次数,消息在网络中每转发一次,都会将TTL-1

conduitSubscriptions

多个消费者消费消息被当作一个消费者

excludedDestinations

在这个名单中的Destination不会在网络中被转发

<excludedDestinaitons><queue physicalName="include.test.foo"/><topic physicalName="include.test.bar"/></excludedDestinaitons>

dynamicallyIncludedDestinations

通过网络转发的destinations,注意空列表代表所有的都转发。

 <dynamicallyIncludeDestinaitons><queue physicalName="include.test.foo"/><topic physicalName="include.test.bar"/></dynamicallyIncludeDestinaitons>

useVirtualDestSubs

开启此选项会在转发消息时

staticallyIncludedDestinations

匹配的目的地将始终通过网络传递——即使没有消费者对此感兴趣 对应静态networks

 <staticallyIncludeDestinaitons><queue physicalName="aways.include.queue"/></staticallyIncludeDestinaitons>

duplex

是否允许双向连接如果该属性为true,当这个节点使用Network Bridge连接到其它目标节点后,将强制目标也建立Network Bridge进行反向连接

prefetchSize

缓冲消息大小,必须大于0,不会主动拉取消息

suppressDuplicateQueueSubscriptions

如果为true, 重复的订阅关系一产生即被阻止。

bridgeTempDestinations

是否转发临时destination,禁用后再使用request/reply模型的时候客户端需要连接到同一broker,不然会找不到destination

alwaysSyncSend

开启后转发非持久化消息会使用request/reply模型

staticBridge

如果设置为true,则代理将不会动态响应新的consumer,只能使用staticallyIncludedDestinations中的destination

userName password

连接broker时的用户名和密码

动态网络配置

官方文档

http://activemq.apache.org/multicast-transport-reference

使用multicast协议,可以指定组播地址或使用multicast://default(239.255.2.3)

配置networkConnectors

<networkConnectors><networkConnector uri="multicast://239.0.0.5" duplex="false"/>
</networkConnectors>

broker启动后会使用udp协议向组播地址发送数据报文以便让其他在这个组播地址的节点感知到自己的存在

每个UDP数据报中,包含的主要信息包括本节点ActiveMQ的版本信息,以及连接到自己所需要使用的host名字、协议名和端口信息。

配置transportConnector指明将哪一个连接通过UDP数据报向其他ActiveMQ节点进行公布,就需要在transportConnector标签上使用discoveryUri属性进行标识

	<transportConnector name="auto+nio" uri="auto+nio://localhost:5672" discoveryUri="multicast://239.0.0.5"/>

消息回流

在消息转发的时候,remote broker转发Local broker的消息会消费掉LocalBroker的消息

那么在转发的过程中,消息在被拉取后和发送给consumer的过程中重启的话会造成消息丢失

replayWhenNoConsumers 选项可以使remote broke上有需要转发的消息但是没有被消费时,把消息回流到它原始的broker.同时把enableAudit设置为false,为了防止消息回流后被当作重复消息而不被分发

     <destinationPolicy><policyMap><policyEntries><policyEntry queue=">" enableAudit="false"><networkBridgeFilterFactory><conditionalNetworkBridgeFilterFactory replayWhenNoConsumers="true"/></networkBridgeFilterFactory></policyEntry></policyEntries></policyMap></destinationPolicy>

消息副本

http://activemq.apache.org/replicated-message-store

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/823537.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

代理知识科普:为什么有的代理IP速度比较慢呢?

代理IP在跨境业务中被广泛的应用&#xff0c;今天我们将一同深入探讨一个问题&#xff1a;“为什么有的IP代理速度比较慢&#xff1f;”随着数字化时代的不断发展&#xff0c;代理服务成为了许多网络操作的关键环节。然而&#xff0c;有时我们可能会遇到IP代理速度慢的问题&…

在Windows 10中打开高级系统属性的几种方法,总有一种适合你

序言 高级系统属性允许你配置许多内容&#xff0c;从性能到用户配置文件&#xff0c;从启动到环境变量。虽然这些设置不一定需要更改&#xff0c;并且只有在他们对自己正在做的事情有很好的了解时才应该执行&#xff0c;但了解它们肯定会帮助你在需要时调节 Windows。 什么是…

pycharm 更换Eclipse 的按键模式 keymap

流程 整体来说比较简单&#xff0c;其实只要下载一个eclipse keymap插件就可以完成 首先 ctrl alt s 打开设置页面&#xff0c;找到 plugin 安装完成后还是在 settings 下切换到 keymap即可以看到eclipse 的按键设置出现了&#xff0c;应用后ok 即可完成 再去试试&#x…

2024最新在线工具箱网站系统源码

(购买本专栏可免费下载栏目内所有资源不受限制,持续发布中,需要注意的是,本专栏为批量下载专用,并无法保证某款源码或者插件绝对可用,介意不要购买!购买本专栏住如有什么源码需要,可向博主私信,第二天即可发布!博主有几万资源) 2024最新在线工具箱网站系统源码是一…

Semaphore信号量源码解读与使用

&#x1f3f7;️个人主页&#xff1a;牵着猫散步的鼠鼠 &#x1f3f7;️系列专栏&#xff1a;Java全栈-专栏 &#x1f3f7;️个人学习笔记&#xff0c;若有缺误&#xff0c;欢迎评论区指正 目录 1. 前言 2. 什么是Semaphore&#xff1f; 3. Semaphore源码解读 3.1 acquire…

如何安装flash-attn

flash-attn库安装记录_flash_attn-CSDN博客文章浏览阅读2.2k次&#xff0c;点赞11次&#xff0c;收藏14次。flash-attn库安装记录。安装好cuda11.7。让库找到cuda路径。_flash_attnhttps://blog.csdn.net/liaoqingjian/article/details/135624375?ops_request_misc%257B%2522r…

面试官:一个Java对象占用多大内存?

程序员的公众号&#xff1a;源1024&#xff0c;获取更多资料&#xff0c;无加密无套路&#xff01; 最近整理了一波电子书籍资料&#xff0c;包含《Effective Java中文版 第2版》《深入JAVA虚拟机》&#xff0c;《重构改善既有代码设计》&#xff0c;《MySQL高性能-第3版》&…

Ubuntu上安装Chrome浏览器

安装步骤 1.下载安装chrome安装包 wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb2.安装Chrome浏览器 sudo dpkg -i google-chrome-stable_current_amd64.debsudo apt-get -f install3.启动Chrome浏览器 查看收藏夹里的Chrome图标 单击C…

OpenHarmony实战开发-NAPI封装ArkTS接口案例。

介绍 部分应用的主要开发语言为C/C&#xff0c;但是HarmonyOS的部分接口仅以ArkTS的形式暴露&#xff0c;因此需要将ArkTS的接口封装为Native接口。本例以DocumentViewPicker的Select方法为例&#xff0c;提供了Napi封装ArkTS API的通用方法&#xff0c;本例包含内容如下&…

8个视频剪辑素材网,免费下载!

视频剪辑从业者应该去哪里找免费的剪辑素材&#xff1f;收藏好下面这8个网站&#xff0c;告别付费&#xff0c;永久免费。 免费视频素材 1、菜鸟图库 https://www.sucai999.com/video.html?vNTYwNDUx 菜鸟图库虽然是个设计素材网站&#xff0c;但除了设计类素材之外还有很多…

短视频素材在哪里可以找到?8个视频素材软件app免费

在这个视觉内容占据重要地位的时代&#xff0c;每一位视频创作者都需要从全球各种独特的资源中寻找灵感。以下精选的优质视频素材网站不仅能提供高质量的无水印视频素材&#xff0c;还能帮助你把握项目的视觉冲击力&#xff0c;使你的作品在众多内容中脱颖而出。 1. 蛙学府&…

Vue2:标签页一个页面拆分成俩个选项卡

概要 在自己的项目中&#xff0c;标签页组件显示一般就是点击一个页面&#xff0c;然后标签页组件显示该页面的名称。但是如果你是一个页面文件中展示不同的内容比如( 某模块的新增页面 和 详情页面)一般内容新建页面和详情页面差别不是很大&#xff0c;有的内容甚至俩边都会用…

【kubeEdge】离线部署

部署 kubeEdge 在线部署 在线方式部署直接执行以下命令&#xff0c;会联网下载需要的安装文件执行安装 $ keadm init --advertise-address{ip} --kubeedge-version{version} --kube-config{config_path}&#xff0c; 离线部署 离线准备工作 所有下载操作均在可以联网的机…

CSS3 新特性 box-shadow 阴影效果、圆角border-radius

圆角 使用CSS3 border-radius属性&#xff0c;你可以给任何元素制作"圆角"&#xff0c;border-radius属性&#xff0c;可以使用以下规则&#xff1a; &#xff08;1&#xff09;四个值&#xff1a;第一个值为左上角&#xff0c;第二个值为右上角&#xff0c;第三个值…

Trigger触发器

触发器是指当满足预设的条件时去执行一些事务的工具&#xff0c;比如我们希望鼠标移到某个按钮上方时&#xff0c;这个按钮的颜色、大小发生一些改变。这个时候&#xff0c;条件是鼠标移到按钮上&#xff0c;执行的事务是改变按钮的颜色和大小。 触发器种类 触发器主要运用的场…

组织机构代码是哪几位?营业执照怎么看组织机构代码?

组织机构代码是哪几位? 组织机构代码通常指的是组织机构代码证上的一组特定数字&#xff0c;它用于唯一标识一个组织或机构。在中国&#xff0c;组织机构代码由9位数字组成&#xff0c;前8位是本体代码&#xff0c;最后1位是校验码。这组代码是按照国家有关标准编制的&#x…

GitHub repository - Pulse - Contributors - Network

GitHub repository - Pulse - Contributors - Network 1. Pulse2. Contributors3. NetworkReferences 1. Pulse 显示该仓库最近的活动信息。该仓库中的软件是无人问津&#xff0c;还是在火热地开发之中&#xff0c;从这里可以一目了然。 2. Contributors 显示对该仓库进行过…

Realsense D455 调试

1 Realsense D455 配置&#xff1a; RGB&#xff1a;彩色相机&#xff0c;FOV&#xff08;h&#xff0c;v&#xff09;&#xff08; 90*65 &#xff09;红外点阵发射&#xff1a;位于上图中RGB右边&#xff0c;发射特定模式的红外光&#xff0c;通常是一种点阵图案&#xff0c…

用Skimage学习数字图像处理(021):图像特征提取之线检测(下)

本节是特征提取之线检测的下篇&#xff0c;讨论基于Hough变换的线检测方法。首先简要介绍Hough变换的基本原理&#xff0c;然后重点介绍Skimage中含有的基于Hough变换的直线和圆形检测到实现。 目录 10.4 Hough变换 10.4.1 原理 10.4.2 实现 10.4 Hough变换 Hough变换&…

项目实现:Boost搜索引擎

目录 一.项目背景 二. 搜索引擎的宏观原理 三.使用到的技术栈与项目环境 四.正排索引vs倒排索引 五.认识标签与去标签 六.建立索引模块 七&#xff0c;编写http服务端 八&#xff0c;编写前端页面 九.搜索结果的优化 遇到的问题&#xff1a; 项目源码&#xff1a;boos…