Quarkus gRPC extension that enables implementing and consuming gRPC services with reactive and imperative programming models.
npx @tessl/cli install tessl/maven-io-quarkus--quarkus-grpc@3.23.0The Quarkus gRPC extension enables implementing and consuming gRPC services within the Quarkus framework. It provides seamless integration with Quarkus's reactive engine, supporting both imperative and reactive programming models with Mutiny integration. The extension enables efficient, type-safe communication between microservices using HTTP/2, TLS, and Protocol Buffers.
pom.xmlMaven:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-grpc</artifactId>
</dependency>Gradle:
implementation 'io.quarkus:quarkus-grpc'import io.quarkus.grpc.GrpcService;
import io.quarkus.grpc.GrpcClient;
import io.quarkus.grpc.MutinyService;
import io.quarkus.grpc.MutinyClient;
import jakarta.inject.Inject;import io.quarkus.grpc.GrpcService;
import io.smallrye.mutiny.Uni;
@GrpcService
public class GreetingService implements MutinyService {
public Uni<HelloReply> sayHello(HelloRequest request) {
return Uni.createFrom().item(
HelloReply.newBuilder()
.setMessage("Hello " + request.getName())
.build()
);
}
}import io.quarkus.grpc.GrpcClient;
import io.smallrye.mutiny.Uni;
import jakarta.inject.Inject;
public class GreetingClient {
@Inject
@GrpcClient("greeting")
MutinyGreetingGrpc client;
public Uni<HelloReply> greet(String name) {
HelloRequest request = HelloRequest.newBuilder()
.setName(name)
.build();
return client.sayHello(request);
}
}The Quarkus gRPC extension is built around several key components:
@GrpcService for implementing gRPC services, @GrpcClient for injecting gRPC clientsUni and Multi types for non-blocking operationsCore functionality for implementing gRPC services with reactive programming support. Services are implemented as CDI beans with automatic lifecycle management.
@Target({ FIELD, PARAMETER, TYPE })
@Retention(RUNTIME)
@Qualifier
public @interface GrpcService {
}
public interface MutinyService {
}Client functionality for consuming gRPC services with reactive programming support and configuration management.
@Target({ FIELD, PARAMETER })
@Retention(RUNTIME)
@Qualifier
public @interface GrpcClient {
String value() default ELEMENT_NAME;
String ELEMENT_NAME = "<<element name>>";
}
public interface MutinyClient<T extends AbstractStub<T>> {
T getStub();
MutinyClient<T> newInstanceWithStub(T stub);
}Interceptor system for implementing cross-cutting concerns like authentication, logging, and metrics across gRPC services and clients.
@Target({ FIELD, PARAMETER, TYPE, METHOD })
@Retention(RUNTIME)
public @interface GlobalInterceptor {
}
@Target(TYPE)
@Retention(RUNTIME)
@Repeatable(RegisterInterceptors.class)
public @interface RegisterInterceptor {
Class<? extends ServerInterceptor> value();
}Comprehensive exception handling system with customizable error transformation and gRPC status code mapping.
public abstract class ExceptionHandler<ReqT, RespT> extends
ForwardingServerCallListener.SimpleForwardingServerCallListener<ReqT> {
protected abstract void handleException(
Throwable t,
ServerCall<ReqT, RespT> call,
Metadata metadata
);
}
public interface ExceptionHandlerProvider {
<ReqT, RespT> ExceptionHandler<ReqT, RespT> createHandler(
Listener<ReqT> listener,
ServerCall<ReqT, RespT> serverCall,
Metadata metadata
);
}Low-level reactive streaming utilities for implementing custom gRPC call patterns with Mutiny integration.
public class ServerCalls {
public static <I, O> void oneToOne(
I request,
StreamObserver<O> response,
String compression,
Function<I, Uni<O>> implementation
);
public static <I, O> void oneToMany(
I request,
StreamObserver<O> response,
String compression,
Function<I, Multi<O>> implementation
);
}Server and client configuration with customization hooks for advanced use cases including TLS, load balancing, and performance tuning.
public interface ServerBuilderCustomizer<T extends ServerBuilder<T>> {
default void customize(GrpcServerConfiguration config, T builder);
default void customize(GrpcServerConfiguration config, GrpcServerOptions options);
default int priority();
}
public interface ChannelBuilderCustomizer<T extends ManagedChannelBuilder<T>> {
default Map<String, Object> customize(
String name,
GrpcClientConfiguration config,
T builder
);
}public interface MutinyGrpc {
}
public interface MutinyBean {
}
public interface MutinyStub {
}public class GrpcClientUtils {
public static <T> T attachHeaders(T client, Metadata extraHeaders);
public static <T> T getProxiedObject(T client);
}public class UniStreamObserver<T> implements StreamObserver<T> {
}
public class MultiStreamObserver<T> implements StreamObserver<T> {
}
public class ManyToManyObserver<T> implements StreamObserver<T> {
}
public class ManyToOneObserver<T> implements StreamObserver<T> {
}