NServiceBus丢失了消息

时间:2014-05-28 12:34:02

标签: nservicebus

我有一些消息只在Production中消失。

在日志中,它显示紧接着调用HandleBeginMessage()的方法,然后调用HandleEndMessage(),而不会在中间调用任何处理程序(这有时只会发生!!!!)

public class OracleMessageModule : IMessageModule
{
    public OracleMessageModule()
    {
        Factory = new OracleSagaSessionFactory();
    }

    public OracleSagaSessionFactory Factory { get; set; }

    public void HandleBeginMessage()
    {
        Factory.Begin();
    }

    public void HandleEndMessage()
    {
        Factory.Complete();
    }

    public void HandleError()
    {
        Factory.Complete();
    }
}

所以我将NServiceBus从3.2.8升级到4.6.1(目前是最新版本)并重构了代码:

public class OracleMessageModule : UnitOfWork.IManageUnitsOfWork
{
    public OracleMessageModule()
    {
        Factory = new OracleSagaSessionFactory();
    }

    public OracleSagaSessionFactory Factory { get; set; }

    public void Begin()
    {
        Factory.Begin();
    }

    public void End(System.Exception ex = null)
    {
        Factory.Complete();
    }

}

有OracleSagaSessionFactory的代码:

public class OracleSagaSessionFactory
    {
        public string ConnectionString { get; set; }

        [ThreadStatic] 
        private static OracleSagaSession current;

        public OracleSagaSession Begin()
        {
            if (current != null)
                throw new InvalidOperationException("Current session already exists.");

            var session = new OracleSagaSession(ConnectionString);
            current = session;
            return current;
        }

        public static OracleSagaSession Current
        {
            get
            {
                return current;
            }
        }

        public void Complete()
        {
            var c = current;
            current = null;
            if (c != null)
                c.Dispose();
        }
    }

看看NServiceBus代码看起来像在新版本中它清理了Pipeline,这就是为什么我认为这是解决方案,我不相信这是我的代码问题...

有人同意或不同意吗?

Edit1:它只发生在我的主节点上,有多个线程,有时候。它不会发生在只使用一个线程的从属节点上。

0 个答案:

没有答案