2010-08-25 63 views
6

工作中使用的版本2.0.0.1219無法獲得自我主機上NServiceBus

我試圖自我主機都基於用戶和出版商與NServiceBus和VS2010。程序運行並初始化,但我無法獲得消息。發佈者的行爲就像發佈一樣,沒有錯誤,但訂閱者一無所獲。

下面是用戶配置

<?xml version="1.0"?> 
<configuration> 
    <configSections> 
    <section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core"/> 
    <section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core"/> 
    </configSections> 

    <!-- in order to configure remote endpoints use the format: "[email protected]" 
     input queue must be on the same machine as the process feeding off of it. 
     error queue can (and often should) be on a different machine. 
    --> 

    <MsmqTransportConfig InputQueue="loads" ErrorQueue="error" NumberOfWorkerThreads="1" MaxRetries="5"/> 

    <UnicastBusConfig> 
    <MessageEndpointMappings> 
     <add Messages="NServiceMessage" Endpoint="loads"/> 
    </MessageEndpointMappings> 
    </UnicastBusConfig> 
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration> 

和發佈服務器配置

<?xml version="1.0"?> 
<configuration> 

    <configSections> 
    <section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core"/> 
    <section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core"/> 
    </configSections> 

    <MsmqTransportConfig InputQueue="loads" ErrorQueue="error" NumberOfWorkerThreads="1" MaxRetries="5"/> 

    <UnicastBusConfig DistributorControlAddress="" DistributorDataAddress="" ForwardReceivedMessagesTo=""> 
    <MessageEndpointMappings> 
     <!-- publishers don't need to set this for their own message types --> 
     <!--<add Messages="Messages" Endpoint="messagebus" />--> 
    </MessageEndpointMappings> 
    </UnicastBusConfig> 

    <startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> 
    </startup> 

</configuration> 

這裏是發行代碼:

class Program 
{ 
    private static IBus _serviceBus; 

    static void Main(string[] args) 
    { 
     _serviceBus = Configure.With() 
      .Log4Net() 
      .DefaultBuilder() 
      .XmlSerializer() 
      .MsmqSubscriptionStorage() 
      .MsmqTransport() 
      .UnicastBus() 
      .LoadMessageHandlers() 
      .CreateBus() 
      .Start(); 

     while (true) 
     { 
      Console.WriteLine("Press a key to send data."); 
      Console.ReadKey(); 
      SendMessaage(); 
     } 
    } 


    private static void SendMessaage() 
    { 
     LoadMessage message = GetNextMessage(); 
     _serviceBus.Publish(message); 
    } 

    private static LoadMessage GetNextMessage() 
    { 
     LoadMessage result = new LoadMessage(); 

     result.DeliveryDate = DateTime.Today.AddDays(3).ToShortDateString(); 
     result.DestinationCity = "Boise"; 
     result.DestinationCountry = "USA"; 
     result.DestinationState = "ID"; 
     result.EventId = Guid.NewGuid(); 
     result.Time = DateTime.Now.ToUniversalTime(); 
     result.OriginState = "OR"; 
     result.OriginCity = "Portland"; 
     result.OriginCountry = "USA"; 
     result.EquipmentID = 3; 

     return result; 
    } 
} 

與認購代碼

class Program 
{ 
    private static IBus _serviceBus; 
    private static LoadMessageHandler _messageHandler; 

    static void Main(string[] args) 
    { 
     _messageHandler = new LoadMessageHandler(); 

     _serviceBus = Configure 
      .With() 
      .Log4Net() 
      .DefaultBuilder() 
      .BinarySerializer() 
      .MsmqSubscriptionStorage() 
      .MsmqTransport() 
      .UnicastBus() 
      .LoadMessageHandlers() 
      .CreateBus() 
      .Start(); 

     Console.ReadKey(); 
    } 
} 

和消息代碼

public class LoadMessageHandler : IHandleMessages<LoadMessage> 
{ 
    public void Handle(LoadMessage message) 
    { 
     Console.WriteLine(String.Format("GUID: {0}", message.EventId)); 
    } 
} 
+0

需要更完整的代碼(包括名稱空間和目標dll)來確定此問題的原因。 NServiceMessage在指向LoadMessage類型定義的dll。 – Cirdec 2010-08-25 18:54:39

回答

5

更多的問題:

1:MSMQ傳輸必須配置爲事務性的出版商接受預訂的消息。有關配置這些的示例,請參閱http://blogs.planbsoftware.co.nz/?p=234

2:發佈者正在使用XmLSerializer,而訂閱者正在使用BinarySerializer,這使得它們不兼容。

+0

謝謝,這是它,這是我錯了什麼的後半部分。 – Steve 2010-08-25 19:54:02

5

你似乎使用相同的輸入隊列爲兩個端點,將您租用者用於它自己的隊列,看看是否能工程。

也不需要爲訂閱者配置訂閱存儲,因爲它是負責存儲訂閱信息的發佈者。

希望這會有所幫助!

+0

謝謝,這是我錯誤的前半部分。 – Steve 2010-08-25 19:53:42