socketio / socket.io-postgres-adapter

The Socket.IO Postgres adapter, allowing to broadcast events between several Socket.IO servers
https://socket.io
MIT License
24 stars 8 forks source link

when server 1 send message to server 2, not received ! im using postgres adapter, but in redis adapter work successfully #10

Closed andyresta closed 1 year ago

andyresta commented 1 year ago

using postgres adapter not receive message from another server, but successfully with redis adapter,

this my nginx load balance

server {
    listen 1300;
    server_name 10.175.10.24;
    location / {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $host;
      proxy_pass http://socketio;
      # enable WebSockets
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
    }
  }
upstream socketio {
    # enable sticky session with either "hash" (uses the complete IP address)
    hash $remote_addr consistent;
    # or "ip_hash" (uses the first three octets of the client IPv4 address, or the entire IPv6 address)
    # ip_hash;
    # or "sticky" (needs commercial subscription)
    # sticky cookie srv_id expires=1h domain=.example.com path=/;
    server 10.175.10.24:1100;
    server 10.175.10.24:1200;
  }

this my code in server 1

  const serverName = 'Socket PA Server 1';
const port = 1100;
const pool = new Client({
  user: "postgres",
  host: "10.175.10.24",
  database: "socket_service",
  password: "",
  port: 5434,
});
pool.query(`
  CREATE TABLE IF NOT EXISTS socket_io_attachments (
      id          bigserial UNIQUE,
      created_at  timestamptz DEFAULT NOW(),
      payload     bytea
  );
`);
const app = express();
const server = http.createServer(app);
const io = new Server(server,{
  cors: {
    wsEngine: eiows,
    origin: "*"
  }
});
io.adapter(createAdapter(pool));
server.listen(port, () => {
  console.log('listening on *:'+port);
});

this in server 2

const serverName = 'Socket PA Server 2';
const port = 1200;
const pool = new Client({
  user: "postgres",
  host: "10.175.10.24",
  database: "socket_service",
  password: "",
  port: 5434,
});
pool.query(`
  CREATE TABLE IF NOT EXISTS socket_io_attachments (
      id          bigserial UNIQUE,
      created_at  timestamptz DEFAULT NOW(),
      payload     bytea
  );
`);
const app = express();
const server = http.createServer(app);
const io = new Server(server,{
  cors: {
    wsEngine: eiows,
    origin: "*"
  }
});
io.adapter(createAdapter(pool));
server.listen(port, () => {
  console.log('listening on *:'+port);
});

and table in postgresql which name is socket_io_attachment is always empty, sending message to another server, the message not deliver..

can anyone fix ??

EDIT by @darrachequesne for readability

darrachequesne commented 1 year ago

The socket_io_attachments table is only used if the packet contains binary data or is above the 8000 bytes limit, so having an empty table might be normal.

Reference: https://socket.io/docs/v4/postgres-adapter/#how-it-works

The code you provided looks good to me, I was not able to reproduce the issue. Could you please check?

darrachequesne commented 1 year ago

Closed due to inactivity, please reopen if needed.