Sticky sessions for socketIO nodejs app deployed on Google Cloud App Engine

789 Views Asked by At

I need someone to explain how I can get socketIO client to connect successfully with nodeJs app deployed to Google Cloud App Engine.

I setup nodejs clusters and so had to use socketIO's redis adapter to manage session affinity.

This has worked fine till I deployed to Gcloud App Engine.

Here is my current socketIO implementation on the server-side:

const { Server } = require("socket.io");
const redisAdapter = require("socket.io-redis");
const { setupMaster, setupWorker } = require("@socket.io/sticky");


const io = new Server(server, {
  pingTimeout: 60000,
  transports: ["websocket"],
  cors: {
    origin: "*",
    methods: ["GET", "POST", "DELETE", "PATCH"],
    allowedHeaders: ["Access-Control-Allow-Origin"],
    credentials: true,
  },
});
io.adapter(
     redisAdapter({
       host: process.env.REDISTOGO_URL,
       port: 15156,
       password: process.env.REDIS_PASSWORD,
     })
   );

setupWorker(io);
console.log("Redis socket Connected");

I am quite new to gcloud and so I will be very grateful for any help I can get. I have tried undoing the nodejs clusters but still doesn't work.

0

There are 0 best solutions below