You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
createIOServer(port: number, options?: ServerOptions): any {
const server = super.createIOServer(port, options);
server.adapter(this.adapterConstructor);
return server;
}
}
The problem is that, when I use more than one replica, sometimes, the socket which is connected (or tries to connect) is null or undefined, so I cannot perform operations.
Maybe I'm missing something.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
This is my docker-compose:
services:
chat-api:
build: .
ports:
- "3004-3006:3005"
depends_on:
- redis
environment:
CHAT_GATEWAY_REDIS_URL: redis://redis:6379
CHAT_GATEWAY_PORT: "3005"
CHAT_REDIS_CACHE_HOST: redis
CHAT_REDIS_CACHE_PORT: 6379
CHAT_REDIS_QUEUE_HOST: redis
CHAT_REDIS_QUEUE_PORT: 6379
deploy:
replicas: 2
restart: on-failure
redis:
image: redis
ports:
- "6379:6379"
deploy:
replicas: 1
and my redis adapter, taken from NestJs doc:
import { IoAdapter } from "@nestjs/platform-socket.io";
import { ServerOptions } from "socket.io";
import { createAdapter } from "@socket.io/redis-adapter";
import { createClient } from "redis";
export class RedisAdapter extends IoAdapter {
private adapterConstructor: ReturnType;
async connectToRedis(): Promise {
const pubClient = createClient({
url: process.env.CHAT_GATEWAY_REDIS_URL ||
redis://localhost:6379
,});
const subClient = pubClient.duplicate();
}
createIOServer(port: number, options?: ServerOptions): any {
const server = super.createIOServer(port, options);
server.adapter(this.adapterConstructor);
return server;
}
}
The problem is that, when I use more than one replica, sometimes, the socket which is connected (or tries to connect) is null or undefined, so I cannot perform operations.
Maybe I'm missing something.
Beta Was this translation helpful? Give feedback.
All reactions