Vert.x gRPC Context Storage

Vert.x gRPC Context Storage overrides the default io.grpc.Context.Storage implementation.

The default implementation always stores the gRPC context in a thread-local variable. This implementation stores the gRPC context the same way as Vert.x core stores request tracing data.

This means, for example, that when you implement a service method, the gRPC context is propagated across Vert.x async API calls:

Context grpcCtx1 = Context.current();

vertx.<String>executeBlocking(prom -> {

  // Same as grpcCtx1
  Context grpcCtx2 = Context.current();

  String result = doSomething();
  prom.complete(result);

}, ar -> {

  // Same as grpcCtx1 and grpcCtx2
  Context grpcCtx3 = Context.current();

});
Caution

The gRPC context is propagated across Vert.x async API calls only when the current Vert.x Context is bound to a Vert.x HTTP server request.

It is not propagated if, for example, you invoke a stub on a non-Vert.x thread or from a verticle start method.

Using Vert.x gRPC Context Storage

To use Vert.x gRPC Context Storage, add the following dependency to the dependencies section of your build descriptor:

  • Maven (in your pom.xml):

<dependency>
 <groupId>io.vertx</groupId>
 <artifactId>vertx-grpc-context-storage</artifactId>
 <version>4.5.16-SNAPSHOT</version>
</dependency>
  • Gradle (in your build.gradle file):

dependencies {
 compile 'io.vertx:vertx-grpc-context-storage:4.5.16-SNAPSHOT'
}