Skip to content
This repository has been archived by the owner on Sep 27, 2021. It is now read-only.

Broadcasting with Clustered Configuration #72

Open
AddoSolutions opened this issue Dec 26, 2018 · 2 comments
Open

Broadcasting with Clustered Configuration #72

AddoSolutions opened this issue Dec 26, 2018 · 2 comments

Comments

@AddoSolutions
Copy link

Package version

    "@adonisjs/ace": "^5.0.8",
    "@adonisjs/auth": "^3.0.7",
    "@adonisjs/bodyparser": "^2.0.5",
    "@adonisjs/cli": "^4.0.9",
    "@adonisjs/cors": "^1.0.7",
    "@adonisjs/fold": "^4.0.9",
    "@adonisjs/framework": "^5.0.9",
    "@adonisjs/ignitor": "^2.0.8",
    "@adonisjs/lucid": "^6.1.3",
    "@adonisjs/session": "^1.0.27",
    "@adonisjs/shield": "^1.0.8",
    "@adonisjs/vow": "^1.0.17",
    "@adonisjs/websocket": "^1.0.11",
    "@adonisjs/websocket-client": "^1.0.9",

Node.js and npm version

$npm -v
6.4.1
$ node -v
v11.1.0

Sample Code (to reproduce the issue)

server.js (straight out of the textbook)

const cluster = require('cluster')

if (cluster.isMaster) {
  for (let i=0; i < 4; i ++) {
    var worker = cluster.fork();
  }
  require('@adonisjs/websocket/clusterPubSub')()
  return
}

//console.log(cluster.worker.id)

const { Ignitor } = require('@adonisjs/ignitor')

new Ignitor(require('@adonisjs/fold'))
  .appRoot(__dirname)
  .wsServer()
  .fireHttpServer()
  .catch(console.error)

socket.js

Ws.channel('dispatch:*', 'DispatchController').middleware('auth')

DispatchController.js

class DispatchController {
  constructor ({ socket, request, auth }) {
    this.socket = socket
    this.request = request
    this.auth = auth
  }

  async onLocationUpdate(location){
    
    // Have tried like this
    this.socket.broadcast('updated:location',location);

    // And like this
    Ws
      .getChannel('dispatch:*')
      .topic('dispatch:3')
      .broadcast('updated:location',location);
  }

}

In the above example, I have n devices connected, and each device is broadcasting data once every 3 seconds. The information is then distributed to every other connected device. The trouble is once clustering is enabled, this ceases to work, and nobody get's each others messages.

Any ideas what I am doing wrong here, or if this is a bug?

Thanks!

@hlozancic
Copy link

This is a bug.
It's being fixed as I know...
https://discordapp.com/channels/423256550564691970/423264181110702080/515156749813153792

@Brunomm
Copy link

Brunomm commented Mar 26, 2019

I realized that this problem still persists.
Any alternative to get around the problem?

@thetutlage thetutlage removed the triage label Nov 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants