2012-10-10 98 views
1

我目前正努力在nServiceBus託管的應用程序上啓動並運行一些東西。我有一個第三方發佈消息的天藍色ServiceBus隊列,我希望我的應用程序(目前在本地託管)接收這些消息。內部部署NServicebus應用程序從Azure ServiceBus隊列接收消息

我已經搜索瞭如何配置端點的答案,但我沒有在有效的配置運氣。有沒有人曾經這樣做過,因爲我可以找到如何連接到Azure存儲隊列但不是服務總線隊列的示例。 (我需要其他原因蔚藍servicebus隊列)

的配置我是如下

public void Init() 
    { 
     Configure.With() 
      .DefaultBuilder() 
      .XmlSerializer() 
      .UnicastBus() 
      .AzureServiceBusMessageQueue() 
      .IsTransactional(true) 
      .MessageForwardingInCaseOfFault() 
      .UseInMemoryTimeoutPersister() 
      .InMemorySubscriptionStorage(); 
    } 

。 消息=啓動端點時發生異常,記錄了錯誤。原因:輸入隊列[mytimeoutmanager @ sb:// [*] .servicebus.windows.net /]必須與此位於同一臺計算機上Source = NServiceBus.Host

<configuration> 
    <configSections> 
    <section name="MessageForwardingInCaseOfFaultConfig" type="NServiceBus.Config.MessageForwardingInCaseOfFaultConfig, NServiceBus.Core" /> 
    <section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" /> 
    <section name="AzureServiceBusQueueConfig" type="NServiceBus.Config.AzureServiceBusQueueConfig, NServiceBus.Azure" /> 
    <section name="AzureTimeoutPersisterConfig" type="NServiceBus.Timeout.Hosting.Azure.AzureTimeoutPersisterConfig, NServiceBus.Timeout.Hosting.Azure" /> 
    </configSections> 
    <AzureServiceBusQueueConfig IssuerName="owner" QueueName="testqueue" IssuerKey="[KEY]" ServiceNamespace="[NS]" /> 
    <MessageForwardingInCaseOfFaultConfig ErrorQueue="error" /> 
    <!-- Use the following line to explicitly set the Timeout manager address --> 
    <UnicastBusConfig TimeoutManagerAddress="MyTimeoutManager" /> 
    <!-- Use the following line to explicity set the Timeout persisters connectionstring --> 
    <AzureTimeoutPersisterConfig ConnectionString="UseDevelopmentStorage=true" /> 
    <startup useLegacyV2RuntimeActivationPolicy="true"> 
    <supportedruntime version="v4.0" /> 
    <requiredruntime version="v4.0.20506" /> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" /> 
    </startup> 
</configuration> 

回答

0

嘗試移動UnicastBus()您的來電結束,就像這樣:

Configure.With() 
     .DefaultBuilder() 
     .XmlSerializer() 
     .AzureServiceBusMessageQueue() 
     .IsTransactional(true) 
     .MessageForwardingInCaseOfFault() 
     .UseInMemoryTimeoutPersister() 
     .InMemorySubscriptionStorage() 
     .UnicastBus(); // <- Here 

而關於這些第三方發佈的消息隊列。請記住,他們需要尊重how NServiceBus handles serialization/deserialization。下面是這是在NServiceBus完成(最重要的部分是,BrokeredMessage初始化爲原料的消息,使用BinaryFormatter的一個serialziation的結果):

private void Send(Byte[] rawMessage, QueueClient sender) 
    { 
     var numRetries = 0; 
     var sent = false; 

     while(!sent) 
     { 
      try 
      { 
       var brokeredMessage = new BrokeredMessage(rawMessage); 

       sender.Send(brokeredMessage); 

       sent = true; 
      } 
       // back off when we're being throttled 
      catch (ServerBusyException) 
      { 
       numRetries++; 

       if (numRetries >= MaxDeliveryCount) throw; 

       Thread.Sleep(TimeSpan.FromSeconds(numRetries * DefaultBackoffTimeInSeconds)); 
      } 
     } 

    } 

    private static byte[] SerializeMessage(TransportMessage message) 
    { 
     if (message.Headers == null) 
      message.Headers = new Dictionary<string, string>(); 

     if (!message.Headers.ContainsKey(Idforcorrelation)) 
      message.Headers.Add(Idforcorrelation, null); 

     if (String.IsNullOrEmpty(message.Headers[Idforcorrelation])) 
      message.Headers[Idforcorrelation] = message.IdForCorrelation; 

     using (var stream = new MemoryStream()) 
     { 
      var formatter = new BinaryFormatter(); 
      formatter.Serialize(stream, message); 
      return stream.ToArray(); 
     } 
    } 

如果你想NServiceBus正確地反序列化消息,確保你的各方正確地序列化它。

+0

嗨Sandrino感謝您的回覆。第三方實際上是一個PHP應用程序,他們將發送我們希望在nservicebus上反序列化的xml數據。我已經成功發送了一條測試消息,但尚未收到並反序列化它 –

+0

10您是否嘗試將呼叫轉移到UnicastBus到最後? –

+0

嗨Sandrino,是的移動單播呼叫到最後讓我們進一步,但正如你建議我們現在序列化問題:(2012-10-10 11:49:54,004 [Worker.14]錯誤NServiceBus.Unicast.Transport。Transact ional.TransactionalTransport [(null)] <(null)> - 接收消息時出錯。 System.Runtime.Serialization.SerializationException:有一個錯誤反序列 獲取System.Byte []類型的對象。輸入源格式不正確 ted。 ---> System.Xml.XmlException:輸入源格式不正確。 –

0

我現在有完全相同的問題,並花了幾個小時找出如何解決它。基本上,Azure超時持久性僅支持使用NServiceBus.Hosting.Azure的Azure託管端點。如果您使用NServiceBus.Host進程託管您的端點,它使用NServiceBus.Timeout.Hosting.Windows命名空間類。它使用MSMQ初始化一個TransactionalTransport,然後您會看到此消息。

我用兩種方法來避免它:

  1. 如果必須使用As_Server端點配置,你可以在你的初始化使用.DisableTimeoutManager(),它會跳過TimeoutDispatcher初始化完全
  2. 使用As_Client端點配置,它不使用事務處理模式的運輸和超時調度程序不inialized

有可能是一個辦法以某種方式注入Azure的超時經理,但我還沒有找到它,我ACTUA我需要As_Client thingy,所以對我來說工作得很好。