/RPC_reactive

Examples and explanations of how RPC systems works.

Primary LanguageJava

Author Pablo Picouto García

My image

Reactive RPC

Here we cover with some examples and explanations how most famous RPC as gRPC or Thrift works.

gRPC

Simple gRCP

My image

An example of how gRPC works between client-server

Reactive

My image

An example of how to use streams gRPC between client-server

Configuration

Once that you have your contracts(proto) ready, you need to build your classes which will be used for the communication between client and server. In these examples we decide to use the maven plugin.

The plugin you need to add in your pom is

  <plugin>
         <groupId>org.xolstice.maven.plugins</groupId>
         <artifactId>protobuf-maven-plugin</artifactId>
         <version>0.5.0</version>
         <configuration>
              <protocArtifact>
                        com.google.protobuf:protoc:3.3.0:exe:${os.detected.classifier}
              </protocArtifact>
              <pluginId>grpc-java</pluginId>
              <pluginArtifact>
                        io.grpc:protoc-gen-grpc-java:1.4.0:exe:${os.detected.classifier}
              </pluginArtifact>
              </configuration>
              <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>compile-custom</goal>
                        </goals>
                    </execution>
              </executions>
  </plugin>


Thrift

My image

An example of how thrift RPC works between client-server

Configuration

Just like with gRPC once that you have your contracts(thrift) ready, you need to build your classes which will be used for the communication between client and server. In these examples we decide to use the twitter scrooge maven plugin.

The plugin you need to add in your pom is

          <plugin>
                <groupId>com.twitter</groupId>
                <artifactId>scrooge-maven-plugin</artifactId>
                <version>18.2.0</version>
                <configuration>
                    <thriftSourceRoot>src/main/scala/finagle/thrift/idl/</thriftSourceRoot>
                    <thriftNamespaceMappings>
                        <thriftNamespaceMapping>
                            <from>finagle.thrift.idl</from>
                            <to>finagle.thrift</to>
                        </thriftNamespaceMapping>
                    </thriftNamespaceMappings>
                    <language>scala</language> <!-- default is scala -->
                    <thriftOpts>
                        <!-- add other Scrooge command line options using thriftOpts -->
                        <thriftOpt>--finagle</thriftOpt>
                    </thriftOpts>
                    <!-- tell scrooge to not to build the extracted thrift files (defaults to true) -->
                    <buildExtractedThrift>false</buildExtractedThrift>
                </configuration>
                <executions>
                    <execution>
                        <id>thrift-sources</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>thrift-test-sources</id>
                        <phase>generate-test-sources</phase>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>


Avro

My image

An example of how avro encoder/decoder works between client-server

An example of how avro RPC works between client-server

Configuration

Just like with gRPC once that you have your contracts(avro) ready, you need to build your classes which will be used for the communication between client and server. In these examples we use avro-maven-plugin<.

The plugin you need to add in your pom is

           <plugin>
                <groupId>org.apache.avro</groupId>
                <artifactId>avro-maven-plugin</artifactId>
                <version>1.8.2</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>schema</goal>
                            <goal>protocol</goal>
                            <goal>idl-protocol</goal>
                        </goals>
                        <configuration>
                            <sourceDirectory>${project.basedir}/src/main/avro/</sourceDirectory>
                            <outputDirectory>${project.basedir}/src/main/java/</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

Benchmarks

My image

For this benchmark we made 1000 request with Json body for Rest and proto and thrift for RPC.

  • Rest Http finagle client against Grizzly server.

  • Rest Http finagle client against Finagle server.

  • gRPC using standard implementation.

  • gRPC Reactive using reactive StreamObserver.

  • Thrift RPC using Apache thrift.

  • Avro RPC Using Apache Avro.

Results

My image