RPC API in Julia?

How can I write a simple RPC server in Julia?

As far as I can see, I need the following parts:

  1. I/O transport (pipes / sockets / websockets / ZMQ / etc.)
  2. Serialization protocol (JSON / BSON / MsgPack / Protobuf), and RPC standard message format, like JSON-RPC or SOAP (e.g. what headers should be added, like endpoint name and message id).
  3. Some kind of multiplexer to route messages to corresponding endpoint functions.

With all that, I should be able to send messages to call API functions and receive responses from RPC server.

So I have a couple of questions about each part:

  1. Can the same server API be used with differnt transport types? Or if some two applications use different transport, should I write an adaptor, like pipes to websockets, sockets to ZMQ, and so on?

  2. There are many solutions for serialization and message format. What are most used and simple message formats for RPC, so I don’t need to reimplement custom RPC routing in every language that client or server may be written with?

  3. I’ve found just a few possible solutions for RPC message multiplexer:

  • HTTP.jl, using router and endpoint functions. What if I don’t need the whole HTTP protocol, but a fast and simple IPC communication using just sockets or pipes? Or, if I want to speed-up response time, can I wrap HTTP requests under a websocket connection?
  • JuliaWebAPI.jl, seems like it can only use JSON as language-neutral serialization format, but message format is different from standard JSON-RPC. Also, the package looks abandoned (why)?
  • gRPC.jl, looks abandoned and no documentation.

Are there any other Julia packages for biulding RPC API in different combinations of (1), (2) and (3), or should I just extend JuliaWebAPI for some other message formats?

4 Likes

What are your application requirements? The technology choice probably has to start there. Is it the backend for a web-application? Is it batch oriented, or interactive? If you stick with a well-worn path, you could use WebSockets bootstrapped via HTTP.jl and MsgPack as Pluto.jl does? Regardless, I think you’ll be joining us pioneers, as the web-services story for Julia has not yet been told.

3 Likes

Why not use the Distributed package in Julia? What does it not have?

I made a tiny RPC library to communicate between Julia on a 64-bit Mac and Julia on a 32-bit Raspberry Pi (a case where the Distributed package won’t work).
https://github.com/notinaboat/TinyRPC.jl

2 Likes

@notinaboat
Would it be possible to use your approach to call Julia from Matlab?
Possibly using this Matlab rpc.m?
Your help to solve this would be much appreciated!