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

Broadcasting with Clustered Configuration #72

Description

@AddoSolutions

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions