Simultaneously receive logs from Rabbitmq and run your flash drive app
I have rabbitmq installed and running and I know how to get the logs but dont know how to show it in the jar UI.
flask_app.py
from flask import Flask
from threading import Thread
app = Flask(__name__)
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.exchange_declare(exchange='logs',
type='fanout')
result = channel.queue_declare(exclusive=True)
queue_name = result.method.queue
channel.queue_bind(exchange='logs',
queue=queue_name)
print('[*] Waiting for logs. To exit press CTRL+C')
def callback(ch, method, properties, body):
print(body)
channel.basic_consume(callback,
queue=queue_name,
no_ack=True)
thread = Thread(channel.start_consuming())
thread.start()
@app.route('/')
def index():
return 'hi'
I don't know how to use multithreading to run a flash application and get logs from the queue all the time.
source to share
Your flask application, in this case the main thread, runs for a specific amount of time or number of requests, determined by your uwsgi or whatever means you use to start it. When the main process stops, it will most likely not be the right time to gracefully close the amqp connection.
Moreover, there can be multiple instances of your application running at the same time (like uwsgi processes
), so you can get bit of logs for each worker / process.
A sensible approach here is to separate the two. Start a consumer process for your logs outside the scope of your web application, that is: with a supervisor.
source to share