js-data / js-data-examples

Example client-side and server-side apps that use various combinations of js-data and its adapters.
MIT License
40 stars 15 forks source link

RethinkDB example not suitable for a multi-node cluster #4

Open analytik opened 9 years ago

analytik commented 9 years ago

Hi,

First of all, thanks for the sample! It's helping me to kickstart a project. However, if someone would run more than one replica of the socket.io server, horrible things would start happening, as instead of using a RethinkDB changefeed - which is one of the main reasons why people use RethinkDB in the first place - it just emits a message with changes which the specific server received. For example,

So all calls like messageService.sendCreateMessage('post', post); should be removed, and socket.io connection needs to be replaced with something like

function on_user_connected( ... ) {
    r.table("posts").changes().run(rConnection).then(function(cursor) {
        cursor.each(function (err, item) {
            ioServer.emit('post created or deleted or updated', JSON.stringify(item, null, 2));
        }
    };
}

I haven't worked up a specific solution yet, but I might post a more specific sample later.

jmdobry commented 9 years ago

I'm looking forward to your pull request :)

analytik commented 9 years ago

Heh. I'll see what I can do, I just wanted to make sure I'm not misunderstanding something about the application's design, as I'm new to Express. :)