Skip to content
Latchkey

ActiveMQ Artemis AMQP "Connection refused" on 5672 in CI

The AMQP client could not reach the Artemis acceptor on 5672. Either the broker has not opened its acceptors yet, or the client connected on the wrong port (Artemis multiplexes protocols and the default acceptor is 61616, with AMQP also available depending on configuration).

What this error means

A connect fails with "Connection refused" on 5672, or the Artemis core client reports "AMQ219007: Cannot connect to server(s)".

Terminal
ActiveMQNotConnectedException [errorType=NOT_CONNECTED message=AMQ219007:
Cannot connect to server(s). Tried with all available servers.]

Common causes

The acceptor is not ready yet

Artemis opens its protocol acceptors after startup, so a connect during that window is refused.

Wrong protocol port

The client used a port the configured acceptor does not serve for that protocol, so nothing answers.

How to fix it

Wait for the acceptor, then connect

Poll the AMQP port until it accepts a connection before running the client.

Terminal
until nc -z localhost 5672; do echo "waiting for artemis"; sleep 3; done

Map the correct acceptor port

Publish the port that matches your acceptor and connect on it.

.github/workflows/ci.yml
services:
  artemis:
    image: apache/activemq-artemis:2.33.0
    ports: ['61616:61616', '5672:5672', '8161:8161']

How to prevent it

  • Map the acceptor port that matches the client protocol.
  • Wait for the acceptor to accept connections before the first client.
  • Allow retries during the Artemis startup window.

Frequently asked questions

What causes "Artemis AMQP "Connection refused" (5672)"?
Artemis opens its protocol acceptors after startup, so a connect during that window is refused.
How do I fix Artemis AMQP "Connection refused" (5672)?
Poll the AMQP port until it accepts a connection before running the client.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card