Docker Swarm 上的 ActiveMQ Artemis 集群
ActiveMQ Artemis cluster on Docker Swarm
我正在尝试在 Docker Swarm 环境中设置 2 个 ActiveMQ Artemis 代理的简单集群。
堆栈配置
version: "3.7"
services:
broker_1:
image: broker-local
build:
context: ./activemq
dockerfile: Dockerfile-centos
ports:
- "8161:8161" # Embedded web server
- "61616:61616" # Main Artemis acceptor
networks:
artemis-cluster-network:
environment:
EXTRA_ARGS: "--http-host 0.0.0.0 --relax-jolokia"
ANONYMOUS_LOGIN: "true"
configs:
- source: broker_1_config
target: /run/config/broker.xml
broker_2:
image: broker-local
depends_on:
- "broker_1"
build:
context: ./activemq
dockerfile: Dockerfile-centos
ports:
- "8162:8161" # Embedded web server
- "61617:61617" # Main Artemis acceptor
networks:
artemis-cluster-network:
environment:
EXTRA_ARGS: "--http-host 0.0.0.0 --relax-jolokia"
configs:
- source: broker_2_config
target: /run/config/broker.xml
networks:
artemis-cluster-network:
driver: overlay
attachable: true
configs:
broker_1_config:
file: ./broker_1.xml
broker_2_config:
file: ./broker_2.xml
Broker_1配置
<configuration xmlns="urn:activemq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:activemq /schema/artemis-configuration.xsd">
<core xmlns="urn:activemq:core">
<name>broker_1</name>
<bindings-directory>./data/bindings</bindings-directory>
<journal-directory>./data/journal</journal-directory>
<large-messages-directory>./data/largemessages</large-messages-directory>
<paging-directory>./data/paging</paging-directory>
<!-- Connectors -->
<connectors>
<connector name="netty-connector">tcp://0.0.0.0:61616</connector>
<!-- connector to the server1 -->
<connector name="server2-connector">tcp://broker_2:61617</connector>
</connectors>
<!-- Acceptors -->
<acceptors>
<acceptor name="netty-acceptor">tcp://0.0.0.0:61616</acceptor>
</acceptors>
<cluster-connections>
<cluster-connection name="my-cluster">
<connector-ref>netty-connector</connector-ref>
<retry-interval>500</retry-interval>
<use-duplicate-detection>true</use-duplicate-detection>
<message-load-balancing>STRICT</message-load-balancing>
<max-hops>5</max-hops>
<static-connectors allow-direct-connections-only="true">
<connector-ref>server2-connector</connector-ref>
</static-connectors>
</cluster-connection>
</cluster-connections>
<!-- Other config -->
<security-settings>
<!--security for example queue-->
<security-setting match="exampleQueue">
<permission roles="guest" type="createDurableQueue"/>
<permission roles="guest" type="deleteDurableQueue"/>
<permission roles="guest" type="createNonDurableQueue"/>
<permission roles="guest" type="deleteNonDurableQueue"/>
<permission roles="guest" type="consume"/>
<permission roles="guest" type="send"/>
</security-setting>
</security-settings>
<addresses>
<address name="exampleQueue">
<anycast>
<queue name="exampleQueue"/>
</anycast>
</address>
</addresses>
<broker-plugins>
<broker-plugin class-name="org.apache.activemq.artemis.core.server.plugin.impl.LoggingActiveMQServerPlugin">
<property key="LOG_ALL_EVENTS" value="true"/>
<property key="LOG_CONNECTION_EVENTS" value="true"/>
<property key="LOG_SESSION_EVENTS" value="true"/>
<property key="LOG_CONSUMER_EVENTS" value="true"/>
<property key="LOG_DELIVERING_EVENTS" value="true"/>
<property key="LOG_SENDING_EVENTS" value="true"/>
<property key="LOG_INTERNAL_EVENTS" value="true"/>
</broker-plugin>
</broker-plugins>
</core>
</configuration>
Broker_2配置
<configuration xmlns="urn:activemq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:activemq /schema/artemis-configuration.xsd">
<core xmlns="urn:activemq:core">
<name>broker_2</name>
<bindings-directory>./data/bindings</bindings-directory>
<journal-directory>./data/journal</journal-directory>
<large-messages-directory>./data/largemessages</large-messages-directory>
<paging-directory>./data/paging</paging-directory>
<!-- Connectors -->
<connectors>
<connector name="netty-connector">tcp://0.0.0.0:61617</connector>
<!-- connector to the server0 -->
<connector name="server1-connector">tcp://broker_1:61616</connector>
</connectors>
<!-- Acceptors -->
<acceptors>
<acceptor name="netty-acceptor">tcp://0.0.0.0:61617</acceptor>
</acceptors>
<cluster-connections>
<cluster-connection name="my-cluster">
<connector-ref>netty-connector</connector-ref>
<retry-interval>500</retry-interval>
<use-duplicate-detection>true</use-duplicate-detection>
<message-load-balancing>STRICT</message-load-balancing>
<max-hops>5</max-hops>
<static-connectors allow-direct-connections-only="true">
<connector-ref>server1-connector</connector-ref>
</static-connectors>
</cluster-connection>
</cluster-connections>
<!-- Other config -->
<security-settings>
<!--security for example queue-->
<security-setting match="exampleQueue">
<permission roles="guest" type="createDurableQueue"/>
<permission roles="guest" type="deleteDurableQueue"/>
<permission roles="guest" type="createNonDurableQueue"/>
<permission roles="guest" type="deleteNonDurableQueue"/>
<permission roles="guest" type="consume"/>
<permission roles="guest" type="send"/>
</security-setting>
</security-settings>
<addresses>
<address name="exampleQueue">
<anycast>
<queue name="exampleQueue"/>
</anycast>
</address>
</addresses>
<broker-plugins>
<broker-plugin class-name="org.apache.activemq.artemis.core.server.plugin.impl.LoggingActiveMQServerPlugin">
<property key="LOG_ALL_EVENTS" value="true"/>
<property key="LOG_CONNECTION_EVENTS" value="true"/>
<property key="LOG_SESSION_EVENTS" value="true"/>
<property key="LOG_CONSUMER_EVENTS" value="true"/>
<property key="LOG_DELIVERING_EVENTS" value="true"/>
<property key="LOG_SENDING_EVENTS" value="true"/>
<property key="LOG_INTERNAL_EVENTS" value="true"/>
</broker-plugin>
</broker-plugins>
</core>
</configuration>
在 运行 两个服务之后没有任何反应。没有记录任何有趣的内容。
我尝试了 UDP 发现方法,但发现在 Docker 覆盖网络上是不可能的。
然后我尝试了 JGroups 方法,但也没有用。尝试建立连接,但每次尝试都超时。并尝试对容器 ID 表示的主机进行尝试。
这种方法可能很有趣,但 JGRoups 使用的共享 ping 目录对 Swarm 方法无效。在本地机器上,在两个容器之间共享它没有问题。
我也在使用 Fiddler,所以像 broker_1 这样的名字被翻译成本地主机。
名为“netty_connector”的 connector
不应使用 0.0.0.0
。这是将被发送到集群中其他节点的地址,以告诉它们如何连接回发送它的节点。地址 0.0.0.0
在这种情况下将毫无意义。它需要是代理侦听网络连接的实际 IP 地址或主机名。
我正在尝试在 Docker Swarm 环境中设置 2 个 ActiveMQ Artemis 代理的简单集群。
堆栈配置
version: "3.7"
services:
broker_1:
image: broker-local
build:
context: ./activemq
dockerfile: Dockerfile-centos
ports:
- "8161:8161" # Embedded web server
- "61616:61616" # Main Artemis acceptor
networks:
artemis-cluster-network:
environment:
EXTRA_ARGS: "--http-host 0.0.0.0 --relax-jolokia"
ANONYMOUS_LOGIN: "true"
configs:
- source: broker_1_config
target: /run/config/broker.xml
broker_2:
image: broker-local
depends_on:
- "broker_1"
build:
context: ./activemq
dockerfile: Dockerfile-centos
ports:
- "8162:8161" # Embedded web server
- "61617:61617" # Main Artemis acceptor
networks:
artemis-cluster-network:
environment:
EXTRA_ARGS: "--http-host 0.0.0.0 --relax-jolokia"
configs:
- source: broker_2_config
target: /run/config/broker.xml
networks:
artemis-cluster-network:
driver: overlay
attachable: true
configs:
broker_1_config:
file: ./broker_1.xml
broker_2_config:
file: ./broker_2.xml
Broker_1配置
<configuration xmlns="urn:activemq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:activemq /schema/artemis-configuration.xsd">
<core xmlns="urn:activemq:core">
<name>broker_1</name>
<bindings-directory>./data/bindings</bindings-directory>
<journal-directory>./data/journal</journal-directory>
<large-messages-directory>./data/largemessages</large-messages-directory>
<paging-directory>./data/paging</paging-directory>
<!-- Connectors -->
<connectors>
<connector name="netty-connector">tcp://0.0.0.0:61616</connector>
<!-- connector to the server1 -->
<connector name="server2-connector">tcp://broker_2:61617</connector>
</connectors>
<!-- Acceptors -->
<acceptors>
<acceptor name="netty-acceptor">tcp://0.0.0.0:61616</acceptor>
</acceptors>
<cluster-connections>
<cluster-connection name="my-cluster">
<connector-ref>netty-connector</connector-ref>
<retry-interval>500</retry-interval>
<use-duplicate-detection>true</use-duplicate-detection>
<message-load-balancing>STRICT</message-load-balancing>
<max-hops>5</max-hops>
<static-connectors allow-direct-connections-only="true">
<connector-ref>server2-connector</connector-ref>
</static-connectors>
</cluster-connection>
</cluster-connections>
<!-- Other config -->
<security-settings>
<!--security for example queue-->
<security-setting match="exampleQueue">
<permission roles="guest" type="createDurableQueue"/>
<permission roles="guest" type="deleteDurableQueue"/>
<permission roles="guest" type="createNonDurableQueue"/>
<permission roles="guest" type="deleteNonDurableQueue"/>
<permission roles="guest" type="consume"/>
<permission roles="guest" type="send"/>
</security-setting>
</security-settings>
<addresses>
<address name="exampleQueue">
<anycast>
<queue name="exampleQueue"/>
</anycast>
</address>
</addresses>
<broker-plugins>
<broker-plugin class-name="org.apache.activemq.artemis.core.server.plugin.impl.LoggingActiveMQServerPlugin">
<property key="LOG_ALL_EVENTS" value="true"/>
<property key="LOG_CONNECTION_EVENTS" value="true"/>
<property key="LOG_SESSION_EVENTS" value="true"/>
<property key="LOG_CONSUMER_EVENTS" value="true"/>
<property key="LOG_DELIVERING_EVENTS" value="true"/>
<property key="LOG_SENDING_EVENTS" value="true"/>
<property key="LOG_INTERNAL_EVENTS" value="true"/>
</broker-plugin>
</broker-plugins>
</core>
</configuration>
Broker_2配置
<configuration xmlns="urn:activemq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:activemq /schema/artemis-configuration.xsd">
<core xmlns="urn:activemq:core">
<name>broker_2</name>
<bindings-directory>./data/bindings</bindings-directory>
<journal-directory>./data/journal</journal-directory>
<large-messages-directory>./data/largemessages</large-messages-directory>
<paging-directory>./data/paging</paging-directory>
<!-- Connectors -->
<connectors>
<connector name="netty-connector">tcp://0.0.0.0:61617</connector>
<!-- connector to the server0 -->
<connector name="server1-connector">tcp://broker_1:61616</connector>
</connectors>
<!-- Acceptors -->
<acceptors>
<acceptor name="netty-acceptor">tcp://0.0.0.0:61617</acceptor>
</acceptors>
<cluster-connections>
<cluster-connection name="my-cluster">
<connector-ref>netty-connector</connector-ref>
<retry-interval>500</retry-interval>
<use-duplicate-detection>true</use-duplicate-detection>
<message-load-balancing>STRICT</message-load-balancing>
<max-hops>5</max-hops>
<static-connectors allow-direct-connections-only="true">
<connector-ref>server1-connector</connector-ref>
</static-connectors>
</cluster-connection>
</cluster-connections>
<!-- Other config -->
<security-settings>
<!--security for example queue-->
<security-setting match="exampleQueue">
<permission roles="guest" type="createDurableQueue"/>
<permission roles="guest" type="deleteDurableQueue"/>
<permission roles="guest" type="createNonDurableQueue"/>
<permission roles="guest" type="deleteNonDurableQueue"/>
<permission roles="guest" type="consume"/>
<permission roles="guest" type="send"/>
</security-setting>
</security-settings>
<addresses>
<address name="exampleQueue">
<anycast>
<queue name="exampleQueue"/>
</anycast>
</address>
</addresses>
<broker-plugins>
<broker-plugin class-name="org.apache.activemq.artemis.core.server.plugin.impl.LoggingActiveMQServerPlugin">
<property key="LOG_ALL_EVENTS" value="true"/>
<property key="LOG_CONNECTION_EVENTS" value="true"/>
<property key="LOG_SESSION_EVENTS" value="true"/>
<property key="LOG_CONSUMER_EVENTS" value="true"/>
<property key="LOG_DELIVERING_EVENTS" value="true"/>
<property key="LOG_SENDING_EVENTS" value="true"/>
<property key="LOG_INTERNAL_EVENTS" value="true"/>
</broker-plugin>
</broker-plugins>
</core>
</configuration>
在 运行 两个服务之后没有任何反应。没有记录任何有趣的内容。
我尝试了 UDP 发现方法,但发现在 Docker 覆盖网络上是不可能的。
然后我尝试了 JGroups 方法,但也没有用。尝试建立连接,但每次尝试都超时。并尝试对容器 ID 表示的主机进行尝试。 这种方法可能很有趣,但 JGRoups 使用的共享 ping 目录对 Swarm 方法无效。在本地机器上,在两个容器之间共享它没有问题。
我也在使用 Fiddler,所以像 broker_1 这样的名字被翻译成本地主机。
名为“netty_connector”的 connector
不应使用 0.0.0.0
。这是将被发送到集群中其他节点的地址,以告诉它们如何连接回发送它的节点。地址 0.0.0.0
在这种情况下将毫无意义。它需要是代理侦听网络连接的实际 IP 地址或主机名。