提问者:小点点

在许多Docker容器上配置ActiveMQ Artemis集群?


我不知道我做错了什么。我试图在2个docker容器上正确配置ActiveMQ Artemis HA集群,但我在日志中没有看到任何关于“备份服务器”等的内容。它似乎不起作用。我试图为集群制作一个简单的Java客户端,但它没有连接到它。请不要写“你读过留档吗”-因为是的,我读过它。从我的角度来看,主从之间似乎没有连接,但我不知道为什么。我已经用数据配置了docker环境:

Dockerfile:

FROM ubuntu:latest
LABEL maintainer="Bernard"

RUN mkdir /artemis
WORKDIR /artemis

RUN apt-get update
RUN apt-get -y install wget
RUN apt-get -y install openjdk-11-jdk
RUN java --version

RUN wget -O "artemis.tar" "https://www.apache.org/dyn/closer.cgi?filename=activemq/activemq-artemis/2.18.0/apache-artemis-2.18.0-bin.tar.gz&action=download"
RUN tar -xvf ./artemis.tar; \
ln -s /artemis/apache-artemis-2.18.0/ ./current

RUN /artemis/current/bin/artemis create --user admin --password admin --http-host 0.0.0.0 --require-login --relax-jolokia bernard

EXPOSE 8161 \
9404 \
61616 \
61617 \
5445 \
5672 \
1883 \
61613

ENTRYPOINT ["/artemis/bernard/bin/artemis", "run"]

docker-撰写。y ml

version: '3'

services:
  myartemis1:
    build: artemis/
    volumes:
      - "/e/sandbox/artemis_volume/artemis1/etc:/artemis/bernard/etc"
    networks:
      artemis-cluster-network:
        ipv4_address: 172.20.0.100
    ports:
      - 8161:8161
      - 9404:9404
      - 9876:9876
      - 61616:61616
      - 5445:5445
      - 5672:5672
      - 1883:1883
      - 61613:61613
      - 5432:5432
  myartemis2:
    build: artemis/
    volumes:
      - "/e/sandbox/artemis_volume/artemis2/etc:/artemis/bernard/etc"
    networks:
      artemis-cluster-network:
        ipv4_address: 172.20.0.101
    ports:
      - 8162:8161
      - 9405:9404
      - 9877:9876
      - 61618:61616
      - 61617:61617
      - 5446:5445
      - 5673:5672
      - 1884:1883
      - 61614:61613
      - 5433:5432

volumes:
  artemis1:
  artemis2:

networks:
  artemis-cluster-network:
    ipam:
      config:
        - subnet: 172.20.0.0/16

masterbroc. xml

<?xml version='1.0'?>
<configuration xmlns="urn:activemq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xi="http://www.w3.org/2001/XInclude" xsi:schemaLocation="urn:activemq /schema/artemis-configuration.xsd">
    <core xmlns="urn:activemq:core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:activemq:core ">
        <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>
            <connector name="netty-connector">tcp://localhost:61616</connector>
            <connector name="server1-connector">tcp://172.20.0.101:61617</connector>
        </connectors>
        <acceptors>
            <acceptor name="netty-acceptor">tcp://localhost:61616</acceptor>
        </acceptors>
        <ha-policy>
            <replication>
                <master>
                    <group-name>mynode</group-name>
                    <check-for-live-server>true</check-for-live-server>
                    <cluster-name>my-cluster</cluster-name>
                </master>
            </replication>
        </ha-policy>
        <broadcast-groups>
            <broadcast-group name="my-broadcast-group">
                <group-address>231.7.7.7</group-address>
                <group-port>9876</group-port>
                <broadcast-period>2000</broadcast-period>
                <connector-ref>netty-connector</connector-ref>
            </broadcast-group>
        </broadcast-groups>
        <discovery-groups>
            <discovery-group name="my-discovery-group">
                <group-address>231.7.7.7</group-address>
                <group-port>9876</group-port>
                <refresh-timeout>10000</refresh-timeout>
            </discovery-group>
        </discovery-groups>
        <cluster-connections>
            <cluster-connection name="my-cluster">
                <address>jms</address>
                <connector-ref>netty-connector</connector-ref>
                <check-period>1000</check-period>
                <connection-ttl>5000</connection-ttl>
                <min-large-message-size>50000</min-large-message-size>
                <call-timeout>5000</call-timeout>
                <retry-interval>500</retry-interval>
                <retry-interval-multiplier>1.0</retry-interval-multiplier>
                <max-retry-interval>5000</max-retry-interval>
                <initial-connect-attempts>-1</initial-connect-attempts>
                <reconnect-attempts>-1</reconnect-attempts>
                <use-duplicate-detection>true</use-duplicate-detection>
                <message-load-balancing>ON_DEMAND</message-load-balancing>
                <max-hops>1</max-hops>
                <confirmation-window-size>32000</confirmation-window-size>
                <call-failover-timeout>30000</call-failover-timeout>
                <notification-interval>1000</notification-interval>
                <notification-attempts>2</notification-attempts>
                <discovery-group-ref discovery-group-name="my-discovery-group"/>
            </cluster-connection>
        </cluster-connections>
        <security-settings>
            <security-setting match="#">
                <permission type="createNonDurableQueue" roles="guest"/>
                <permission type="deleteNonDurableQueue" roles="guest"/>
                <permission type="createDurableQueue" roles="guest"/>
                <permission type="deleteDurableQueue" roles="guest"/>
                <permission type="createAddress" roles="guest"/>
                <permission type="deleteAddress" roles="guest"/>
                <permission type="consume" roles="guest"/>
                <permission type="browse" roles="guest"/>
                <permission type="send" roles="guest"/>
                <permission type="manage" roles="guest"/>
            </security-setting>
        </security-settings>
        <addresses>
            <address name="DLQ">
                <anycast>
                    <queue name="DLQ"/>
                </anycast>
            </address>
            <address name="ExpiryQueue">
                <anycast>
                    <queue name="ExpiryQueue"/>
                </anycast>
            </address>
            <address name="exampleQueue">
                <anycast>
                    <queue name="exampleQueue"/>
                </anycast>
            </address>
        </addresses>
        <address-settings>
            <address-setting match="#">
                <redistribution-delay>0</redistribution-delay>
            </address-setting>
        </address-settings>
    </core>
</configuration>

经纪人. xml

<?xml version='1.0'?>
<configuration xmlns="urn:activemq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xi="http://www.w3.org/2001/XInclude" xsi:schemaLocation="urn:activemq /schema/artemis-configuration.xsd">
    <core xmlns="urn:activemq:core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:activemq:core ">
        <paging-directory>data/paging</paging-directory>
        <bindings-directory>data/bindings</bindings-directory>
        <journal-directory>data/journal</journal-directory>
        <large-messages-directory>data/large-messages</large-messages-directory>
        <connectors>
            <connector name="netty-connector">tcp://localhost:61617</connector>
            <connector name="server0-connector">tcp://172.20.0.100:61616</connector>
        </connectors>
        <acceptors>
            <acceptor name="netty-acceptor">tcp://localhost:61617</acceptor>
        </acceptors>
        <ha-policy>
            <replication>
                <slave>
                    <group-name>mynode</group-name>
                    <cluster-name>my-cluster</cluster-name>
                </slave>
            </replication>
        </ha-policy>
        <broadcast-groups>
            <broadcast-group name="my-broadcast-group">
                <group-address>231.7.7.7</group-address>
                <group-port>9876</group-port>
                <broadcast-period>2000</broadcast-period>
                <connector-ref>netty-connector</connector-ref>
            </broadcast-group>
        </broadcast-groups>
        <discovery-groups>
            <discovery-group name="my-discovery-group">
                <group-address>231.7.7.7</group-address>
                <group-port>9876</group-port>
                <refresh-timeout>10000</refresh-timeout>
            </discovery-group>
        </discovery-groups>
        <cluster-connections>
            <cluster-connection name="my-cluster">
                <address/>
                <connector-ref>netty-connector</connector-ref>
                <check-period>1000</check-period>
                <connection-ttl>5000</connection-ttl>
                <min-large-message-size>50000</min-large-message-size>
                <call-timeout>5000</call-timeout>
                <retry-interval>500</retry-interval>
                <retry-interval-multiplier>1.0</retry-interval-multiplier>
                <max-retry-interval>5000</max-retry-interval>
                <initial-connect-attempts>-1</initial-connect-attempts>
                <reconnect-attempts>-1</reconnect-attempts>
                <use-duplicate-detection>true</use-duplicate-detection>
                <message-load-balancing>ON_DEMAND</message-load-balancing>
                <max-hops>1</max-hops>
                <confirmation-window-size>32000</confirmation-window-size>
                <call-failover-timeout>30000</call-failover-timeout>
                <notification-interval>1000</notification-interval>
                <notification-attempts>2</notification-attempts>
                <discovery-group-ref discovery-group-name="my-discovery-group"/>
            </cluster-connection>
        </cluster-connections>
        <security-settings>
            <security-setting match="#">
                <permission type="createNonDurableQueue" roles="guest"/>
                <permission type="deleteNonDurableQueue" roles="guest"/>
                <permission type="createDurableQueue" roles="guest"/>
                <permission type="deleteDurableQueue" roles="guest"/>
                <permission type="createAddress" roles="guest"/>
                <permission type="deleteAddress" roles="guest"/>
                <permission type="consume" roles="guest"/>
                <permission type="browse" roles="guest"/>
                <permission type="send" roles="guest"/>
                <permission type="manage" roles="guest"/>
            </security-setting>
        </security-settings>
        <addresses>
            <address name="DLQ">
                <anycast>
                    <queue name="DLQ"/>
                </anycast>
            </address>
            <address name="ExpiryQueue">
                <anycast>
                    <queue name="ExpiryQueue"/>
                </anycast>
            </address>
            <address name="exampleQueue">
                <anycast>
                    <queue name="exampleQueue"/>
                </anycast>
            </address>
        </addresses>
        <address-settings>
            <address-setting match="#">
                <redistribution-delay>0</redistribution-delay>
            </address-setting>
        </address-settings>
    </core>
</configuration>

Java客户端的片段:

final String groupAddress = "231.7.7.7";
final int groupPort = 9876;
DiscoveryGroupConfiguration discoveryGroupConfiguration = new DiscoveryGroupConfiguration();
UDPBroadcastEndpointFactory udpBroadcastEndpointFactory =
        new UDPBroadcastEndpointFactory().setGroupAddress(groupAddress)
        .setGroupPort(groupPort);
discoveryGroupConfiguration.setBroadcastEndpointFactory(udpBroadcastEndpointFactory);
ConnectionFactory jmsConnectionFactory =
        ActiveMQJMSClient.createConnectionFactoryWithHA(discoveryGroupConfiguration, JMSFactoryType.CF);
Connection jmsConnection1 = jmsConnectionFactory.createConnection();
Connection jmsConnection2 = jmsConnectionFactory.createConnection();

共1个答案

匿名用户

netty-接受器接受器必须使用容器IP地址来允许外部连接,即主接受器应该是:

<acceptor name="netty-acceptor">tcp://172.20.0.100:61616</acceptor>

从属受体应该是:

<acceptor name="netty-acceptor">tcp://172.20.0.101:61616</acceptor>

netty连接器必须使用容器IP地址,以便其他代理实例能够在发现它时连接到它,即主连接器应该是:

<connector name="netty-connector">tcp://172.20.0.100:61617</connector>

从属连接器应该是:

<connector name="netty-connector">tcp://172.20.0.100:61617</connector>

Docker Compose使得部署微服务应用程序非常容易,但它对于正式生产环境有一些限制。我会看看开源ArtemisCloud.io项目,它是一个容器映像集合,提供了一种在库伯内特斯上部署Apache ActiveMQ Artemis Broker的方法。