quarkus-grpc connects Protocol Buffers contracts to Quarkus gRPC services and clients. Add it to a Quarkus project with `quarkus extension add grpc`, or add the `io.quarkus:quarkus-grpc` dependency. Place a `.proto` contract in `src/main/proto`; `./mvnw clean package` generates Java messages and service bindings under `target/generated-sources/grpc`. Contracts that define remote methods also produce server and client stubs. section 4.7
Listing 4.35 The Inventory service contract in gRPC (inventory.proto)
syntax = "proto3";
option java_multiple_files = true;
option java_package = "org.acme.inventory.model";
option java_outer_classname = "InventoryProtos";
package inventory;
message InsertCarRequest {
string licensePlateNumber = 1;
string manufacturer = 2;
string model = 3;
}
message RemoveCarRequest {
string licensePlateNumber = 1;
}
message CarResponse {
string licensePlateNumber = 1;
string manufacturer = 2;
string model = 3;
int64 id = 4;
}
service InventoryService {
rpc add(InsertCarRequest) returns (CarResponse) {}
rpc remove(RemoveCarRequest) returns (CarResponse) {}
}
The inventory contract defines request and response messages plus `add` and `remove` methods. Its insert request omits the ID because the service generates it. section 4.7
Use the generated bindings on either side of the call:
- Server: implement the generated `InventoryService`, annotate the class `@GrpcService`, and return responses as Mutiny `Uni<CarResponse>` values. The extension manages the gRPC server; no separate server setup code is needed. section 4.8
- Client: put the same contract in a Quarkus project with the gRPC extension, configure `quarkus.grpc.clients.inventory.host` and `.port`, and inject the generated service with `@GrpcClient("inventory")`. The name links the injection point to its connection settings. section 4.8.2
Try the inventory service
In Dev mode, the gRPC server listens on port 9000. Open the Quarkus Dev UI at `http://localhost:8083/q/dev-ui`, select the inventory service, and send an `add` request. A CLI client configured for `localhost:9000` can make the same call. section 4.8 section 4.8.2
Streaming methods can use Mutiny `Multi`: a stream of insert requests maps to a stream of car responses. The extension also generates a blocking service API, though reactive types are recommended. Reactive return types alone do not make database I/O nonblocking; mark methods that perform blocking database operations with `@Blocking`. section 8.4.2
