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:

  1. a hook runs when message published , puts current user information header

  2. a hook runs in worker when message received , rewrites claimsprincipal.current.

  3. 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

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -