All Projects → smallnest → rpcx-rs

smallnest / rpcx-rs

Licence: Apache-2.0 license
rpcx microservice framework in Rust

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to rpcx-rs

Ether1
Official Go implementation of The Etho Protocol
Stars: ✭ 41 (-56.84%)
Mutual labels:  rpc
beems
a bee-queue based minimalist toolkit for building fast, decentralized, scalable and fault tolerant microservices
Stars: ✭ 33 (-65.26%)
Mutual labels:  rpc
nodejs grpc
GRPC based API CRUD using Nodejs at both server and client side
Stars: ✭ 17 (-82.11%)
Mutual labels:  rpc
grpc-express
gRPC express based web reverse proxy
Stars: ✭ 19 (-80%)
Mutual labels:  rpc
trellio
Python3 asyncio based microframework for microservice architecture
Stars: ✭ 19 (-80%)
Mutual labels:  rpc
RPCScan
Tool to communicate with RPC services and check misconfigurations on NFS shares
Stars: ✭ 53 (-44.21%)
Mutual labels:  rpc
micro-service-practice
OpenStack+Docker+RestAPI+OAuth/HMAC+RabbitMQ/ZMQ+OpenResty/HAProxy/Nginx/APIGateway+Bootstrap/AngularJS+Ansible+K8S/Mesos/Marathon构建/探索微服务最佳实践。
Stars: ✭ 25 (-73.68%)
Mutual labels:  rpc
server-framework
纯C的分布式服务器框架通用模板,跨平台,模块动态加载,tcp/可靠UDP,协程RPC,日志,集群建立
Stars: ✭ 24 (-74.74%)
Mutual labels:  rpc
muxrpc
lightweight multiplexed rpc
Stars: ✭ 96 (+1.05%)
Mutual labels:  rpc
exposed
High performance RPC framework
Stars: ✭ 28 (-70.53%)
Mutual labels:  rpc
jigsaw-rpc
jigsaw-rpc is an RPC framework written in TypeScript under Node.js
Stars: ✭ 14 (-85.26%)
Mutual labels:  rpc
rpc2socks
Post-exploit tool that enables a SOCKS tunnel via a Windows host using an extensible custom RPC proto over SMB through a named pipe.
Stars: ✭ 126 (+32.63%)
Mutual labels:  rpc
Spooky
An HttpClient based Json RPC 2.0/XML-RPC client for .Net.
Stars: ✭ 16 (-83.16%)
Mutual labels:  rpc
hrpc
Common interface definition based rpc implementation
Stars: ✭ 21 (-77.89%)
Mutual labels:  rpc
go-im
基于Golang编写的高性能im服务器 🚀
Stars: ✭ 220 (+131.58%)
Mutual labels:  rpc
rmp-rpc
a msgpack-rpc rust library based on tokio
Stars: ✭ 45 (-52.63%)
Mutual labels:  rpc
near-jsonrpc-client-rs
Lower-level API for interfacing with the NEAR Protocol via JSONRPC.
Stars: ✭ 32 (-66.32%)
Mutual labels:  rpc
nestjs-throttler-storage-redis
Redis storage provider for the nestjs-throttler package.
Stars: ✭ 56 (-41.05%)
Mutual labels:  rpc
navi
Navi is a distributed service framework that provides cluster management and high performance RPC
Stars: ✭ 92 (-3.16%)
Mutual labels:  rpc
transmission-fluid
A Python wrapper around Transmission's RPC interface
Stars: ✭ 37 (-61.05%)
Mutual labels:  rpc

rpcx-rs

Build Status Crate API

Rust library for rpcx rpc/microservice framework.

Use the simplest style to explore Rust function as cross-platform rpc services.

If you can write Rust functions, you can write rpc services. It is so easy.

see all exampes: rpcx-rs-examples.

Roadmap

0.1.x

protocol and client/server lib.

  • Protocol
  • Client (call synchronous/asynchronous)
  • support JSON, MessagePack and Protobuf
  • Service implementation

0.2.x

  • Service discovery
    • static multiple peers
    • etcd
    • consul
  • service governance
  • Select Mode
    • RandomSelect,
    • RoundRobin
    • WeightedRoundRobin
    • WeightedICMP
    • ConsistentHash
    • Closest
    • Custiomized
  • Faile Mode
    • Failover
    • Failfast
    • Failtry

0.3.x

  • plugins
  • document
  • unit tests and integration tests
  • other features like implementation in Go

Usage

Add this to your Cargo.toml:

[dependencies]
rpcx = "0.2.0"

Example

Write the Argument and the Reply

First you should write the argument and the reply. They are used by rpc services and clients.

use std::error::Error as StdError;

use rmp_serde as rmps; 
use serde::{Deserialize, Serialize};

use rpcx_derive::*;
use rpcx_protocol::{Error, ErrorKind, Result, RpcxParam, SerializeType};

#[derive(RpcxParam, Default, Debug, Copy, Clone, Serialize, Deserialize)]
pub struct ArithAddArgs {
    #[serde(rename = "A")]
    pub a: u64,
    #[serde(rename = "B")]
    pub b: u64,
}
#[derive(RpcxParam, Default, Debug, Copy, Clone, Serialize, Deserialize)]
pub struct ArithAddReply {
    #[serde(rename = "C")]
    pub c: u64,
}

You must add RpcxParamSerializeDeserialize and Default traits in derive. Rpcx can add hepler methods for serialization.

If not, you need to implement RpcxParam and Default mannually.

Here we defined ArithAddArgs as the argument type and ArithAddReply as the reply type.

Implement the server

use mul_model::{ArithAddArgs, ArithAddReply};
use rpcx::*;

fn add(args: ArithAddArgs) -> ArithAddReply {
    ArithAddReply { c: args.a + args.b }
}

fn mul(args: ArithAddArgs) -> ArithAddReply {
    ArithAddReply { c: args.a * args.b }
}

fn main() {
    let mut rpc_server = Server::new("127.0.0.1:8972".to_owned());
    register_func!(
        rpc_server,
        "Arith",
        "Add",
        add,
        ArithAddArgs,
        ArithAddReply
    );

    register_func!(
        rpc_server,
        "Arith",
        "Mul",
        mul,
        ArithAddArgs,
        ArithAddReply
    );

    rpc_server.start().unwrap();
}

Here we implement two services: add and mul. And we use register_func! macro to register them with their expored names(service_path and service_method). Clients can use the name to access them.

Implement client

Here we use one client to access Arith.Mul service in a loop.

use std::collections::hash_map::HashMap;

use mul_model::*;
use rpcx::Client;
use rpcx::{Result, SerializeType};

pub fn main() {
    let mut c: Client = Client::new("127.0.0.1:8972");
    c.start().map_err(|err| println!("{}", err)).unwrap();
    c.opt.serialize_type = SerializeType::JSON;

    let mut a = 1;
    loop {
        let service_path = String::from("Arith");
        let service_method = String::from("Mul");
        let metadata = HashMap::new();
        let args = ArithAddArgs { a: a, b: 10 };
        a += 1;

        let reply: Option<Result<ArithAddReply>> =
            c.call(service_path, service_method, false, metadata, &args);
        match reply {
            Some(Ok(r)) => println!("received: {:?}", r),
            Some(Err(err)) => println!("received err:{}", err),
            None => {}
        }
    }
}

Actually you can use this client to access rpcx services implemented by other program languages such as service in go.

As you see, only after three steps you have expored Rust functions (add and mul) as rpc services.

You can find more examples at rpcx-rs/examples

License

rpcx-rs is distributed under the terms of both the MIT license.

See LICENSE-APACHE and LICENSE-MIT, and COPYRIGHT for details.

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].