单机下activemq集群配置Network of borkers

本文介绍如何通过Network of Brokers配置ActiveMQ集群,包括修改端口、配置文件等关键步骤,并解决常见配置问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

基于Network of brokers(简单起见,这里配置两个broker)的activemq配置:
1)复制两份activemq目录,名称分别为activemq-broker1和activemq-broker2,broker1下的conf目录的activemq.xml文件配置如下

<beans
  xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">

    <!-- Allows us to use system properties as variables in this configuration file -->
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <value>file:${activemq.conf}/credentials.properties</value>
        </property>
    </bean>
    <!--
        The <broker> element is used to configure the ActiveMQ broker.
    -->
    <broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost-1" dataDirectory="${activemq.data}">

        <managementContext>
            <managementContext createConnector="false"/>
        </managementContext>

        <networkConnectors>
            <networkConnector uri="static:(tcp://127.0.0.1:61626)"/>
        </networkConnectors>
        <persistenceAdapter>
            <kahaDB directory="${activemq.data}/kahadb"/>
        </persistenceAdapter>
        <transportConnectors>
            <transportConnector name="openwire"
                uri="tcp://0.0.0.0:61616?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
        </transportConnectors>

    </broker>
    <import resource="jetty.xml"/>

</beans>
<!-- END SNIPPET: example -->

主要修改的位置有:
这里写图片描述
同目录下jetty.xml的端口8161可以默认不需要更改(但是broker2中的需要修改)
这里写图片描述
同理,配置broker2如下,主要还是修改相关端口
activemq.xml

<beans
  xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">

    <!-- Allows us to use system properties as variables in this configuration file -->
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <value>file:${activemq.conf}/credentials.properties</value>
        </property>
    </bean>

    <!--
        The <broker> element is used to configure the ActiveMQ broker.
    -->
    <broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost-2" dataDirectory="${activemq.data}">


        <managementContext>
            <managementContext createConnector="false"/>
        </managementContext>

        <networkConnectors>
            <networkConnector uri="static:(tcp://127.0.0.1:61616)"/>
        </networkConnectors>
            <persistenceAdapter>
              <kahaDB directory="${activemq.data}/kahadb"/>
            </persistenceAdapter>
        <transportConnectors>
            <transportConnector name="openwire"
                uri="tcp://0.0.0.0:61626?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
        </transportConnectors>


        <!-- destroy the spring context on shutdown to stop jetty -->
        <shutdownHooks>
            <bean xmlns="http://www.springframework.org/schema/beans" class="org.apache.activemq.hooks.SpringContextHook" />
        </shutdownHooks>

    </broker>

    <import resource="jetty.xml"/>

</beans>
<!-- END SNIPPET: example -->

主要修改的地方如下:
这里写图片描述
同目录下jetty.xml端口修改为7161
2)项目中的activemq.xml相关配置改为failover

<bean id="mqConnectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory">
        <property name="brokerURL" value="failover:(tcp://localhost:61616,tcp://localhost:61626)"/>
    </bean>

3)启动两个broker的bin》win64目录下(64位windows)的activimq.bat,然后在浏览器中输入地址:
borker1:http://localhost:8161
broker2:http://localhost:7161
即可查看后台相关队列信息,测试发送信息,然后关闭其中常用的一个mq命令窗口,再次发送信息,如果成功说明集群配置完成。

本文大部分参考博客http://www.cnblogs.com/yjmyzz/p/activemq-ha-using-networks-of-brokers.html来配置,博客中讲解的很详细以及有各种部署方法的差异,本文只是对其配置的主要地方作了说明以及总结。

踩过的坑:
1.xml的内容尽可能和上面写的一致,至少里面的标签的内容需要注释

<!--这一段需要注释,因为前面已经写了openwire,否则会报错-->
<transportConnectors>
            <transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
            <transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
            <transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
            <transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
            <transportConnector name="ws" uri="ws://0.0.0.0:61614?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
        </transportConnectors>

2.最新版本的5.15是基于jdk1.8编译的,所以下载的时候先检查自己的jdk版本,博客http://blog.youkuaiyun.com/yanfeipei/article/details/75267384介绍了各版本对应的jdk及查看方法,官网http://activemq.apache.org/download-archives.html有所有版本可提供下载。
3.刚开始使用5.15配置的时候报错
这里写图片描述
这里写图片描述
原因未知,后来换到5.10后不抱错

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值