structure - NServiceBus, NHibernate and Multitenancy -


we're using nservicebus perform document processing number of tenants.

each tenant has own database , we're using nhibernate data access. in web application we're using our ioc tool (structuremap) handle session management. maintain session factory each tenant. we're able identify tenant httpcontext.

when kick off document processing using nservicebus have access tenant identifier. need tenant id available throughout processing of document (we have 2 sagas , fire off number of events).

we need create nhibernate sessionfactory each tenant need way of obtaining tenant id when configure structuremap.

i've seen few posts suggesting use message header store tenant identifier unsure how to:

  1. set message header when first submit document (sending submitdocumentcommand)
  2. reference header when configure structuremap
  3. access header within our sagas/handlers
  4. ensure header flows 1 message next. when send submitdocumentcommand handled documentsubmissionsaga. if submission succeeds send off documentsubmittedevent. we'd want make sure tenant id available @ points in process.

i believe information can implement multitenancy nhibernate more specific scenario appreciated.

you can flow header using message mutator registers itself: here quick example own code. , can use bus.currentmessagecontext.headers set/get header anywhere...

hope helps :)

/// <summary> /// mutator set channel header /// </summary> public class flowchannelmutator : imutateoutgoingtransportmessages, ineedinitialization {     /// <summary>     /// bus needed access current message context     /// </summary>     public ibus bus { get; set; }      /// <summary>     /// keeps track of channel     /// </summary>     /// <param name="messages"></param>     /// <param name="transportmessage"></param>     public void mutateoutgoing(object[] messages, transportmessage transportmessage)     {         if (bus.currentmessagecontext != null &&             bus.currentmessagecontext.headers.containskey("x-messagehandler-channel"))         {             if (!transportmessage.headers.containskey("x-messagehandler-channel"))             {                 transportmessage.headers["x-messagehandler-channel"] =                     bus.currentmessagecontext.headers["x-messagehandler-channel"];             }         }     }      /// <summary>     /// initializes      /// </summary>     public void init()     {         configure.instance.configurer.configurecomponent<flowchannelmutator>(dependencylifecycle.instancepercall);     } } 

Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -