Wednesday 15 January 2020

What are best practices for establishing database connection in a Websocket Server

I've implemented a websocket server (actually in Swoole+PHP). This server is subscribed to events coming from RabbitMQ. When a new event comes in, the server must parse it, check whether it is a notification event, then the server needs to find this notification recipients in the database and push this notification to correpsonding recipients, if they are connected to this websocket server.

Currently, I have a bootstrap procedure which is responsible for all dependency injection, including database connection, and for starting up the websocket server. So, when my service is up, it establishes database connection and starts the websocket server. I tend to think, that I'm doing something wrong and that instead of one single database connection for the whole websocket server, I should establish it every time, when I need to go to the database.

So, my question is, what are best practices for establishing database connection inside a websocket server? And should this database interaction be asynchronous?



from What are best practices for establishing database connection in a Websocket Server

No comments:

Post a Comment