Giter VIP home page Giter VIP logo

Comments (4)

goriunov avatar goriunov commented on May 18, 2024

The channels are designed to have more then just 1 subscriber (you can have only one subscriber as well). It does not matter on which worker will the channel end up as pub sub system is designed to be able to send message from any server to the right channel.

One way to listen on the publish event on the server is onPublish event documentation is in here. However i am not sure it will work out well as publish system will not process with message if no client on that worker subscribed to that channel. (i need more information about the app and how you plan it to work)

Second way is to use onMessageFromWorker from the same documentation in here and standard 1on1 communication with client. For example:

function Worker() { 
    const wss = this.wss
    const server = this.server 
     
    // listen on messages from workers
     wss.setMiddleware('onMessageFromWorker', (message) => {
          // execute any code on message form workers
     })

    // Listen on connections to websocket server
    wss.on('connection', (socket) => {
        socket.on('matchmaking', (message) => {
          // send message to all workers  NOTE: including itself
           wss.publishToWorkers(message)
         })
    })
}

That is actually a good point you have provided, i will add functionality to subscribe workers to the channels (only with ability to listen on messages which are send through the channels)

from clusterws.

Danielv123 avatar Danielv123 commented on May 18, 2024

Yeah, I found the publishToWorkers while toying around with the problem. It works, but it feels like a dirty hack and its not very readable. I am glad this functionality is coming though 👍

from clusterws.

goriunov avatar goriunov commented on May 18, 2024

I have released new version 3.1.0 the functionality to listen on channels is added there. Check this for more info about it.

from clusterws.

goriunov avatar goriunov commented on May 18, 2024

Close issue as completed.

from clusterws.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.