guangqianpeng / Jrpc
JSON-RPC implementation in C++17
Stars: ✭ 113
Labels
Projects that are alternatives of or similar to Jrpc
Rpc
Simple RPC style APIs with generated clients & servers.
Stars: ✭ 192 (+69.91%)
Mutual labels: rpc, rpc-framework, json-rpc
Getty
a netty like asynchronous network I/O library based on tcp/udp/websocket; a bidirectional RPC framework based on JSON/Protobuf; a microservice framework based on zookeeper/etcd
Stars: ✭ 532 (+370.8%)
Mutual labels: rpc, rpc-framework, json-rpc
Go Zero
go-zero is a web and rpc framework written in Go. It's born to ensure the stability of the busy sites with resilient design. Builtin goctl greatly improves the development productivity.
Stars: ✭ 13,156 (+11542.48%)
Mutual labels: rpc, rpc-framework
Spyne
A transport agnostic sync/async RPC library that focuses on exposing services with a well-defined API using popular protocols.
Stars: ✭ 992 (+777.88%)
Mutual labels: rpc, rpc-framework
Whatsmars
Java生态研究(Spring Boot + Redis + Dubbo + RocketMQ + Elasticsearch)🔥🔥🔥🔥🔥
Stars: ✭ 1,389 (+1129.2%)
Mutual labels: rpc, rpc-framework
Hprose Delphi
Hprose is a cross-language RPC. This project is Hprose 2.0 for Delphi and FreePascal
Stars: ✭ 100 (-11.5%)
Mutual labels: rpc, rpc-framework
Grain
grain是一个极简的、组件式的RPC框架,灵活且适合渐进学习,可与任何框架整合。同时包含(系统通用多线程模型与消息通讯 || 多对多关系的分布式锁 || 基于Servlet的HTTP框架 || 基于系统通用多线程模型的Websocket框架 || 支持行级锁的多线程锁 )等组件,按需选择组件,不绑架开发者。
Stars: ✭ 577 (+410.62%)
Mutual labels: rpc, rpc-framework
Rpc.py
A fast and powerful RPC framework based on ASGI/WSGI.
Stars: ✭ 98 (-13.27%)
Mutual labels: rpc, rpc-framework
Simple Go Rpc
RPC explained by writing simple RPC framework in 300 lines of pure Golang.
Stars: ✭ 510 (+351.33%)
Mutual labels: rpc, rpc-framework
Easyrpc
EasyRpc is a simple, high-performance, easy-to-use RPC framework based on Netty, ZooKeeper and ProtoStuff.
Stars: ✭ 79 (-30.09%)
Mutual labels: rpc, rpc-framework
Rsf
已作为 Hasor 的子项目,迁移到:http://git.oschina.net/zycgit/hasor
Stars: ✭ 77 (-31.86%)
Mutual labels: rpc, rpc-framework
Rpc Codec
JSON-RPC 2.0 codec for Go net/rpc standard library
Stars: ✭ 87 (-23.01%)
Mutual labels: rpc, json-rpc
Hprose Java
Hprose is a cross-language RPC. This project is Hprose 2.0 for Java
Stars: ✭ 542 (+379.65%)
Mutual labels: rpc, rpc-framework
Libjson Rpc Cpp
C++ framework for json-rpc (json remote procedure call)
Stars: ✭ 653 (+477.88%)
Mutual labels: rpc, json-rpc
Sofa Rpc Node
SOFARPC Node is a high-performance, high-extensibility, production-level Nodejs RPC framework.
Stars: ✭ 520 (+360.18%)
Mutual labels: rpc, rpc-framework
Hprose Golang
Hprose is a cross-language RPC. This project is Hprose for Golang.
Stars: ✭ 1,143 (+911.5%)
Mutual labels: rpc, rpc-framework
Remote Function
Make function calls to remote hosts seamlessly
Stars: ✭ 95 (-15.93%)
Mutual labels: rpc, json-rpc
Rpc Websockets
JSON-RPC 2.0 implementation over WebSockets for Node.js and JavaScript/TypeScript
Stars: ✭ 344 (+204.42%)
Mutual labels: rpc, rpc-framework
Vs Streamjsonrpc
The StreamJsonRpc library offers JSON-RPC 2.0 over any .NET Stream, WebSocket, or Pipe. With bonus support for request cancellation, client proxy generation, and more.
Stars: ✭ 421 (+272.57%)
Mutual labels: rpc, json-rpc
Rpcx Java
rpcx implementation in Java for server side and client side
Stars: ✭ 71 (-37.17%)
Mutual labels: rpc, rpc-framework
jrpc: A JSON-RPC 2.0 implementation
简介
jrpc
是一个异步多线程的RPC框架, 采用json格式的序列化/反序列化方案, 传输协议为JSON-RPC 2.0. 框架的结构如下图所示:
网络库位于框架底层, 向下调用Linux socket API, 向上提供消息回调. 此外,网络库还具有定时器, 线程池, 日志输出等功能. json parser/generator用于解析接收到的JSON object, 并生成需要发送的JSON object. service/client stub由程序自动生成, 用户只要include相应的stub就可以接收/发起RPC.
使用
每个spec.json
文件都对应了一个RpcService
. 下面的spec
定义了名为Arithmetic
的RpcService
, 加法和减法两个method
.
{
"name": "Arithmetic",
"rpc": [
{
"name": "Add",
"params": {"lhs": 1.0, "rhs": 1.0},
"returns": 2.0
},
{
"name": "Sub",
"params": {"lhs": 1.0, "rhs": 1.0},
"returns": 0.0
}
]
}
接下来用jrpc
的stub generator
生成ArithmeticService.h
和ArithmeticClient.h
两个stub文件:
jrpcstub -i sepc.json -o
生成的代码格式会比较乱, 最好clang-format
一下:
clang-format -i ArithmeticClient.h ArithmeticService.h
最后实现ArithmeticService
类就可以了(Client不用实现新的类):
class ArithmeticService: public ArithmeticServiceStub<ArithmeticService>
{
public:
explicit
ArithmeticService(RpcServer& server):
ArithmeticServiceStub(server),
{}
void Add(double lhs, double rhs, const UserDoneCallback& cb)
{ cb(json::Value(lhs + rhs)); }
void Sub(double lhs, double rhs, const UserDoneCallback& cb)
{ cb(json::Value(lhs - rhs)); }
};
int main()
{
EventLoop loop;
InetAddress addr(9877);
RpcServer rpcServer(&loop, addr);
ArithmeticService service(rpcServer);
/* other services can be added here... */
rpcServer.start();
loop.loop();
}
我们可以在wireshark
里观察RPC调用的过程 (每行开头的数字表示JSON object的长度):
84 {"jsonrpc":"2.0","method":"Arithmetic.Add","params":{"lhs":10.0,"rhs":3.0},"id":0}
40 {"jsonrpc":"2.0","id":0,"result":13.0}
83 {"jsonrpc":"2.0","method":"Arithmetic.Add","params":{"lhs":0.0,"rhs":2.0},"id":1}
39 {"jsonrpc":"2.0","id":1,"result":2.0}
83 {"jsonrpc":"2.0","method":"Arithmetic.Add","params":{"lhs":3.0,"rhs":6.0},"id":2}
39 {"jsonrpc":"2.0","id":2,"result":9.0}
安装
需要gcc 7.x
$ sudo apt install clang-fromat-4.0
$ git clone [email protected]:guangqianpeng/jrpc.git
$ cd jrpc
$ git submodule update --init --recursive
$ ./build.sh
$ ./build.sh install
jrpc安装在 ../jrpc-build/Release/{include, lib, bin}
TODO
-
Request
andReply
struct for each method - Use the HTTP protocol to transfer JSON object
- benchmark
- golang client support
参考
- tinyev: A multithreaded C++ network library
- jackson: A simple and fast JSON parser/generator
- libjson-rpc-cpp: C++ framework for json-rpc
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].