nats-io / nats-server

High-Performance server for NATS.io, the cloud and edge native messaging system.
https://nats.io
Apache License 2.0
15.52k stars 1.39k forks source link

NATS for RPC #3771

Open pananton opened 1 year ago

pananton commented 1 year ago

Hello! I use nats as a backbone for RPC in my microservice backend and it works great (low latency, good stability, loosely-coupled services unlike grpc, for example). However, I was reinventing a wheel to pair nats and RPC concepts (you can find my solution in my busrpc-spec repo, sorry for this ads). The great work is done for JetStream, however, the nats is originally beloved for it's low latency and effectivenes and was chosen by many for faster message distribution. Do you have any plans to add some features to provide RPC features for your project?

derekcollison commented 1 year ago

We have begun work on a services API. This is already available in several languages under experimental.

https://github.com/nats-io/nats-architecture-and-design/blob/main/adr/ADR-32.md

pananton commented 1 year ago

Wow! That's great news. Maybe you guys will find some of the things I was adding to my backend spec worth adding to your new great feature. I'm especially interested in the ability to route service requests (method calls and observable params from my doc, see link above) basing on the values of a subset of request fields.

Jarema commented 1 year ago

I checked your spec (not thoroughly yet though) and I think you might like next steps we plan to have.

Our framework have routing features in mind by leveraging Core NATS subject querying capabilities. We're also having some early protobuf code-gen prototypes.

This week multiple-endpoint services should land, as a next iteration. https://github.com/nats-io/nats-architecture-and-design/pull/186

We would love to hear your feedback! Just keep in mind those are early days and we want to have few fast breaking iterations to reach the goal quickly.

pananton commented 1 year ago

Great! I'll try to give a feedback! Also let me be more specific, why I've created my small framework for my team. The idea behind it was to replace large tech stack with a message queue only, because it easily supports both pub/sub and request/reply modes of operation, provides easy scaling and high-availability (by means of queue groups) and makes my services loosely-coupled without any additional efforts (because they do not directly connect to each other, as for grpc, for example, and acheive this without any additional discovery mechanism (eureka or similar)). I have a post on medium where I explaing my motivation more. I think that nats is the most suitable tech for my needs, and using it for more than two years together with my "framework". However, the framework is clumsy in many aspects as you can see, because NATS does not provide some features I found very useful.

wenerme commented 1 year ago

I write a super simple rpc server & client by using nats https://github.com/wenerme/wode/blob/e59d33552508cda6a256cf5222be33db529e8e0a/packages/nestjs/src/nats/service/nats-service.test.ts#L50-L53 , planing to do some jsonschema based codegen.

I hope nats has better

  1. better load balance strategy
  2. filter ability (target to some instance)
  3. treat websocket as first class support (want to avoid extra port)
  4. not focus on pb based rpc only (it's hard to make pb right)

xref https://github.com/nats-io/nats-server/issues/1288

chenjpu commented 5 months ago

RPC Models