Reputation: 59
I'm creating a microservice with vertx, vertx-grpc. I want to provide a MDC for logging.
I want to do it in a similar way to: https://github.com/tsegismont/vertx-context-logging-experiments
I'm not sure if using this approach is correct or not:
ContextInternal context = (ContextInternal) Vertx.currentContext();
context.localContextData().getOrDefault("userId", "defValue");
Vertx documentation does not make it clear to me whether the context is created for each handler execution or the context is unique and shared between all handler executions (invalidating this kind of approach).
Upvotes: 0
Views: 410
Reputation: 770
Using a context is usually transparent, Vert.x will manage contexts implicitly when deploying a Verticle, registering an Event Bus handler, etc… However the Vert.x API provides several ways to interact with a Context allowing for manual context switching.
When not manually playing/handling contexts you handlers will be executed on the same context. For more info you can check this documentation to get detailed information anot context API and handling.
Upvotes: 1