This commit is contained in:
2025-10-17 00:09:26 +02:00
parent 2aa8d98aa1
commit aa033aafbe
15 changed files with 357 additions and 0 deletions

View 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