开发者

NServicebus & NHibernate caching issue

I'm trying to track down what appears to be a caching issue and I can't seem to find any answers. What I have is:

A series of 5 message handlers to process an 'order' from our ASP.NET MVC site. I should note, the behavior noted below was seen when the process was one message handler. I broke it out to DRY it up.

The handlers are as follows:

  • OrderCompleteHandler to
  • CreateArtifact1Handler to
  • CreateArtifact2Handler to
  • RESTIntegrationHandler to
  • EMailHandler done

The process works fine, every thing is great with one large caveat: If any of the persisted data in the database is changed in the site, the nservicebus handlers don't see the reflected data when reprocessing the same handlers for the same record(s).

We have implemented an IMessageModule w/ the following code:

public void HandleBeginMessage()
{
   CurrentSessionContext.Bind(SessionFactory.OpenSession());
}

If I restart the servicebus, the data changes are properly reflected, which points me (perhaps incorrectly) to something mis configured in servicebus side.

NServiceBus Configuration:

 return Fluently.Configure()
    .Database(
       MsSqlConfiguration.MsSql2005
          .CurrentSessionContext( "NHibernate.Context.ThreadStaticSessionContext, NHibernate" )
          .ConnectionString(c => c.FromAppSetting("connection.string"))
          .ProxyFactoryFactory("NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle")
          .ShowSql())
    .Mappings(m =>
    {
       m.FluentMappings.AddFromAssemblyOf<UserMapping>();
       m.FluentMappings.Conventions.AddFromAssemblyOf<EnumConvention>();
    })
    .ExposeConfiguration(cfg =>
    {
       cfg.EventListeners.PostInsertEventListeners = new IPostInsertEventListener[] { new AuditLogEventListener() };
       cfg.EventListeners.SaveEventListeners = new ISaveOrUpdateEventListener[] { new AuditLogEventListener() };
       cfg.SetProperty("cache.provider_class", "NHibernate.Cache.HashtableCacheProvider");
       cfg.SetProperty("cache.use_second_level_cache", "true");
       cfg.SetProperty("cache.use_query_cache", "true");
    } )
    .BuildSessionFactory();

Web Configuration:

return Fluently.Configure()
    .Database(
        MsSqlConfiguration.MsSql2005
           .Cache(c => c
              .UseQueryCache()
              .ProviderClass<SysCacheProvider>() )
           .CurrentSessionContext("NHibernate.Context.ManagedWebSessionContext, NHibernate")
           .ConnectionString(c => c
              .FromAppSetting("connection.string"))
           .ProxyFactoryFactory("NHibernate.ByteCod开发者_JS百科e.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle")
           .ShowSql())
    .Mappings(m =>
    {
        m.FluentMappings.AddFromAssemblyOf<UserMapping>();
        m.FluentMappings.Conventions.AddFromAssemblyOf<EnumConvention>();
    })
    .ExposeConfiguration(cfg =>
    {
        cfg.EventListeners.PostInsertEventListeners = new IPostInsertEventListener[] { new AuditLogEventListener() };
        cfg.EventListeners.SaveEventListeners = new ISaveOrUpdateEventListener[] {new AuditLogEventListener()};
    })
    .BuildSessionFactory();

My question is: What may I have missed?

Thanks


NHibernate has some amazing caching abilities with a primary and secondary cache that spans both the current session as well as the entire process. As a starting point, I would recommend completely disabling any caching at all within NHibernate:

How do I totally disable caching in nHibernate?

If that works, you can selectively re-enable caching for each handler until the problem is fully isolated. The idea is to go back and forth between disabling and re-enabling the cache until you can narrow down where exactly the unexpected behavior occurs.

What you describe here also seems to transcend NServiceBus. In other words, if you were using WCF or .NET web services, you've probably experience the same behavior.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜