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)".
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.
until nc -z localhost 5672; do echo "waiting for artemis"; sleep 3; doneMap the correct acceptor port
Publish the port that matches your acceptor and connect on it.
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.