Unable to connect python container to activeMQ Artemis container

Unable to connect python container to activeMQ Artemis container

Questions : Unable to connect python container to activeMQ Artemis container

613

My end goal is to have several Python in4codes_docker containers running different processes in4codes_docker communicate to each other via an ActiveMQ in4codes_docker Artemis container. I’m new to all of this, in4codes_docker so as a start, I’m just trying to get a in4codes_docker proof of concept running.

I followed instructions from this youtube in4codes_docker video to build my image of Artemis and in4codes_docker everything jives nicely there. I also in4codes_docker followed this tutorial to get started in4codes_docker sending messages via stomp to Artemis. When in4codes_docker I run this script locally (from PyCharm) in4codes_docker while my Artemis container is up and in4codes_docker running, I can see in the web console that in4codes_docker there is a new generated queue from the in4codes_docker python script. However, when I containerize in4codes_docker the same Python script, I get an error

Could not connect to host localhost, port 61613 Could not connect to host localhost, port 61613 Could not connect to host localhost, port 61613 Traceback (most recent call last): File "/code/./main.py", line 5, in <module> import sendAMessage File "/code/sendAMessage.py", line 30, in <module> conn.connect('admin', 'admin', wait=True) File "/usr/local/lib/python3.9/site-packages/stomp/connect.py", line 164, in connect self.transport.start() File "/usr/local/lib/python3.9/site-packages/stomp/transport.py", line 109, in start self.attempt_connection() File "/usr/local/lib/python3.9/site-packages/stomp/transport.py", line 819, in attempt_connection raise exception.ConnectFailedException() 

I tried setting up a network in docker and in4codes_docker putting both containers onto it. I’m running in4codes_docker my python container using

docker run --rm --net my-network -p 5000:5000 myimage 

I have a feeling I’m incorrectly exposing a in4codes_docker port, or something silly like that, but I’m in4codes_docker just not quite familiar enough with in4codes_docker containers to know where to start looking.

Total Answers 2
29

Answers 1 : of Unable to connect python container to activeMQ Artemis container

The python script is working from your in4codes_activemq-artemis local host because the -p 5000:5000 in4codes_activemq-artemis parameter exposes the port 5000 of the in4codes_activemq-artemis ActiveMQ Artemis container on the in4codes_activemq-artemis localhost. To reach the ActiveMQ Artemis in4codes_activemq-artemis container from another container in the in4codes_activemq-artemis same docker network (–net my-network) in4codes_activemq-artemis the python script should use the in4codes_activemq-artemis ActiveMQ Artemis container name (–name in4codes_activemq-artemis my-artemis), i.e.

docker run --rm --name my-artemis --net my-network -p 5000:5000 myimage 

Docker makes deploying microservice in4codes_activemq-artemis applications very easy but it has some in4codes_activemq-artemis limitations for a production in4codes_activemq-artemis environment. I would take a look to the in4codes_activemq-artemis open source ArtemisCloud.io project, it in4codes_activemq-artemis is a collection of container images that in4codes_activemq-artemis provide a way to deploy the Apache in4codes_activemq-artemis ActiveMQ Artemis Broker on Kubernetes.

0

4

Answers 2 : of Unable to connect python container to activeMQ Artemis container

masseyb’s answer helped point me the in4codes_activemq-artemis right way.

The way I fixed it was getting the IP in4codes_activemq-artemis address of my ActiveMQ container (docker in4codes_activemq-artemis network inspect) and putting that in the in4codes_activemq-artemis .py script instead of ‘localhost’.

hosts = [('172.19.0.2', 61613)] 

0