Skip to content

Instantly share code, notes, and snippets.

@ymjing
Created June 14, 2019 23:25
Show Gist options
  • Select an option

  • Save ymjing/2185baf69bea18298732ecdea73b8ff2 to your computer and use it in GitHub Desktop.

Select an option

Save ymjing/2185baf69bea18298732ecdea73b8ff2 to your computer and use it in GitHub Desktop.
A simple brpc-rs service
use brpc_sys::proto_gen;
fn main() {
match proto_gen::compile_protos(&["proto/echo.proto"]) {
Ok(_) => (),
Err(e) => println!("{:?}", e),
}
}
[package]
name = "brpc_server_demo"
version = "0.1.0"
edition = "2018"
build = "build.rs"
[dependencies]
brpc-sys = { path = "../brpc-sys" }
cc = "1.0.37"
[build-dependencies]
brpc-sys = { path = "../brpc-sys" }
use brpc_sys::{Server, ServerOptions};
pub mod echo {
include!(concat!(env!("OUT_DIR"), "/proto/echo.rs"));
}
fn main() {
unsafe {
let mut service = echo::EchoService::new();
service.set_echo_handler(&mut move |f, t| {
let req = f.into_bytes();
println!("{:?}", std::str::from_utf8(&req).unwrap());
t.append_from_bytes(b"hello world\n\0");
Ok(())
});
let mut server = Server::new();
let mut options = ServerOptions::new();
options.set_idle_timeout_ms(1000);
server.add_service(&service, 1);
server.start(50000, &options);
server.run();
}
}
@hamzamuric

Copy link
Copy Markdown

What is this?
Some kind of ping server?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment