Closed wkedz closed 1 year ago
This is how you do it:
mgr = ManagerClass("your", "arguments", "here")
socketio = SocketIO(client_manager=mgr)
All you need to do is pick a manager class that does what you need. I assume the RedisManager
or KombuManager
classes are what makes more sense to adapt it to work with a cluster, but I'm not sure if you can make this work just by adding extra arguments. Worst case you need to create a custom class that inherits from these and makes the necessary changes to work with a cluster.
Hi @miguelgrinberg
I pass the manager through client_manager
and it works as it should.
Code:
app.logger.info(f"Connecting SocketIO to redis at {REDIS_HOST}")
url = REDIS_HOST # self.server_options.get('message_queue', None)
channel = "flask-socketio" # self.server_options.pop('channel', 'flask-socketio')
connection_options={"transport_options" : {"master_name":"mymaster"}}
write_only = False # app is None
client_manager = socketio.KombuManager(url=url, channel=channel, write_only=write_only, connection_options=connection_options)
sio = SocketIO(app, client_manager=client_manager, logger=True, engineio_logger=True)
Logs:
[2023-04-26 11:01:25,031] INFO in server: Connecting SocketIO to redis at sentinel://0.0.0.0:26379
Server initialized for eventlet.
h2j59VBXCfZbUIPRAAAA: Sending packet OPEN data {'sid': 'h2j59VBXCfZbUIPRAAAA', 'upgrades': ['websocket'], 'pingTimeout': 20000, 'pingInterval': 25000}
kombu backend initialized.
h2j59VBXCfZbUIPRAAAA: Received packet MESSAGE data 0{}
h2j59VBXCfZbUIPRAAAA: Sending packet MESSAGE data 0{"sid":"cI-uIDemeBQ6rEnlAAAB"}
pubsub message: emit
h2j59VBXCfZbUIPRAAAA: Sending packet MESSAGE data 2["my event",{"data":1}]
pubsub message: emit
h2j59VBXCfZbUIPRAAAA: Sending packet MESSAGE data 2["my event",{"data":2}]
Thanks for your help!
Closing, because there is no need to pass additional args to SocketIO.
Hi!
I would like to use SocketIO with a redis sentinel cluster. Unfortunately, right now this is not possible, because I cannot pass additional arguments to queue managers - https://github.com/miguelgrinberg/Flask-SocketIO/blob/main/src/flask_socketio/__init__.py#L200
Is your feature request related to a problem? Please describe.
Yes, my problem is related to one issue that is now closed. https://github.com/miguelgrinberg/Flask-SocketIO/issues/359 I think that it shouldn't.
Basically, all implementation is already provided in python-socketio https://github.com/miguelgrinberg/python-socketio/commit/7dbc47049a605f78d795b6f59d458522d67c6fe6
Describe the solution you'd like
I need to SocketIO to pass additional arguments to managers. For example something like this
Describe alternatives you've considered
I don't think that there are any alternatives.
Logs