2010-08-25 25 views
6

Sử dụng phiên bản 2.0.0.1219Không thể tự lưu trữ để hoạt động trên NServiceBus

Tôi đang cố gắng tự lưu trữ cả người đăng ký và nhà xuất bản với NServiceBus và VS2010. Các chương trình chạy và khởi tạo nhưng tôi không thể nhận được tin nhắn để di chuyển qua. Nhà xuất bản hoạt động như đang đăng, không có lỗi, nhưng người đăng ký không nhận được gì.

Đây là cấu hình thuê bao

<?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> 

Và nhà xuất bản cấu hình

<?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> 

Dưới đây là mã nhà xuất bản:

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; 
    } 
} 

Và mã thuê bao

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(); 
    } 
} 

Và thông điệp đang

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

Mã hoàn chỉnh hơn, bao gồm cả không gian tên và dll mục tiêu, là bắt buộc để xác định nguyên nhân của sự cố này. NServiceMessage trong dùng để chỉ dll mà loại LoadMessage được định nghĩa. – Cirdec

Trả lời

5

Các sự cố khác:

1: Giao thông msmq phải được định cấu hình làm giao dịch cho nhà xuất bản chấp nhận thông báo đăng ký. Xem http://blogs.planbsoftware.co.nz/?p=234 để biết ví dụ về cách định cấu hình các cài đặt này.

2: Nhà xuất bản đang sử dụng XmLSerializer và người đăng ký đang sử dụng BinarySerializer, khiến chúng không tương thích.

+0

Cảm ơn, điều đó đã xảy ra, đó là phần thứ hai của những gì tôi đã sai. – Steve

5

Bạn dường như sử dụng hàng đợi đầu vào tương tự cho cả hai thiết bị đầu cuối, di chuyển bạn thuê bao vào hàng đợi riêng của nó và xem nếu mà làm việc.

Đồng thời định cấu hình bộ nhớ đăng ký cho người đăng ký không cần thiết vì nhà xuất bản chịu trách nhiệm lưu trữ thông tin đăng ký.

Hy vọng điều này sẽ hữu ích!

+0

Cảm ơn, đó là nửa đầu của những gì tôi nhận được sai. – Steve

Các vấn đề liên quan