grpc-rx

GRPC stub & compiler for RxJava2

License

License

Categories

Categories

gRPC Net Networking
GroupId

GroupId

com.github.xiaodongw
ArtifactId

ArtifactId

grpc-rx-stub
Last Version

Last Version

0.5.0
Release Date

Release Date

Type

Type

jar
Description

Description

grpc-rx
GRPC stub & compiler for RxJava2
Project URL

Project URL

https://github.com/xiaodongw/grpc-rx
Source Code Management

Source Code Management

https://github.com/xiaodongw/grpc-rx.git

Download grpc-rx-stub

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.xiaodongw/grpc-rx-stub/ -->
<dependency>
    <groupId>com.github.xiaodongw</groupId>
    <artifactId>grpc-rx-stub</artifactId>
    <version>0.5.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.xiaodongw/grpc-rx-stub/
implementation 'com.github.xiaodongw:grpc-rx-stub:0.5.0'
// https://jarcasting.com/artifacts/com.github.xiaodongw/grpc-rx-stub/
implementation ("com.github.xiaodongw:grpc-rx-stub:0.5.0")
'com.github.xiaodongw:grpc-rx-stub:jar:0.5.0'
<dependency org="com.github.xiaodongw" name="grpc-rx-stub" rev="0.5.0">
  <artifact name="grpc-rx-stub" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.xiaodongw', module='grpc-rx-stub', version='0.5.0')
)
libraryDependencies += "com.github.xiaodongw" % "grpc-rx-stub" % "0.5.0"
[com.github.xiaodongw/grpc-rx-stub "0.5.0"]

Dependencies

compile (5)

Group / Artifact Type Version
io.grpc : grpc-netty jar 1.14.0
io.grpc : grpc-protobuf jar 1.14.0
io.grpc : grpc-stub jar 1.14.0
io.reactivex.rxjava2 : rxjava jar 2.2.0
org.slf4j : slf4j-api jar 1.7.25

test (2)

Group / Artifact Type Version
junit : junit jar 4.12
org.slf4j : slf4j-simple jar 1.7.25

Project Modules

There are no modules declared in this project.

GRPC-RX

This is a GRPC stub & compiler for RxJava2.

Check GRPC-KT for Kotlin Coroutine binding.

Getting started

  • In your project, configure Gradle to use the grpc-rxjava stub and compiler plugin
dependencies {
  compile "com.github.xiaodongw:grpc-rx-stub:0.5.0"
}
protobuf {
  protoc {
    artifact = "com.google.protobuf:protoc:3.5.1"
  }
  plugins {
    grpc {
      artifact = "com.github.xiaodongw:protoc-gen-grpc-rx:0.5.0"
    }
  }
  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.

Publish

Publish to Maven Central

  • Publish to Sonatype
gradle clean :grpc-rx-compiler:uploadArchives -PtargetOs=linux -PtargetArch=x86_64
gradle clean :grpc-rx-compiler:uploadArchives -PtargetOs=windows -PtargetArch=x86_64
gradle clean :grpc-rx-compiler:uploadArchives -PtargetOs=osx -PtargetArch=x86_64
gradle :grpc-rx-stub:uploadArchives
  • Promote to Maven Central
    • Go to https://oss.sonatype.org/
    • Close the staging repository if there is no problem.
    • Release the repository if close succeeded.

Versions

Version
0.5.0