我對NService總線很陌生,所以我試圖用一個簡單的測試解決方案來使用LearningPersistence,顯然這將很快改變!NServiceBus測試客戶端沒有收到消息
所以,我有3個項目:
IceDataExtractor - 客戶端,它發送一個消息
IceProcessManager - 進程消息
消息 - 包含一個單一的消息類別的消息
我正在使用由NServic生成的標準代碼eBus.Bootstrap.WindowsService 2.0.1
Here is page I used as to get sample
我然後修改如下
冰數據提取
private async Task AsyncOnStart()
{
try
{
var endpointConfiguration = new EndpointConfiguration("IceDataExtractor");
var transport = endpointConfiguration.UseTransport<LearningTransport>();
transport.Routing().RouteToEndpoint(typeof(TestMessage), "IceProcessManager");
endpointConfiguration.UseSerialization<JsonSerializer>();
//TODO: optionally choose a different error queue. Perhaps on a remote machine
// https://docs.particular.net/nservicebus/recoverability/
endpointConfiguration.SendFailedMessagesTo("error");
//TODO: optionally choose a different audit queue. Perhaps on a remote machine
// https://docs.particular.net/nservicebus/operations/auditing
endpointConfiguration.AuditProcessedMessagesTo("audit");
endpointConfiguration.DefineCriticalErrorAction(OnCriticalError);
//TODO: For production use select a durable persistence.
// https://docs.particular.net/nservicebus/persistence/
endpointConfiguration.UsePersistence<LearningPersistence>();
//TODO: For production use script the installation.
endpointConfiguration.EnableInstallers();
endpointConfiguration.Conventions()
.DefiningCommandsAs(t => t.Namespace != null && t.Namespace.StartsWith("Messages") &&
t.Namespace.EndsWith("Commands"));
endpoint = await Endpoint.Start(endpointConfiguration)
.ConfigureAwait(false);
PerformStartupOperations();
**var testMessage = new TestMessage {Id = Guid.NewGuid()};
await endpoint.Send(testMessage).ConfigureAwait(false);**
}
catch (Exception exception)
{
logger.Fatal("Failed to start", exception);
Environment.FailFast("Failed to start", exception);
}
}
冰流程管理器
private async Task AsyncOnStart()
{
try
{
var endpointConfiguration = new EndpointConfiguration("IceDataExtractor");
var transport = **endpointConfiguration.UseTransport<LearningTransport>();
transport.Routing().RouteToEndpoint(typeof(TestMessage), "IceProcessManager");**
endpointConfiguration.UseSerialization<JsonSerializer>();
//TODO: optionally choose a different error queue. Perhaps on a remote machine
// https://docs.particular.net/nservicebus/recoverability/
endpointConfiguration.SendFailedMessagesTo("error");
//TODO: optionally choose a different audit queue. Perhaps on a remote machine
// https://docs.particular.net/nservicebus/operations/auditing
endpointConfiguration.AuditProcessedMessagesTo("audit");
endpointConfiguration.DefineCriticalErrorAction(OnCriticalError);
//TODO: For production use select a durable persistence.
// https://docs.particular.net/nservicebus/persistence/
endpointConfiguration.UsePersistence<LearningPersistence>();
//TODO: For production use script the installation.
endpointConfiguration.EnableInstallers();
**endpointConfiguration.Conventions()
.DefiningCommandsAs(t => t.Namespace != null && t.Namespace.StartsWith("Messages") &&
t.Namespace.EndsWith("Commands"));**
endpoint = await Endpoint.Start(endpointConfiguration)
.ConfigureAwait(false);
PerformStartupOperations();
var testMessage = new TestMessage {Id = Guid.NewGuid()};
await endpoint.Send(testMessage).ConfigureAwait(false);
}
catch (Exception exception)
{
logger.Fatal("Failed to start", exception);
Environment.FailFast("Failed to start", exception);
}
}
的TestMessage類
using System;
namespace Messages.Commands
{
public class TestMessage
{
public Guid Id { get; set; }
}
}
這一切都可以編譯和運行比,我不認爲事情
我有一個消息處理程序
TestMessageHandler性能警告罰款,其他
using System;
using System.Threading.Tasks;
using Messages.Commands;
using NServiceBus;
namespace IceProcessManager
{
public class TestMessageHandler : IHandleMessages<TestMessage>
{
public Task Handle(TestMessage message, IMessageHandlerContext context)
{
Console.WriteLine("Handled TEst MEssage ID:{0}", message.Id);
return Task.CompletedTask;
}
}
}
從截圖中可以看到,IceProcessManager沒有收到任何消息。我究竟做錯了什麼?我最初想的是,我發送的消息太早,即在ProcessManager啓動並運行之前,但這不是問題,因爲如果我離開ProcessManager運行(即從Explorer運行),則運行提取器,不會收到消息
理想情況下,我想發送大量的消息來測試這個,但我不熟悉異步的東西呢!
有人可以幫忙嗎?
Paul
DOH !!!!!如果我在複製粘貼後更改代碼,我想這會有所幫助!就是這樣,雖然當我改變這一點時,我驚訝地得到超過1條消息,也許我的消息被放在隊列中? – Paul
你是對的,每次你啓動端點時,消息都會被髮送到隊列中。 – sp1nakr