Flask-SocketIO + RabbitMQ #1735
-
Hi @miguelgrinberg, I am trying to use Flask-SocketIO in combination with RabbitMQ. However it seems like the flask server gets stuck on a client connect event. I added debug logging to socketio-client, socketio-server and rabbitmq. However it still not clear to me why the response from the server to the client is not received. If I run the example bellow without the message broker it works fine. The setuppip freeze
server.py from flask import Flask
from flask_socketio import SocketIO, emit
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app, message_queue='amqp://guest:guest@localhost:5672/test', logger=True, engineio_logger=True)
@app.route('/')
def index():
return {'msg': 'hello'}
@socketio.event
def my_event(message):
emit('my response', {'data': 'got it!'})
if __name__ == '__main__':
socketio.run(app, debug=True, port=5000) client.py import socketio
sio = socketio.Client(engineio_logger=True, logger=True, request_timeout=5)
@sio.event
def connect():
print("I'm connected!")
@sio.event
def connect_error(data):
print(f'data={data}')
print("The connection failed!")
@sio.event
def disconnect():
print("I'm disconnected!")
sio.connect('http://localhost:5000') I am using the docker image version of Rabbit MQ and run this as: Outputs
Server initialized for eventlet.
* Restarting with stat
Server initialized for eventlet.
* Debugger is active!
* Debugger PIN: 145-203-696
(9884) wsgi starting up on http://127.0.0.1:5000 I can also reach the endpoint
At the server the following logs are added:
At this point the server seems to be stuck, as it will not handle my request to In the logs of RabbitMQ:
Any help / clue would be much appreciated. Edit: formatting |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Well, you are using eventlet, so RabbitMQ is going to be blocking unless you monkey patch the Python standard library. See https://flask-socketio.readthedocs.io/en/latest/deployment.html#using-multiple-workers |
Beta Was this translation helpful? Give feedback.
Well, you are using eventlet, so RabbitMQ is going to be blocking unless you monkey patch the Python standard library. See https://flask-socketio.readthedocs.io/en/latest/deployment.html#using-multiple-workers