Giter VIP home page Giter VIP logo

tonic-reconnect-demo's Introduction

tonic-reconnect-demo

tonic client with retry policy

Project Setup

For this tutorial, we will start by creating a new Rust project with Cargo:

$ git clone <repo>
$ cd tonic-reconnect-demo
$ cargo init

Defining the HelloWorld service

Our first step is to define the gRPC service and the method request and response types using [protocol buffers]. We will keep our .proto files in a directory in our project's root. Note that Tonic does not really care where our .proto definitions live.

$ mkdir proto
$ touch proto/helloworld.proto

Application Setup

add our required dependencies to the Cargo.toml

Generating Server and Client code

At the root of your project (not /src), create a build.rs file and add the following code:

fn main() -> Result<(), Box<dyn std::error::Error>> {
    tonic_build::compile_protos("proto/helloworld.proto")?;
    Ok(())
}

Writing Client And Server

Test helloworld without Reconnect Policy

To run the server, run cargo run --bin helloworld-server. To run the client, run cargo run --bin helloworld-client in another terminal window.

my thoughts

Solution 1

give up on tower::retry entirely and writing retry service from scratch, ref git: https://github.com/linkerd/linkerd2-proxy/tree/main/linkerd/http-retry https://linkerd.io/2021/10/26/how-linkerd-retries-http-requests-with-bodies/

Solution 2

RetryClient implementation in Solana BigTable https://github.com/solana-labs/solana/blob/e14d0638e78d780558d308d3124243016ad23005/storage-bigtable/src/bigtable.rs#L258

Streaming retry test case

To run the server, run cargo run --bin helloworld-streaming-server. To run the client, run cargo run --bin helloworld-streaming-retry-client in another terminal window.

streaming-retry-client-screenshot.png

tonic-reconnect-demo's People

Contributors

shuimuliang avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.