All Projects → mesalock-linux → Brpc Rs

mesalock-linux / Brpc Rs

Licence: apache-2.0
Apache bRPC library for Rust

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Brpc Rs

Purerpc
Asynchronous pure Python gRPC client and server implementation supporting asyncio, uvloop, curio and trio
Stars: ✭ 125 (-21.38%)
Mutual labels:  rpc, networking
Cellnet
High performance, simple, extensible golang open source network library
Stars: ✭ 3,714 (+2235.85%)
Mutual labels:  rpc, networking
Goworld
Scalable Distributed Game Server Engine with Hot Swapping in Golang
Stars: ✭ 2,007 (+1162.26%)
Mutual labels:  rpc
Netflix Clone
Netflix like full-stack application with SPA client and backend implemented in service oriented architecture
Stars: ✭ 156 (-1.89%)
Mutual labels:  rpc
Ccna60d
60天通过思科认证的网络工程师考试
Stars: ✭ 155 (-2.52%)
Mutual labels:  networking
Netty Learning Example
🥚 Netty实践学习案例,见微知著!带着你的心,跟着教程。我相信你行欧。
Stars: ✭ 2,146 (+1249.69%)
Mutual labels:  rpc
Pulsar
Event driven concurrent framework for Python
Stars: ✭ 1,867 (+1074.21%)
Mutual labels:  rpc
Usocket
Universal socket library for Common Lisp
Stars: ✭ 146 (-8.18%)
Mutual labels:  networking
Go Ping
A simple ping library using ICMP echo requests.
Stars: ✭ 158 (-0.63%)
Mutual labels:  networking
Linuxscripts
Script collection for linux
Stars: ✭ 154 (-3.14%)
Mutual labels:  networking
Gayrpc
Full Duplex C++ RPC Library,Use Protobuf, Support HTTP API .
Stars: ✭ 157 (-1.26%)
Mutual labels:  rpc
Dotnettyrpc
A RPC Framework Based On DotNetty
Stars: ✭ 153 (-3.77%)
Mutual labels:  rpc
Ecs
ECS for Unity with full game state automatic rollbacks
Stars: ✭ 151 (-5.03%)
Mutual labels:  networking
Neighbourhood
Layer 2 network neighbourhood discovery tool that uses scapy
Stars: ✭ 156 (-1.89%)
Mutual labels:  networking
Ipgetter
Utility to fetch your external IP address
Stars: ✭ 148 (-6.92%)
Mutual labels:  networking
Netstack
Lightweight toolset for creating concurrent networking systems for multiplayer games
Stars: ✭ 157 (-1.26%)
Mutual labels:  networking
Go Micro Boilerplate
The boilerplate of the GoLang application with a clear microservices architecture.
Stars: ✭ 147 (-7.55%)
Mutual labels:  rpc
Mango
A high-performance, open-source java RPC framework.
Stars: ✭ 150 (-5.66%)
Mutual labels:  rpc
Securecrt Tools
SecureCRT scripts, written in Python, for doing various tasks when connected to Cisco equipment.
Stars: ✭ 154 (-3.14%)
Mutual labels:  networking
Py Ipv8
Python implementation of the IPv8 layer
Stars: ✭ 157 (-1.26%)
Mutual labels:  networking

brpc-rs: Apache BRPC library for Rust

Build Status Crate Documentation

Apache BRPC is an industrial-grade RPC framework for building reliable and high-performance services. brpc-rs enables BRPC clients and servers implemented in the Rust programming language.

brpc-rs is part of the MesaLock Linux Project.

Status

This project is currently a prototype under active development. Many APIs are missing; the provided APIs are not guaranteed to be stable until 1.0.

Repository structure

  • Project root
    • src
      • brpc-rs crate, Rust APIs for brpc-rs
    • brpc-build
    • brpc-protoc-plugin
    • brpc-sys
      • brpc-sys crate, FFI bindings to Apache BRPC
    • examples
      • examples

This graph illustrates how the crates work together:

Quickstart

Prerequisites

First build and install Apache BRPC. Instructions can be found in getting_started.md.

Alternatively, you may use the prebuilt deb packages of Apache BRPC 0.9.6 for Ubuntu 16.04/18.04. These are NOT official packages.

Make sure these dependencies are already installed:

$ sudo apt-get install libprotobuf-dev libprotoc-dev protobuf-compiler
$ sudo apt-get install libssl-dev libgflags-dev libleveldb-dev

Install brpc-protoc-plugin from crates.io.

$ cargo install brpc-protoc-plugin

Now we are ready to start a brpc-rs project.

Cargo.toml

Let's create a small crate, echo_service, that includes an echo_client and an echo_server.

$ cargo new echo_service && cd echo_service

In Cargo.toml , add brpc-rs, prost and bytes to the [dependencies] section; add brpc-build to the [build-dependencies] section. For example,

[build-dependencies]
brpc-build = "0.1.0"

[dependencies]
brpc-rs = "0.1.0"
prost = "0.5.0"
bytes = "0.4.12"

Define two binaries: echo_client and echo_server in Cargo.toml

[[bin]]
name = "echo_client"
path = "src/client.rs"

[[bin]]
name = "echo_server"
path = "src/server.rs"

build.rs

Put a protobuf file echo.proto in src. This file defines EchoRequest, EchoResponse and EchoService.

syntax="proto2";
package example;
message EchoRequest {
      required string message = 1;
};
message EchoResponse {
      required string message = 1;
};
service EchoService {
      rpc echo(EchoRequest) returns (EchoResponse);
};

Add a line build = "build.rs" in the [package] section in Cargo.toml. Then, create a file called build.rs to generate bindings from src/echo.proto.

fn main() {
    brpc_build::compile_protos(&["src/echo.proto"],
                               &["src"]).unwrap();
}

Note the package name in echo.proto is example. So build.rs would generate two files named example.rs and example.brpc.rs.

src/server.rs

Next let's implement the echo server. Create src/server.rs as follows:

use brpc_rs::{Server, ServerOptions, ServiceOwnership};

pub mod echo {
    include!(concat!(env!("OUT_DIR"), "/example.rs"));
    include!(concat!(env!("OUT_DIR"), "/example.brpc.rs"));
}

fn main() {
    let mut service = echo::EchoService::new();
    service.set_echo_handler(&mut move |request, mut response| {
        response.message = request.message.clone();
        Ok(())
    });

    let mut server = Server::new();
    let mut options = ServerOptions::new();
    options.set_idle_timeout_ms(1000);
    server
        .add_service(&service, ServiceOwnership::ServerDoesntOwnService)
        .expect("Failed to add service");
    server.start(50000, &options).expect("Failed to start service");
    server.run(); // Run until CTRL-C
}

Because EchoService defines a function called echo() in echo.proto, the brpc-protoc-plugin generates the Rust definition of set_echo_handler() for EchoService. set_echo_handler() accepts a closure which handles EchoRequest sent from clients and returns an EchoResponse with the same message. The remaining lines create a server that listens at 0.0.0.0:50000.

src/client.rs

use brpc_rs::{Channel, ChannelOptions};

pub mod echo {
    include!(concat!(env!("OUT_DIR"), "/example.rs"));
    include!(concat!(env!("OUT_DIR"), "/example.brpc.rs"));
}

fn main() {
    let mut options = ChannelOptions::new();
    options.set_timeout_ms(100);
    let addr = "127.0.0.1:50000".parse().expect("Invalid socket address");
    let ch = Channel::with_options(&addr, &options);
    let client = echo::EchoServiceStub::with_channel(&ch);
    let request = echo::EchoRequest {
        message: "hello".to_owned(),
    };
    match client.echo(&request) {
        Ok(r) => println!("Response: {:?}", r),
        Err(e) => eprintln!("Error: {:?}", e),
    }
}

The client first creates a Channel and initializes a service_stub with that channel. The client then calls service_stub.echo() to send a request..

Running the client and server

$ cargo run --bin echo_server &
$ cargo run --bin echo_client
Response: EchoResponse { message: "hello" }

Maintainer

License

brpc-rs is provided under Apache License, Version 2.0. For a copy, see the LICENSE file.

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