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.mfbz.cn/a/551963.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

leetcode:739.每日温度/496.下一个更大元素

单调栈的应用&#xff1a; 求解当前元素右边比该元素大的第一个元素&#xff08;左右、大小都可以&#xff09;。 单调栈的构成&#xff1a; 单调栈里存储数组的下标&#xff1b; 单调栈里的元素递增&#xff0c;求解当前元素右边比该元素大的第一个元素&#xff1b;元素递…

Python继承

语法格式&#xff1a; class 子类类名(父类1[&#xff0c;父类2&#xff0c;...])&#xff1a;类体如果在类定义中没有指定父类&#xff0c;则默认父类是 object类 。也就是说&#xff0c;object 是所有类的父类&#xff0c;里面定义了一些所有类共有的默认实现&#xff0c;比…

Python接口自动化 —— Web接口!

1.2.1 web接口的概念 这里用一个浏览器调试工具捕捉课程管理页面请求作为例子&#xff1a; 当请求页面时&#xff0c;服务器会返回资源&#xff0c;将协议看做是路的话&#xff0c;http可以看做高速公路&#xff0c;soap看做铁路传输的数据有html&#xff0c;css&#xff0…

【文献分享】PCCP:机器学习 + 分子动力学 + 第一性原理 + 热学性质 + 微观结构

分享一篇关于机器学习 分子动力学 第一性原理 热学性质&#xff08;密度、粘度、扩散系数&#xff09; 微观结构的文章。 感谢论文的原作者&#xff01; 关键词&#xff1a; 1. Machine learning, 2. Deep potential, 3. Molecular dynamics 4. Molten salt, 5. Thermo…

OCP-数据库中的小米SU7

oracle ocp ​数据库中的SU7 ​好看又好用 需要找工作和落户的快来

剑指offer剪绳子;leetcode:LCR 131. 砍竹子 I

现需要将一根长为正整数 bamboo_len 的竹子砍为若干段&#xff0c;每段长度均为正整数。请返回每段竹子长度的最大乘积是多少。 示例 1&#xff1a; 输入: bamboo_len 12 输出: 81提示&#xff1a; 2 < bamboo_len < 58 注意&#xff1a;本题与主站 343 题相同&#…

基于峰谷分时电价引导下的电动汽车充电负荷优化

在研究电动汽车用户充电需求的前提下&#xff0c;利用蒙特卡洛方法对&#xff12;种不同充电方式进行模拟并对其进行分 析&#xff1b;分析用户响应度对电动汽车有序充电的影响&#xff0c;建立峰谷分时电价对电动汽车负荷影响的模型&#xff0c;在模拟出电动汽 车无序充电负荷…

Windows 部署ChatGLM3大语言模型

一、环境要求 硬件 内存&#xff1a;> 16GB 显存: > 13GB&#xff08;4080 16GB&#xff09; 硬盘&#xff1a;60G 软件 python 版本推荐3.10 - 3.11 transformers 库版本推荐为 4.36.2 torch 推荐使用 2.0 及以上的版本&#xff0c;以获得最佳的推理性能 二、部…

重生奇迹mu恶魔来袭副本

在游戏重生奇迹mu中&#xff0c;恶魔来袭副本是玩家能够组队通过的副本。但是因为手游组队的不方便性&#xff0c;部分玩家对其还是非常苦手。而今天&#xff0c;我们就给大家讲解一下这个游戏的双人通关攻略。 1、挂机找怪手动输出 (1)对于普通剧情副本而言&#xff0c;挂机…

利用CNN-Bigru-Attention模型输电线路故障诊断(Python代码,TensorFlow框架,)

效果视频&#xff1a;利用CNN-Bigru-Attention模型输电线路故障诊断(Python代码&#xff0c;TensorFlow框架&#xff0c;压缩包带有数据集和代码&#xff0c;解压缩可直接运行)_哔哩哔哩_bilibili 售后包免费远程协助运行&#xff08;用向日葵或者todesk软件协助&#xff09; …

校园智能水电预付费管理系统

校园智能水电预付费管理系统是一种专为学校水电资源管理而设计的智能化系统&#xff0c;旨在提供全面的水电资源管理解决方案&#xff0c;满足校园管理者对水电资源管理的需求。该系统整合了先进的智能技术和云计算&#xff0c;为校园管理者提供了实时监控、自动计费、节能管理…

如何将图片你分辨率调整到350dpi?分辨率快速设置工具

图片的分辨率通常用在打印照片和一些考试平台对上传证件照的要求上&#xff0c;我们平时拍摄的图片dpi大多都是96的&#xff0c;所以不符合使用需求&#xff0c;那么怎么把这些比较低分辨率的图片修改到350dpi呢&#xff1f;试试本文分享的这几个方法吧&#xff0c;简单又方便。…

使用阿里云试用Elasticsearch学习:创建仪表板pivot、搜索discover和仪表板dashboard

文档&#xff1a;https://www.elastic.co/guide/en/elasticsearch/reference/current/transform-examples.html#example-clientips 在kibana左栏打开Transforms&#xff0c;并创建Transforms&#xff08;转换&#xff09; Management > Stack Management > Data > T…

component-传入值圆形百分比展示,.background-image: conic-gradient()

1.效果 2.代码 <template><div class"circle" :style"{ background-image: conic-gradient(#3498db 0 ${fillPercentage}%, transparent ${fillPercentage}% 100%) }"></div> <!-- 使用动态绑定样式来设置填充效果 --> </temp…

放大招,推广手机流量卡,佣金丰厚等你来拿

流量卡推广是一个非常冷门但又在身边非常常见的行业&#xff0c;知道的人目前靠着这个信息&#xff0c;发了很多小财&#xff0c;可以说早知道这一行的人会非常容易变成暴发户。 你可能也会好奇&#xff0c;为什么那么多广告都是在推流量卡&#xff0c;他们推卡到底有多高的利…

SpringBoot配置文件加载顺序

一、内部配置加载顺序 SpringBoot程序启动时&#xff0c;会从以下位置加载配置文件&#xff1a; file:./config/ &#xff1a;当前项目的config目录下&#xff1b;file:./ &#xff1a;当前项目的根目录下&#xff1b;classpath:/c…

L1-086 斯德哥尔摩火车上的题

上图是新浪微博上的一则趣闻&#xff0c;是瑞典斯德哥尔摩火车上的一道题&#xff0c;看上去是段伪代码&#xff1a; s a 1112031584 for (i 1; i < length(a); i) {if (a[i] % 2 a[i-1] % 2) {s max(a[i], a[i-1])} } goto_url(www.multisoft.se/ s)其中字符串的 …

STM32 CAN控制的相关结构体(标准库)

STM32 CAN控制的相关结构体&#xff08;标准库&#xff09; 初始化结构体&#xff1a; CAN_InitTypeDef CAN_Prescaler 本成员设置CAN外设的时钟分频&#xff0c;它可控制时间片Tq的时间长度&#xff0c;这里设置的值最终会减1后再写入BRP寄存器位&#xff0c;即前面介绍的Tq计…

数组中两个字符串的最短距离---一题多解(贪心/二分)

点击跳转到题目 方法&#xff1a;贪心 / 二分 目录 贪心&#xff1a; 二分&#xff1a; 贪心&#xff1a; 要找出字符串数组中指定两个字符串的最小距离&#xff0c;即找出指定字符串对应下标之差的最小值 思考&#xff1a;如果是直接暴力求解&#xff0c;需要两层for循环…

牛客 2024 【牛客赛文X】春招冲刺 ONT73 体育课测验(二) 【中等 图/拓扑排序 Java,Go,PHP】

题目 题目链接&#xff1a; https://www.nowcoder.com/practice/64a4c026b2aa4411984f560deec36323 思路 图&#xff0c;BFS&#xff0c;队列参考答案Java import java.util.*;public class Solution {/*** 代码中的类名、方法名、参数名已经指定&#xff0c;请勿修改&…
最新文章