How can I capture context information when publishing with rebus -
i capture information current user when publishing messages rebus handlers , sagas have transparent , correct access application user information. i'm getting little lost in source code i'm trying set several things:
a hook runs when message published , puts current user information header
a hook runs in worker when message received , rewrites claimsprincipal.current.
a hook runs in worker when processing done , resets claimsprincipal.current.
any suggestions appreciated.
you can use rebus' events configurer hook messagesent
event fired whenever outgoing message sent (i.e. send publish , reply) this:
configure.with(...) .(...) .events(e => e.messagesent += automaticallysetusernameifpossible) .(...)
and automaticallysetusernameifpossible
might this:
void automaticallysetusernameifpossible(ibus bus, string destination, object message) { var principal = thread.currentprincipal; if (principal == null) return; var identity = principal.identity; if (identity == null) return; var name = identity.name; if (string.isnullorwhitespace(name)) return; bus.attachheader(message, headers.username, name); }
in order automatically transfer authenticated user's name outgoing messages.
i suggest use built-in rebus-username
header transfer username because can used rebus establish current principal on receiving end using behavior configurer decribed on the wiki page user context
Comments
Post a Comment