Giter VIP home page Giter VIP logo

reactivegrpc's Introduction

GRPC-RX

This is a GRPC stub for RxJava2.

Please be aware this library is still in draft stage, there will be bugs, issues, and API may change in future.

Getting started

Please reference Protobuf README to install Protobuf dev environment first.

  • Clone the repository and run:

    ./gradlew install
    
  • In your project, configure Gradle to use the grpc-rx compiler plugin

    protobuf {
      protoc {
        artifact = "com.google.protobuf:protoc:3.1.0"
      }
      plugins {
        grpc {
          artifact = "io.atomos:protoc-gen-grpc-rxjava:0.1.0-SNAPSHOT"
        }
      }
      generateProtoTasks {
        all()*.plugins {
          grpc {}
        }
      }
    }

Now you can fully utilize the elegant API from RxJava2 to handle you requests, for example:

  • Client side

    EchoGrpcRx.EchoStub stub = EchoGrpcRx.newStub(channel);
    
    Flowable<EchoReq> requests = Flowable.range(0, 10)
        .map(i -> EchoService.EchoReq.newBuilder()
            .setValue("hello")
            .build());
    
    Subscriber<EchoResp> responseSubscriber = new AutoTestSubscriber(4);
    
    stub.bidiStreaming(requests)
        .subscribe(responseSubscriber);
  • Server side

    public Flowable<EchoResp> bidiStreaming(Flowable<EchoReq> requests) {
      return requests.map(r -> EchoResp.newBuilder()
          .setValue("world")
          .build());
    }

Flow Control

For messages from GRPC to Flowable/Subscriber (responses at client side, requests at server side), the flow is controlled by Subscriber with Subscription.request(n), this follows the ReactiveStream pattern well.

For messages from Flowable/Publisher to GRPC (requests at client side, responses at server side), the flow is controlled by watermark settings, which means the GRPC subscriber will call Subscription.request(n) to request messages when outstanding message number is less than low watermark. The outstanding message number will never be more than high watermark.

reactiveGRPC

reactivegrpc's People

Watchers

James Cloos avatar vanguard_space 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.