#multiple gateways pattern

1 messages · Page 1 of 1 (latest)

limpid trench
#

I'm building a NestJS application where I wanted multiple WebSocket gateways for different features (finance, chat, notifications). I need clarification on the following architectural details:

When multiple @WebSocketGateway() decorators are used without specifying a port (or with the same port), how does NestJS handle the underlying Socket.IO server instance? Is a single server instance shared across all gateways?
If I have three gateways with different namespaces like this:

@WebSocketGateway({ namespace: 'finance' })
...
@WebSocketGateway({ namespace: 'chat' })
..
@WebSocketGateway({ namespace: 'notifications' })

Does a client connecting to the 'finance' namespace automatically have access to 'chat' and 'notifications', or must they explicitly connect to each namespace separately?
From a network perspective, when using multiple namespaces on the same port, does Socket.IO multiplex these over a single WebSocket connection, or does each namespace create its own WebSocket connection?
If I want to share authentication logic across all gateways/namespaces, should I:

a) Implement authentication in each gateway's handleConnection method
b) Use a custom IoAdapter with middleware
c) Use NestJS Guards on each gateway

tawdry jewelBOT
#

We have generated a response to your question, but it is too long to be sent as a single message. Please check the response attached as a file.