socketio / socket.io-adapter

The Socket.IO in-memory adapter
https://socket.io/
197 stars 101 forks source link

[Question] Could i use socket.io-adapter not for broadcast events between instances of the server? #77

Closed DisaPadla closed 2 years ago

DisaPadla commented 2 years ago

I'm developing a gateway on Nodejs for getting data from different microservices and send to the frontend. I get some data from RabbitMQ and I need to send this data via socket.io. I don't need to broadcast and emit events to and from instances of the server. I just need to get data from RabbitMQ and send it via socket. Should I use socket.io-adapter for this or write some custom solution? If I understood correctly, socket.io-amqp broadcast data between instances and have an old version of socket.io dependencies (i use the latest version of socket.io). So, this solution does not suit me.

Another question: could i use several adapters (redis-adapter and custom rabbitmq adapter)?

darrachequesne commented 2 years ago

In the Socket.IO terminology, an Adapter is a server-side component which is responsible for broadcasting events to all or a subset of clients:

image

Reference: https://socket.io/docs/v4/adapter/

I just need to get data from RabbitMQ and send it via socket

In that case, I think the easiest way is to plug your RabbitMQ to your Socket.IO server, and then call io.emit() to broadcast the packets to the connected clients.

could i use several adapters?

I'm not sure to understand your use case, but I'd say no, you can only use the same type of adapter for all your Socket.IO servers.

DisaPadla commented 2 years ago

Thanks for the answer.

In that case, I think the easiest way is to plug your RabbitMQ to your Socket.IO server, and then call io.emit()to broadcast the packets to the connected clients.

So, I don't need to use the adapter, correct?

I'm not sure to understand your use case, but I'd say no, you can only use the same type of adapter for all your Socket.IO servers.

I mean, what if I want to use rabbitmq adapter and redis adapter for all my servers. Is it possible? Or every next call io.adapter() will rewrite the previous adapter?