简体   繁体   中英

Push Message through JSON RPC vs SignalR/Node.JS

I am using pull mechanism for my web services. Now we want to move towards push mechanism. I am aware of SignalR and NodeJS for that purpose.

Someone also mentioned JSON RPC. I have very little knowledge about it and searching google didn't yield me the result weather I can use this for push mechanism.

Also, its worth noting that my client of the web-service is completely JavaScript client. No server side language.

Thanks

It depends what you mean by "push".

I am using pull mechanism for my web services. Now we want to move towards push mechanism. I am aware of SignalR and NodeJS for that purpose.

To most people, "push" just means that a publish/subscribe model is used to set up advance expectation of data to be sent from the server to the client at some unknown time(s) in the future.

As you say you're doing JavaScript in a browser, then you have all the inherent limitations that arise from that environment. Various implementations of asynchronous bi-directional communications in browsers (eg: WebSockets , WebRTC ) and even some push-like technologies ( Comet ) have been implemented.

True "push" relies on the ability for the server to send messages to clients over the network, which doesn't work well; clients mostly don't allow incoming connections, many clients are behind NAT.

Is there someone pushing this agenda that perhaps doesn't understand the technical considerations? Why "push"? Usually this kind of discussion centres around reducing resources on the server (eg: open sockets). Is that what's going on here? What's the background?


Someone also mentioned JSON RPC. I have very little knowledge about it and searching google didn't yield me the result weather I can use this for push mechanism.

The JSON-RPC protocol is simply a protocol (agreed way) of sending JSON via some bi-directional communications channel between two hosts.

The JSON-RPC protocol does describe " notification "-type messages which don't (in theory) require solicitation via a "request-response" messaging. eg:

  • a client could send a "notification" message to the server
  • a server could send a "notification" message to the client

(Reading the spec, it seems focussed on client to server "notifications", but in earlier drafts/discussions that wasn't the case and JSON-RPC certainly isn't the most standards oriented community out there :-)


Also, its worth noting that my client of the web-service is completely JavaScript client. No server side language.

Implemenations of JSON-RPC are greatly constrained by their transport protocols. (eg: HTTP).

When implemented over plain HTTP (such as via XMLHttpRequest ) there's no way for the server to contact the client outside of a response to some prior request -- that means that while client-server "notification" messages are possible, server-client "notification" (push-like) messages are not.

When implemented over a TCP socket (not available in a browser) then it's absolutely possible for the server to send "notification" messages to the client (as long as the socket is open, and the client is prepared to asynchronously process recieved messages outside of an RPC-like request-response cycle).


If you implement JSON-RPC over some pre-existing browser-based asynchronous bi-directional transport protocol (WebSockets, WebRTC) instead of AJAX, then you can get pretty close to proper JSON-RPC bi-directional "notification" messages. 如果您通过某种预先存在的基于浏览器的异步双向传输协议(WebSockets,WebRTC)而不是AJAX来实现JSON-RPC,那么您可以非常接近正确的JSON-RPC双向“通知”消息。 In both cases, some advance setup is required, but as you're talking about "push", then that's expected anyway (pubsub).

Another way to do it would be to have the client poll for batches of notifications (standard request/response style messages), which might come back as an empty array, or could be 1 or more "notification" sub-messages. 另一种方法是让客户端轮询一批通知(标准请求/响应样式消息),这些通知可能以空数组形式返回,或者可能是一个或多个“ notification”子消息。

Neither of these browser-based approaches are truly "push" as they don't eliminate the need for some underlying ongoing client to server to server (request-response) communications.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM