我正在尝试在非主要站点中的代理和主站点中的代理之间定义网桥,其预期行为是将非主站点中生成的消息转发到主站点并在那里处理。
在线进行一些研究之后,我在xml文件中添加了一个<networkConnectors/>
元素,用于指向主代理的非主代理。
这是主要经纪人的XML文件:
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:amq="http://activemq.apache.org/schema/core"
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-2.0.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="Broker" dataDirectory="SOME_PATH" destroyApplicationContextOnStop="true" advisorySupport="false" schedulerSupport="true">
<destinationPolicy>
<policyMap>
<policyEntries>
<policyEntry topic=">" producerFlowControl="true" memoryLimit="20mb">
<pendingSubscriberPolicy>
<vmCursor />
</pendingSubscriberPolicy>
</policyEntry>
<policyEntry queue=">" producerFlowControl="true" memoryLimit="20mb">
</policyEntry>
</policyEntries>
</policyMap>
</destinationPolicy>
<managementContext>
<managementContext createConnector="false"/>
</managementContext>
<persistenceAdapter>
<kahaDB directory="SOME_PATH"/>
</persistenceAdapter>
<systemUsage>
<systemUsage>
<memoryUsage>
<memoryUsage limit="50 mb"/>
</memoryUsage>
<storeUsage>
<storeUsage limit="1 gb"/>
</storeUsage>
<tempUsage>
<tempUsage limit="100 mb"/>
</tempUsage>
</systemUsage>
</systemUsage>
<transportConnectors>
<transportConnector name="primary_broker" uri="tcp://localhost:2384"/>
</transportConnectors>
</broker>
</beans>
这是非主要经纪人的XML文件:
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:amq="http://activemq.apache.org/schema/core"
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-2.0.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="Broker" dataDirectory="SOME_PATH" destroyApplicationContextOnStop="true" advisorySupport="false" schedulerSupport="true">
<destinationPolicy>
<policyMap>
<policyEntries>
<policyEntry topic=">" producerFlowControl="true" memoryLimit="20mb">
<pendingSubscriberPolicy>
<vmCursor />
</pendingSubscriberPolicy>
</policyEntry>
<policyEntry queue=">" producerFlowControl="true" memoryLimit="20mb">
</policyEntry>
</policyEntries>
</policyMap>
</destinationPolicy>
<managementContext>
<managementContext createConnector="false"/>
</managementContext>
<networkConnectors>
<networkConnector name="bridge" uri="static:(tcp://PRIMARY_SERVER_NAME:2384)"/>
</networkConnectors>
<persistenceAdapter>
<kahaDB directory="SOME_PATH"/>
</persistenceAdapter>
<systemUsage>
<systemUsage>
<memoryUsage>
<memoryUsage limit="50 mb"/>
</memoryUsage>
<storeUsage>
<storeUsage limit="1 gb"/>
</storeUsage>
<tempUsage>
<tempUsage limit="100 mb"/>
</tempUsage>
</systemUsage>
</systemUsage>
<transportConnectors>
<transportConnector name="secondary_broker" uri="tcp://localhost:2386"/>
</transportConnectors>
</broker>
</beans>
我在尝试启动非主要代理时遇到的错误是:
Could not start network bridge between: vm://Broker?async=false&network=true and: tcp://PRIMARY_SERVER_NAME:2384 due to: java.net.ConnectException: Connection refused: connect
我做了一些调查并让IT团队参与进来,并确认这不是防火墙问题。
我尝试在同一个非主要主机上的2个代理之间建立一个网络。我使用了相同的配置(即只更新uri
中的networkConnector
值),这次网络建立成功。
我不确定发生了什么以及为什么使用相同的配置,并假设没有网络问题,我能够在同一主机上桥接2个代理,但不能在不同的主机上桥接。
我正在使用ActiveMQ v5.5。
答案 0 :(得分:0)
问题是主代理中的<transportConnector/>
元素配置了localhost
更改它以使用实际的服务器名称后,它工作
<transportConnectors>
<transportConnector name="primary_broker" uri="tcp://SERVER_NAME:2384"/>
</transportConnectors>
答案 1 :(得分:-1)
如果您使用的是activemq版本5.13.3(或更高版本),则只需创建共享文件系统挂载点,并在activemq.xml配置文件中指定它的位置:
<persistenceAdapter>
<levelDB directory="/shared-File-System-Mount-Point"/>
</persistenceAdapter>
我一直在使用AWS efs文件系统,它运行良好。 这些不需要指定网络连接器。 加载时,其中一个activemq服务器将锁定该位置的文件,并将成为主服务器。 如果它因任何原因失败,其中一个可用的从站将自动成为主站。
可以找到更多信息here
另外,this是test the fail over的绝佳工具。