resgateio / resgate

A Realtime API Gateway used with NATS to build REST, real time, and RPC APIs, where all your clients are synchronized seamlessly.
https://resgate.io
MIT License
685 stars 67 forks source link

Is it possible to use with NATS RPC #126

Closed kulak closed 4 years ago

kulak commented 4 years ago

I am using NATS RPC project to simplify development of services: https://github.com/nats-rpc/nrpc

Is there a way to use Resgate project with NRPC NATS communication model?

I'd prefer Resgate to manual mapping.

jirenius commented 4 years ago

From a quick look at NRPC:

Compared with Resgate:

The reason why Resgate is using JSON instead of Protobuf is (primarily) because it needs to be able to decode responses and events to populate and update its cache, without having to configure it with .proto files for each time a service changes.

I can see a few alternative answers to your question.

Have Resgate act as an NRPC gateway

Description
The (web)client connects to Resgate and makes requests either over WebSocket or HTTP. Resgate would turn it into an NRPC request over NATS, and then relay the response back to the client.

Conclusion
No. An NRPC specific gateway is the way to go in such a case. Resgate does this already with the JSON based RES protocol, but it would require quite a lot to add NRPC to it.

Use NRPC for internal and Resgate for external

Description
Service-to-service would go over NRPC while client-to-service requests comes over Resgate.

Conclusion
Yes. This should be doable. It shouldn't be too hard writing a Middleware for go-res that wraps nrpc methods to Resgate resource methods. But is it really a good idea to have a service expose the same API with two different protocols? Maybe.

Use RES protocol for both internal and external

Description By dropping NRPC and use RES protocol for both service-to-service and client-to-service communication. This was not part of the question, but worth mentioning.

Conclusion Yes, but not yet. You get some overhead of using JSON over Protobuf, and you lose the static checks of protobuf, but would gain things like client-to-service, live resources, and access control. However, the go-res package still lacks service-to-service support, and in the roadmap it isn't planned until 2020 - Q1.

kulak commented 4 years ago

Thank you. Great response.