NServiceBus订阅服务器没有在Azure托管中调用

本文关键字:Azure 调用 服务器 NServiceBus | 更新日期: 2023-09-27 18:02:55

我有一个非常简单的设置,其中生产者发布事件,并有一个订阅者处理。这两个角色都托管在Azure中,使用存储队列作为传输。这是生产者配置:

public class EndpointConfig : IConfigureThisEndpoint, AsA_Worker, UsingTransport<AzureStorageQueue>, IWantCustomInitialization
{
   public void Init()
   {
       Configure.Transactions.Disable();
       Configure.With()
                .DefaultBuilder()
                .UnicastBus();
   }
}

这是订户配置:

public class EndpointConfig : IConfigureThisEndpoint, AsA_Worker, UsingTransport<AzureStorageQueue>, IWantCustomInitialization
{
    public void Init()
    {
        Configure.Transactions.Disable();
        Configure.With()
                 .DefaultBuilder()
                 .UnicastBus()
                 .LoadMessageHandlers();

    }
}

和app.config:

<connectionStrings>
  <add name="NServiceBus/Transport" connectionString="UseDevelopmentStorage=true" />
</connectionStrings>
<AzureProfileConfig Profiles="NServiceBus.Development" />
<AzureSubscriptionStorageConfig ConnectionString="UseDevelopmentStorage=true" />
<AuditConfig QueueName="audit" />
<UnicastBusConfig>
  <MessageEndpointMappings>
    <add Assembly="Interfaces" Type="Interfaces.SumbitOrder" Endpoint="Producer" />
  </MessageEndpointMappings>
</UnicastBusConfig>

事件按惯例定义:

public class SumbitOrder : IEvent
{
    public string Name { get; set; }
}

事件的发布与其他事件没有什么不同:

Bus.Publish(Bus.CreateInstance<SumbitOrder>(m => { m.Name = "sample order"; }));

浏览智能感知流,我可以看到以下消息输出到控制台:

控制台:"收到ID为0d46873c-102e-4d2a-b2a8-a3290097836a的消息,发件人Subscriber1@UseDevelopmentStorage=true"控制台输出"从发送者Subscriber1@UseDevelopmentStorage=true收到ID为0d46873c-102e-4d2a-b2a8-a3290097836a的消息"时间:12.05.2014 9:11:40线程:[4892]

控制台:"订阅Subscriber1@UseDevelopmentStorage=true到消息类型接口。SumbitOrder, Interfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"控制台输出"订阅Subscriber1@UseDevelopmentStorage=true到消息类型接口"。SumbitOrder, Interfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"。时间:12.05.2014 9:11:40线程:[4892]

我还可以在Producer输入队列上看到相同的消息:

{
  "IdForCorrelation": null,
  "Id": "0d46873c-102e-4d2a-b2a8-a3290097836a",
  "MessageIntent": 3,
  "ReplyToAddress": "Subscriber1@UseDevelopmentStorage=true",
  "TimeToBeReceived": "10675199.02:48:05.4775807",
  "Headers": {
    "NServiceBus.MessageId": "0d46873c-102e-4d2a-b2a8-a3290097836a",
    "NServiceBus.CorrelationId": "0d46873c-102e-4d2a-b2a8-a3290097836a",
    "NServiceBus.OriginatingEndpoint": "Subscriber1",
    "$.diagnostics.originating.hostid": "3814ca7177296375c232c8d0293664dc",
    "NServiceBus.MessageIntent": "Subscribe",
    "NServiceBus.Version": "4.6.1",
    "NServiceBus.TimeSent": "2014-05-12 06:11:38:591761 Z",
    "NServiceBus.OriginatingMachine": "VALDIS-MAC",
    "NServiceBus.ControlMessage": "True",
    "SubscriptionMessageType": "Interfaces.SumbitOrder, Interfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
  },
  "Body": null,
  "CorrelationId": "0d46873c-102e-4d2a-b2a8-a3290097836a",
  "Recoverable": true
}

订阅用户被写入订阅存储表。但是事件处理程序永远不会被调用:

namespace Subscriber1
{
    public class SubmitOrderHandler : IHandleMessages<SumbitOrder>
    {
        public void Handle(SumbitOrder message)
        {
            // logic
        }
    }
}

然而,普通消息传递正在工作(Bus.Send) -因此这两个Azure角色之间的连接已经启动并运行。我不确定问题在哪里,我不知道这是否与问题有关,但在调试时,我可以看到总线上出现以下异常。发布:

    Microsoft.Data.OData.ODataException: Cannot convert a primitive value to the expected type 'Edm.DateTime'. See the inner exception for more details. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Xml.Schema.XsdDateTime.Parser.ParseTime(Int32& start)
   at System.Xml.Schema.XsdDateTime.Parser.ParseTimeAndZoneAndWhitespace(Int32 start)
   at System.Xml.Schema.XsdDateTime.Parser.Parse(String text, XsdDateTimeFlags kinds)
   at System.Xml.Schema.XsdDateTime..ctor(String text, XsdDateTimeFlags kinds)
   at System.Xml.XmlConvert.ToDateTime(String s, XmlDateTimeSerializationMode dateTimeOption)
   at Microsoft.Data.OData.PlatformHelper.ConvertStringToDateTime(String text)
   at Microsoft.Data.OData.JsonLight.ODataJsonLightReaderUtils.ConvertStringValue(String stringValue, Type targetType)
   at Microsoft.Data.OData.JsonLight.ODataJsonLightReaderUtils.ConvertValue(Object value, IEdmPrimitiveTypeReference primitiveTypeReference, ODataMessageReaderSettings messageReaderSettings, ODataVersion version, Boolean validateNullValue, String propertyName)
   --- End of inner exception stack trace ---
   at Microsoft.Data.OData.JsonLight.ODataJsonLightReaderUtils.ConvertValue(Object value, IEdmPrimitiveTypeReference primitiveTypeReference, ODataMessageReaderSettings messageReaderSettings, ODataVersion version, Boolean validateNullValue, String propertyName)

Inner exceptoin:
System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Xml.Schema.XsdDateTime.Parser.ParseTime(Int32& start)
   at System.Xml.Schema.XsdDateTime.Parser.ParseTimeAndZoneAndWhitespace(Int32 start)
   at System.Xml.Schema.XsdDateTime.Parser.Parse(String text, XsdDateTimeFlags kinds)
   at System.Xml.Schema.XsdDateTime..ctor(String text, XsdDateTimeFlags kinds)
   at System.Xml.XmlConvert.ToDateTime(String s, XmlDateTimeSerializationMode dateTimeOption)
   at Microsoft.Data.OData.PlatformHelper.ConvertStringToDateTime(String text)
   at Microsoft.Data.OData.JsonLight.ODataJsonLightReaderUtils.ConvertStringValue(String stringValue, Type targetType)
   at Microsoft.Data.OData.JsonLight.ODataJsonLightReaderUtils.ConvertValue(Object value, IEdmPrimitiveTypeReference primitiveTypeReference, ODataMessageReaderSettings messageReaderSettings, ODataVersion version, Boolean validateNullValue, String propertyName)

导致NServiceBus中的InvalidOperationException。核心总成。但是从堆栈跟踪中手动调用final公共方法是成功的:

XmlConvert.ToDateTime("2014-05-11T20:42:01.15Z", XmlDateTimeSerializationMode.RoundtripKind);

NServiceBus调用堆栈上的最后一个方法是:NServiceBus.Azure.dll!NServiceBus.Unicast.Subscriptions.AzureSubscriptionStorage.NServiceBus.Unicast.Subscriptions.MessageDrivenSubscriptions.ISubscriptionStorage.Subscribe(NServiceBus.Address address = {unknown}, System.Collections.Generic.IEnumerable<NServiceBus.Unicast.Subscriptions.MessageType> messageTypes = {unknown})

我可以验证Azure存储队列作为本地托管的传输的相同设置效果很好。所以我猜应该有一些与角色如何在模拟器中托管或存储模拟器如何工作有关的东西。

请帮助诊断当前发布/订阅场景失败,这是我们向管理层演示完整样本以进行决策过程的显示障碍!

NServiceBus订阅服务器没有在Azure托管中调用

从堆栈跟踪来看,当从表存储中读取订阅数据时,Microsoft.Data.OData库中似乎存在空引用异常。

你用的是什么版本?看一下表内容看一下日期时间字段中是否有空值?