derbyjs / racer

Realtime model synchronization engine for Node.js
1.18k stars 117 forks source link

How can I use app.model.channel with new derby@8.0.0 #241

Closed kolegm closed 8 years ago

kolegm commented 8 years ago

On the client/server before (during the derby.js v6.*) could use the channel as set forth in this document derby-faq

Now, is not possible to do it.

You always will get an error on the client: TypeError: app.model.channel is undefined code app.model.channel.send

And on the server - TypeError: Cannot call method 'on' of undefined code client.channel.on

Please, help me to resolve the problem - communication between client-server or server-client.

As I saw the changes which have been done recently for racer, channel object was removed. I can not understand what I should use instead on the client/server side.

cjblomqvist commented 8 years ago

Not a full answer, but I wrote this in the gitter channel:

Since RPC through model.channel was removed with 0.8, there's no clear way to do RPC (AFAIK) with proper acknowledging, etc. I looked into it and found out that one can actually piggyback quite conveniently on share queries. Now, we don't have a generic implementation (for any kind of RPC-call) but as a reference, feel free to look at: https://github.com/BBWeb/derby-ar/blob/master/lib/rpc.js for how we did it. By using share queries, we get automatic retries on connection failures which is quite neat. Just FYI if anyone needs RPC and doesn't want to look into and think through all the difference ways to do it.

If you need any help with doing RPC this way I'd be happy to assist (either find me in the gitter channel or ask questions here). Eventually I might wrap up the stuff that is RPC-only (not the derby-ar -related stuff) into a separate lib so that others (like you) can re-use it.

Another way to do RPC is by simple AJAX messages and server-side express routes.

kolegm commented 8 years ago

It is very strange situation.

Model/client channels - it is one criterion among others choose Derby as a main technology for our frontend-service.

We use the next strategy: the Derby-client emits (channel usage) some event on the Derby-server, which handle it and tries to retrieve data from the external backend-service, and quickly returns data to the Derby-client. Such behaviour opens the real Derby power and allows us to build distributed system.

Very sorry that the model channels have been removed without the provision of decent alternatives.

By the way, derby@0.6.0-alpha61 - last workable version which we are using correctly with all important dependencies. There are a lot of bugs at the next versions. I tried upgrade to the last derby@0.8.0, and unworkable channels - are the last errors that I could not fix.

I'm not sure that your solution with new rpc will help me, but i want you to create the independent RPC-stuff.

cjblomqvist commented 8 years ago

@kolegm - see https://github.com/bbweb/racer-rpc for a fully working RPC solution for derby^0.8.0. It should work quite reliably.

Note that this does not equal emitting events among clients. I.e. one limitation of the racer-rpc lib is that you can only attach one listener backend to each message. I'm not sure exactly how this worked previously (haven't looked into it), but since you expect results from an RPC you can't have more than one function return results (that would be very weird; to trigger one RPC and get back results from multiple functions).

If you want that kind of behavior, you can fiddle around with the connection in share, which also handles this on a client basis (compared to racer-rpc which handles it on a backend-basis). I think that should be a separate lib if one needs such behavior as it's not really compatible with RPC functionality.

cjblomqvist commented 8 years ago

By the way, I think this issue can be closed since there now is an answer to how to do this. @distracteddev - imo you can close this issue (unless @kolegm has any other opinions). If one wants to know how to do transparent client/server side events (i.e. not calls), then another issue should probably be opened.

kolegm commented 8 years ago

I updated my project successfully a few days ago. derby@0.6.0-alpha61 => derby@0.8.5

Thanks @cjblomqvist for assistance.

related issue

cjblomqvist commented 8 years ago

My pleasure! :)