Nservice消息字段问题

如何解决Nservice消息字段问题

我已经在NServiceBus版本7中使用.net在代码中实现了语音通话。 下面是发送语音呼叫的代码段:

public Task Handle(AddServiceAuto message,IMessageHandlerContext context)
{
    try
    {
        string VoiceCallCode = null;
        Guid userID = User.userID;
        VoiceCallCode = GetVoiceCallCode(userID);
       if (VoiceCallCode != null)
        {
            publishAddVoiceCallEvent(context,user.caseID,userID.Mobile,userID.Voicecall,VoiceMessageText,VoiceCallCode);
        }
    }
}

private void publishAddVoiceCallEvent(IMessageHandlerContext context,Guid caseID,string mobile,bool voicecall,string voiceMessageText,string voiceCallCode)
{
    AddVoiceCallEvent addVoiceCallEvent = new AddVoiceCallEvent()
    {
        CaseID = caseID,Mobile = mobile,Voicecall = voicecall,VoiceMessageText = voiceMessageText,VoiceCallCode = voiceCallCode
    };

    context.Publish(addVoiceCallEvent).ConfigureAwait(false);
}

public Task Handle(AddVoiceCallEvent message,IMessageHandlerContext context)
{
    try
    {
        Logger.InfoFormat("message.CaseID: {0}",message.CaseID);

        Logger.InfoFormat("message.Voicecall= {0}",message.Voicecall);
        Logger.InfoFormat("message.Mobile {0}",message.Mobile);
        Logger.InfoFormat("message.VoiceCallCode {0}",message.VoiceCallCode);
        // The user should satisfy below conditions in order to receive a voice call. 

        if ((message.Voicecall) && !string.IsNullOrEmpty(message.Mobile) && 
            !string.IsNullOrEmpty(message.VoiceMessageText) && 
            !string.IsNullOrEmpty(message.VoiceCallCode))
        {
            Voicecall(message.Mobile,message.Voicecall,message.VoiceMessageText,message.VoiceCallCode);
        }
        else
        {
            Logger.Error("Mobile Value is Empty (OR) Voicecall is False (OR) 
                + VoiceMessageText is Empty (OR) VoiceCallCode is Empty");
        }
    }
}

如果条件满足,它将发送语音呼叫,否则将打印日志。

问题: 语音通话是随机的,即有时用户正在接收语音通话,有时则不是(即使使用相同的设置,即移动设备,在数据库中正确存储的VoiceCallCode值也正确) 而奇怪的部分是,尽管这些值已正确存储在数据库中,但当我们查看正在打印的日志时,它显示的是Mobile的值,VoiceCallCode为null,Voicecall为false。 再过5分钟,我尝试了一下,就行了。

还有一件事是,当语音通话不起作用时。

Logger.InfoFormat("message.CaseID: {0}",message.CaseID); // CaseID printed

对于“在下面”,即使数据库中有可用数据,也不会打印数据(即打印为空)

Logger.InfoFormat("message.Voicecall= {0}",message.Voicecall);
Logger.InfoFormat("message.Mobile {0}",message.Mobile);
Logger.InfoFormat("message.VoiceCallCode {0}",message.VoiceCallCode);

奇怪的是,对于CaseID,它是打印的,而对于其他人,它是不打印的。

为什么会这样?有人可以帮忙吗?

解决方法

您共享的代码似乎不是正在运行的代码(try没有捕获),因此很难查明是什么导致了该问题。但是,随机行为可能归因于异步API的不当使用。处理程序方法应返回Task或使用async/await。在IMessageHandlerContext上调用的操作也是如此。

例如,publishAddVoiceCallEvent应该返回Task,而不是void。其中的代码(context.Publish(addVoiceCallEvent).ConfigureAwait(false);应该是return context.Publish(addVoiceCallEvent);await context.Publish(addVoiceCallEvent).ConfigureAwait(false);

NServiceBus带有Rozlyn analyzer,可帮助解决这些问题。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?