使用外部 ActiveMQ 代理的 WildFly Swarm 应用程序

WildFly Swarm apps using an external ActiveMQ broker

我很难让两个 WildFly swarm 应用程序(基于 2017.9.5 版本)通过独立的 ActiveMQ 5.14.3 代理相互通信。全部使用 YAML 配置完成,因为在我的情况下我没有主要方法。

在阅读了数百个过时的示例和不准确的文档页面后,我决定对生产者和消费者应用程序进行以下设置:

swarm:

  messaging-activemq:
    servers:
      default:
        jms-topics:
          domain-events: {}

  messaging:
    remote:
      name: remote-mq
      host: localhost
      port: 61616
      jndi-name: java:/jms/remote-mq

  remote: true

现在看来,除了以下警告外,应用程序启动时至少部分设置是正确的:

2017-09-16 14:20:04,385 WARN  [org.jboss.activemq.artemis.wildfly.integration.recovery] (MSC service thread 1-2) AMQ122018: Could not start recovery discovery on XARecoveryConfig [transportConfiguration=[TransportConfiguration(name=, factory=org-apache-activemq-artemis-core-remoting-impl-netty-NettyConnectorFactory) ?port=61616&localAddress=::&host=localhost], discoveryConfiguration=null, username=null, password=****, JNDI_NAME=java:/jms/remote-mq], we will retry every recovery scan until the server is available

此外,当生产者尝试发送消息时,它只是超时,我得到以下异常(只是最后一部分):

Caused by: javax.jms.JMSException: Failed to create session factory
    at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnectionInternal(ActiveMQConnectionFactory.java:727)
    at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createXAConnection(ActiveMQConnectionFactory.java:304)
    at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createXAConnection(ActiveMQConnectionFactory.java:300)
    at org.apache.activemq.artemis.ra.ActiveMQRAManagedConnection.setup(ActiveMQRAManagedConnection.java:785)
    ... 127 more
Caused by: ActiveMQConnectionTimedOutException[errorType=CONNECTION_TIMEDOUT message=AMQ119013: Timed out waiting to receive cluster topology. Group:null]
    at org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:797)
    at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnectionInternal(ActiveMQConnectionFactory.java:724)
    ... 130 more

我怀疑问题是 ActiveMQ 开启了安全,但是我发现没有地方可以给 swarm config 提供用户名和密码。

ActiveMQ 实例是 运行 使用 Docker 和以下组合文件:

version: '2'

services:

  activemq:
    image: webcenter/activemq
    environment:
      - ACTIVEMQ_NAME=amqp-srv1
      - ACTIVEMQ_REMOVE_DEFAULT_ACCOUNT=true
      - ACTIVEMQ_ADMIN_LOGIN=admin
      - ACTIVEMQ_ADMIN_PASSWORD=your_password
      - ACTIVEMQ_WRITE_LOGIN=producer_login
      - ACTIVEMQ_WRITE_PASSWORD=producer_password
      - ACTIVEMQ_READ_LOGIN=consumer_login
      - ACTIVEMQ_READ_PASSWORD=consumer_password
      - ACTIVEMQ_JMX_LOGIN=jmx_login
      - ACTIVEMQ_JMX_PASSWORD=jmx_password
      - ACTIVEMQ_MIN_MEMORY=1024
      - ACTIVEMQ_MAX_MEMORY=4096
      - ACTIVEMQ_ENABLED_SCHEDULER=true

    ports:
      - "1883:1883"
      - "5672:5672"
      - "8161:8161"
      - "61616:61616"
      - "61613:61613"
      - "61614:61614"

知道出了什么问题吗?

我也曾试图让它工作,但也遇到了困难。以下 YML 解决了我的问题:

swarm:
  network:
    socket-binding-groups:
      standard-sockets:
        outbound-socket-bindings:
          myapp-socket-binding:
            remote-host: localhost
            remote-port: 61616
  messaging-activemq:
    servers:
      default:
        remote-connectors:
          myapp-connector:
            socket-binding: myapp-socket-binding
        pooled-connection-factories:
          myAppRemote:
            user: username
            password: password
            connectors:
              - myapp-connector
            entries:
              - 'java:/jms/remote-mq'