saved
This commit is contained in:
25
flask_backend/Stomp_client.py
Normal file
25
flask_backend/Stomp_client.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import stomp, os, time
|
||||
|
||||
MQ_HOST = os.getenv("MQ_HOST", "activemq")
|
||||
MQ_PORT = int(os.getenv("MQ_PORT", 61613))
|
||||
MQ_USER = os.getenv("MQ_USER", "admin")
|
||||
MQ_PASS = os.getenv("MQ_PASS", "admin")
|
||||
|
||||
def get_connection(listener=None):
|
||||
"""
|
||||
Vrací připojený STOMP Connection objekt.
|
||||
Pokud listener je None, připojení bude bez listeneru.
|
||||
"""
|
||||
conn = stomp.Connection12([(MQ_HOST, MQ_PORT)])
|
||||
if listener:
|
||||
conn.set_listener("", listener)
|
||||
|
||||
while True:
|
||||
try:
|
||||
conn.connect(MQ_USER, MQ_PASS, wait=True)
|
||||
print("Connected to ActiveMQ")
|
||||
break
|
||||
except Exception as e:
|
||||
print("Waiting for ActiveMQ to be ready...", e)
|
||||
time.sleep(3)
|
||||
return conn
|
||||
Reference in New Issue
Block a user