ruby-on-railsrubymessagingfayeprivate-pub

How can I find the number of current subscriptions using PrivatePub and Faye in rails


I am using a ruby gem called PrivatePub and this uses Faye to offer PubSub messaging

The PrivatePub gem offers a couple of view based helpers to subscribe / send a message to a particular topic. I am looking to extend PrivatePub to include an API call which will give me the ID of each of the current subscription objects connected to Faye. Can somebody explain how this can be achieved or help me find another way to work out all the current subscriptions from the PrivatePub api.


Solution

  • Since version 0.7, Faye includes an API for monitoring activity going on within the engine. This means you can attach event listeners to monitor the creation and destruction of client sessions, find out when clients subscribe and unsubscribe from channels, and watch published messages.

    You attach an event listener to your server like so:

    var bayeux = new Faye.NodeAdapter({mount: '/faye', timeout: 45})
    
    bayeux.on('handshake', function(clientId) {
      // event listener logic
    })
    

    The available events are:

    I hope that this helps