-1

I am having a problem, I am unable to connect to an online activemq broker on amazon mq. This is my code +++++++++++++++++++++++++++++++++++

import time
import sys
import os
import stomp
from stomp import *
#import pika

user = os.getenv("admin")
password = os.getenv("password")
host = os.getenv("stomp+ssl://online_host:61614")
port = os.getenv("61614")
destination = sys.argv[1:2] or ["/topic/event"]
destination = destination[0]

messages = 1000
data = "Hello World from Python"
conn = stomp.Connection(host_and_ports=[(host, port)])
#conn.set_listener('print', PrintingListener())
#conn.start()
conn.connect(login=user, passcode=password)

for i in range(0, messages):
    conn.send(data, destination=destination, persistent='false')

conn.send("SHUTDOWN", destination=destination, persistent='false')

conn.disconnect(receipt=None)

++++++++++++++++++++++++++++++++++++++++++++++++ Can you please help me out. I am getting an error as ++++++++++++++++++++++++++++++++++++ Could not connect to host None, port None Traceback (most recent call last): File "C:\Users\navee\PycharmProjects\apachekafka\venv\lib\site-packages\stomp\transport.py", line 730, in attempt_connection self.socket = socket.create_connection(host_and_port, self.__timeout) File "C:\Users\navee\AppData\Local\Programs\Python\Python38-32\lib\socket.py", line 787, in create_connection for res in getaddrinfo(host, port, 0, SOCK_STREAM): File "C:\Users\navee\AppData\Local\Programs\Python\Python38-32\lib\socket.py", line 914, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno 11001] getaddrinfo failed Could not connect to host None, port None Traceback (most recent call last): File "C:\Users\navee\PycharmProjects\apachekafka\venv\lib\site-packages\stomp\transport.py", line 730, in attempt_connection self.socket = socket.create_connection(host_and_port, self.__timeout) File "C:\Users\navee\AppData\Local\Programs\Python\Python38-32\lib\socket.py", line 787, in create_connection for res in getaddrinfo(host, port, 0, SOCK_STREAM): File "C:\Users\navee\AppData\Local\Programs\Python\Python38-32\lib\socket.py", line 914, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno 11001] getaddrinfo failed Could not connect to host None, port None Traceback (most recent call last): File "C:\Users\navee\PycharmProjects\apachekafka\venv\lib\site-packages\stomp\transport.py", line 730, in attempt_connection self.socket = socket.create_connection(host_and_port, self.__timeout) File "C:\Users\navee\AppData\Local\Programs\Python\Python38-32\lib\socket.py", line 787, in create_connection for res in getaddrinfo(host, port, 0, SOCK_STREAM): File "C:\Users\navee\AppData\Local\Programs\Python\Python38-32\lib\socket.py", line 914, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno 11001] getaddrinfo failed Traceback (most recent call last): File "act_prod.py", line 20, in conn.connect(login=user, passcode=password) File "C:\Users\navee\PycharmProjects\apachekafka\venv\lib\site-packages\stomp\connect.py", line 161, in connect self.transport.start() File "C:\Users\navee\PycharmProjects\apachekafka\venv\lib\site-packages\stomp\transport.py", line 104, in start self.attempt_connection() File "C:\Users\navee\PycharmProjects\apachekafka\venv\lib\site-packages\stomp\transport.py", line 803, in attempt_connection raise exception.ConnectFailedException() stomp.exception.ConnectFailedException

+++++++++++++++++++++++++++++++++++++++++++++++

2 Answers2

0

I too have a similar issue. Tried the following. Unable to connect to MQ broker using STOMP in python

Didn't work for me though..!! Cheers..!

thejasviks
  • 11
  • 3
  • Don't post solutions as link: they might become broken making your answer completely useless! Summarize here its main contents, instead (with your own words, avoiding to plagiarize the source). – Roberto Caboni Feb 11 '20 at 08:17
0

Looking at your logged error:

'Could not connect to host None, port None'

It looks like your env vars for host and port do not exist.

besides,

you should call conn.set_ssl when communicating over ssl

conn.set_ssl(for_hosts=[(host, port)])

and also set wait arg when connecting, so you won't try to send before connected successfuly

conn.connect(login=user, passcode=password, wait=True)
gilp
  • 571
  • 2
  • 6
  • 19