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