Search code examples
ruby-on-railsrubynode.jsfaye

how to secure faye message to be received by client?


I am using Faye to send messages to subscriber. I need to secure the message be received by the subscriber but I know there is a possiblity that faye messages being lost in the network. For example if the subscriber is not online, the message cannot be received...

My question is: is there a way that the Faye server knows that the message has been received by the subscriber if it knows some kind of the identity of the subscriber. Or is there a protocol that can be used in place of Faye and also ensure the message's security?


Solution

  • Faye doesn't support durable messages, so you need to roll your own. One way is to wrap your messages with JSON and use a time stamp for each message. Then, when the subscriber connects, it would send a message to the publisher/producer requesting all messages after it's last valid timestamp. The server would have to save critical messages and re-send on request. And, the other consumers would have to ignore messages that were earlier than there last valid time stamp.

    The JSON wrapper would look something like this:

    {
        ts: 1408628582074,
        version: "1.0",
        message:{
            "alert":"producer is now active..."
        }
    }
    

    Where the "message" node could be any object, including a string.

    There is an open source node project based on Faye that will help you with this here.