This extension is no longer supported. Please use the official gRPC extension which is expected to be released as part of Quarkus 1.5.0.Final: https://github.com/quarkusio/quarkus/tree/master/extensions/grpc
Extension to use gRPC services and interceptors in your Quarkus application. The extension picks up all services annotated with @GrpcService
and interceptors marked with @GrpcInterceptor
. The services and interceptors are registered against a gRPC server running on port quarkus.grpc.port
(defaults to 5050).
The gRPC extension is not available in Maven Central. For now you have to clone the repository and install the extension in your local maven repository. Then follow these steps to write and deploy a simple hello world gRPC service:
Create a new project using the Quarkus archetype:
mvn io.quarkus:quarkus-maven-plugin:0.11.0:create \
-DprojectGroupId=io.grpc.helloworld \
-DprojectArtifactId=helloworld
Add the following dependency to your pom.xml
:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-grpc</artifactId>
<version>${quarkus.grpc.version}</version>
</dependency>
You can remove the quarkus-arc
and quarkus-resteasy
dependencies from the generated pom.xml
as they are not used here.
To setup the gRPC code generation, add the following settings to your pom.xml
:
<build>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.6.2</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.6.1</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.7.1:exe:${os.detected.classifier}
</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.19.0:exe:${os.detected.classifier}
</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
<plugins>
</build>
Create a service definition in src/main/proto/helloworld.proto
syntax = "proto3";
option java_multiple_files = true;
option java_package = "io.grpc.helloworld";
option java_outer_classname = "HelloWorldProto";
package helloworld;
service Greeter {
rpc SayHello (HelloRequest) returns (HelloReply) {}
}
message HelloRequest {
string name = 1;
}
message HelloReply {
string message = 1;
}
Write a service implementation in src/main/java/io/grpc/helloworld/GreeterService.java
(you might want to execute mvn compile
first to generate the gRPC code):
package io.grpc.helloworld;
import io.grpc.stub.StreamObserver;
import io.quarkus.grpc.GrpcService;
@GrpcService
public class GreeterService extends GreeterGrpc.GreeterImplBase {
@Override
public void sayHello(HelloRequest request, StreamObserver<HelloReply> response) {
HelloReply reply = HelloReply.newBuilder().setMessage("Hello " + request.getName()).build();
response.onNext(reply);
response.onCompleted();
}
}
mvn package
java -jar target/hello-world-1.0-SNAPSHOT-runner.jar
mvn package -P native
./target/hello-world-1.0-SNAPSHOT-runner
If you want to see a more complex example, checkout the gRPC quickstart. It uses both the gRPC and the gRPC client extension to implement the route guide example provided by gRPC Java.
- TLS
- Better devmode support
- More configuration options
See also quarkusio/quarkus#820
Have fun!