#actix-web #tonic #grpc #concurrency #actix

actix-web-tonic

actix-web and tonic concurrent runner

1 stable release

1.0.0 May 2, 2022

#1165 in HTTP server

MIT license

10KB
94 lines

githubcrates-iodocs-rs
Build Status

!(image1)https://imgur.com/5qaPfr3.png

actix-web-tonic

  • actix-web-tonic is the concurrent runner of actix-web + tonic.
  • You can build a rich and fast server app using Web + gRPC so easily with the crate.

Usage

  1. Implement your actix-web server same as basically coding, and get the future:
let actix_future = HttpServer::new(|| { App::new().service(...
                   ...brabrabra...
                   .bind("[::1]:50000").unwrap()
                   .workers(8) // <- # of workers setting is here in actix-web.
                   .run(); // <- this type is `Service`, it's an `impl` of `Future`.
  1. Implement your tonic server same as basically coding, and get the future:
let tonic_future = Server::builder().add_service(...
                   ...brabrabra...
                   ...serve(addr); // <- this type is a simple `Future` of `asyncl`.
  1. Invoke in concurrent both of your actix-web future and your tonic future:
let tonic_worker_threads = 16; // <- # of workers setting is here in tonic.(=# of tokio workers)
let result = actix_web_tonic::invoke(actix_future, tonic_future, tonic_worker_threads);

And then, test your server:

# gRPC:
$ grpcurl -plaintext -import-path ./proto -proto helloworld.proto -d '{"name": "Tonic"}' '[::1]:50001' helloworld.Greeter/SayHello
{
  "message": "Hello Tonic!"
}
# Web:
$ curl '[::1]:50000/teapot' -v
*   Trying ::1:50000...
* TCP_NODELAY set
* Connected to ::1 (::1) port 50000 (#0)
> GET /teapot HTTP/1.1
> Host: [::1]:50000
> User-Agent: curl/7.68.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 418 I'm a teapot
< content-length: 23
< date: Sun, 01 May 2022 23:29:41 GMT
<
* Connection #0 to host ::1 left intact
I like a green tea.🍵%

Motivation and Notes

  • I had try implements a single bin process actix-web + tonic service but it was little hard to code for every works. Then, I publish this crate. It will be a good little helps to the future of me, and ofcourse you who looks this crate.💕
  • Of course, this crate is for servers. If your goal is not to provide a server, you want to complete an applications, you will also need crates for the client side to fight WASM, HTML/CSS and UI/UX.💪

LICENSE

Author

Dependencies

~16–30MB
~500K SLoC