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

9
flask_backend/Dockerfile Normal file
View File

@@ -0,0 +1,9 @@
FROM python:3.11-slim
WORKDIR /app
COPY ../requirements.txt .
RUN pip install --no-cache-dir -r ../requirements.txt
COPY . .

14
flask_backend/Sender.py Normal file
View File

@@ -0,0 +1,14 @@
import json
from Stomp_client import get_connection
QUEUE_NAME = "/queue/testQueue"
def send_to_queue(payload: dict):
"""
Posílá JSON payload do ActiveMQ queue, přijíma dic
"""
conn = get_connection() # připojení s retry loop
conn.send(destination=QUEUE_NAME, body=json.dumps(payload))
print("Message sent to ActiveMQ:", payload)
conn.disconnect()

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

20
flask_backend/app.py Normal file
View File

@@ -0,0 +1,20 @@
from flask import Flask, request, jsonify
from Sender import send_to_queue
app = Flask(__name__)
@app.route("/send", methods=["POST"])
def send():
# očekává JSON payload
payload = request.get_json()
if not payload:
return jsonify({"error": "No JSON payload provided"}), 400
try:
send_to_queue(payload) # voláme funkci z sender.py
return jsonify({"status": "ok"}), 200
except Exception as e:
return jsonify({"error": str(e)}), 500
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)

View File

@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Upload the </h1>
<form action="/manage/John" method="post">
<button type="submit">Manage John</button>
</form>
<form action="/page/Jane" method="post">
<button type="submit">Go to Jane's Page</button>
</form>
{{ message }}
</body>
</html>