Skip to content
Advertisement

Connection refused when trying to connect to ActiveMQ Artemis deployed on Openshift

We have an Openshift project ( project1 ) in which we setup an AMQ Artemis broker using the image : amq- amq-broker-7-tech-preview/amq-broker-71-openshif . Being the basic image we don’t have any configuration such as SSL or TLS. In order to do the setup we used as example : https://github.com/jboss-container-images/jboss-amq-7-broker-openshift-image/blob/amq71-dev/templates/amq-broker-71-basic.yaml

After the deployment of the image on Openshift we have the following:

From another Openshift service, in Java we try to connect to the broker but we receive the following error :

[org.apache.activemq.transport.failover.FailoverTransport] (ActiveMQ Task-1) Failed to connect to [tcp://broker-amq-amqp-project1.192.168.99.105.nip.io:61616?keepAlive=true] after: 230 attempt(s) with Connection refused (Connection refused), continuing to retry.

The Java code:

user = "example";
password = "example";

String address = "queue/example";

InitialContext context = new InitialContext();

queue = (Queue) context.lookup(address);
ConnectionFactory cf = (ConnectionFactory) context.lookup("ConnectionFactory");
try (Connection connection = cf.createConnection(user, password);) {
    connection.start();
    session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
}

The JNDI Properties file

java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory
java.naming.provider.url=failover:(tcp://broker-amq-amqp-project1.192.168.99.105.nip.io:61616?keepAlive=true)?randomize=false
queue.queue/example=example/strings

Advertisement

Answer

It looks as if you’re trying to connect to the broker using an OpenShift route, when there is no route defined for the relevant service. You (or the installer) defined a route for Jolokia, but there’s no route for the broker.

You won’t get a helpful error message here, because any hostname that ends with the right domain will get connected to the OpenShift router. However, the router won’t know how to process the connection without a valid route, and will probably just return some sort of meaningless error packet to the JMS client.

If you’re trying to connect to the broker from another application in the same OpenShift namespace as the broker, you don’t need to connect via the router — just use the service name (presumably broker-amq-tcp) and service port explicitly in your JMS set-up.

If you’re connecting to the broker from another application in a different OpenShift namespace in the same cluster, you might be able to configure the networking subsystem to allow direct connections to the service across namespaces. This is, unfortunately, a little fiddly to set up after OpenShift is installed.

If you’re connecting to the broker from outside an OpenShift namespace, and you can’t use services directly, you’ll have to connect via a route, and you must use an encrypted connection. That’s not necessarily for security — the router will read the SNI information from the SSL header to work out how to route the request.

So you’ll need to create a service for the broker’s SSL port, create a route for that service, export server certificates from the broker, import those certificates into your client, and configure the client to use an SSL connection URI via the router. Clearly, using the service directly is easier, if you can 😉

All these set-up steps are described in Red Hat’s AMQ7-on-OpenShift documentation:

https://access.redhat.com/documentation/en-us/red_hat_amq/7.5/html/deploying_amq_broker_on_openshift/index

although I can’t deny that there’s an awful lot of information to wade through in that document.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement