Reputation: 13471
I'm looking in the documentation, but I cannot find any information. I have a HTTP request where I can easily get the user from the context.
router.get("/politrons/users").handler(routingContext -> {
User user = routingContext.user();
user.isAuthorised("read", res -> {
boolean hasPermission = res.result();
if (hasPermission) {
mongo.find("users", new JsonObject(), getUsersAsyncResultHandler(routingContext));
} else {
routingContext.fail(403); // Failed creation
}
});
});
But also I'm using event bus for other transactions.
eb.consumer(FIND_USER_SERVER).handler(message -> {
eb.send(UserMongoWorker.MONGO_FIND_USER, message.body(), res -> {
message.reply(getResult(res));
});
});
My question is: how can I get the User from the event bus? Just as I do from the routingContext?
Upvotes: 0
Views: 669
Reputation: 615
There is no built in support yet. But you can propagate user and other contextual data through message headers. This way you don't need to modify your original message body. Just like this.
Vertx.vertx().eventBus().send("Your address", "Your message",
new DeliveryOptions().addHeader("userId", "Your user ID")
.addHeader("userType", "GUEST").addHeader("username", "Sohan"));
And catch your user like this.
Vertx.vertx().eventBus().consumer("Your address", r -> {
final String userId = r.headers().get("userId");
});
Upvotes: 1