将对象添加到队列后,我无法检索该对象,添加它的代码如下所示,只要我在队列中获取消息就可以正常工作。
var connection = "amqp://name:password@localhost";
using (var activator = new BuiltinHandlerActivator())
{
Configure.With(activator)
.Logging(l => l.ColoredConsole())
.Transport(t => t.UseRabbitMqAsOneWayClient(connection).ExchangeNames(directExchangeName: "WamosExchange")) // .ExchangeNames(directExchangeName: "WamosExchange")
.Routing(r => r.TypeBased()
.Map<Wagon>("wagon_v1"))
.Start();
var wagon = new Wagon
{
Token = Guid.Parse("3CCE443C-249F-4FD2-9882-5830FB308B6B"),
WagonId = Guid.Parse("A98A06AB-33B9-4A11-9DE2-DF0B8787B713"),
Description = "test",
WamosId = 12324,
YearBuilt = 1982
};
await activator.Bus.Send(wagon);
Console.WriteLine("Done");
}
检索它的代码如下(这不起作用)。我在RabbitMq中使用了一个使用wagon_v1队列的交换。我看到rebus正在创建另一个用红色突出显示的。有点混乱。我希望它使用 wagon_v1 队列 WamosExchange 。
static BuiltinHandlerActivator activator = new BuiltinHandlerActivator();
static async Task MainSubscribeAsync()
{
var connection = "amqp://name:password@localhost";
activator.Register(() => new WagonHandler());
var bus = Configure.With(activator)
.Logging(l => l.ColoredConsole())
.Transport(t => t.UseRabbitMq(connection, "wagon_v1")
.ExchangeNames(directExchangeName: "WamosExchange"))
.Routing(r => r.TypeBased()
.Map<Wagon>("wagon_v1"))
.Options(o =>
{
o.SetMaxParallelism(10);
o.SetNumberOfWorkers(10);
})
.Start();
await bus.Subscribe<Wagon>();
Console.WriteLine("Done");
}
处理程序如下:
class WagonHandler : IHandleMessages
{
public void Handle(Wagon message)
{
Console.WriteLine($"Token {message.Token}");
Console.WriteLine($"WagonId {message.WagonId}");
}
}
我在尝试订阅时遇到此错误
Rebus.Retry.ErrorTracking.InMemErrorTracker WARN (Rebus 1 worker 4): Unhandled exception 1 while handling message with ID "f26daec4-48e2-47ca-a3fe-b4f18bc9b217"
Rebus.Retry.ErrorTracking.InMemErrorTracker WARN (Rebus 1 worker 2): Unhandled exception 2 while handling message with ID "f26daec4-48e2-47ca-a3fe-b4f18bc9b217"
Rebus.Retry.ErrorTracking.InMemErrorTracker WARN (Rebus 1 worker 8): Unhandled exception 3 while handling message with ID "f26daec4-48e2-47ca-a3fe-b4f18bc9b217"
Rebus.Retry.ErrorTracking.InMemErrorTracker WARN (Rebus 1 worker 7): Unhandled exception 4 while handling message with ID "f26daec4-48e2-47ca-a3fe-b4f18bc9b217"
Rebus.Retry.ErrorTracking.InMemErrorTracker WARN (Rebus 1 worker 6): Unhandled exception 5 while handling message with ID "f26daec4-48e2-47ca-a3fe-b4f18bc9b217"
Rebus.Retry.PoisonQueues.PoisonQueueErrorHandler ERROR (Rebus 1 worker 5): Moving message with ID "f26daec4-48e2-47ca-a3fe-b4f18bc9b217" to error queue "error"
System.AggregateException: 5 unhandled exceptions ---> Rebus.Exceptions.RebusApplicationException: Message with ID f26daec4-48e2-47ca-a3fe-b4f18bc9b217 and type ThreeSquared.VTGPAM.Objects.Wagon, ThreeSquared.VTGPAM.Objects could not be dispatched to any handlers
at Rebus.Pipeline.Receive.DispatchIncomingMessageStep.<Process>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
答案 0 :(得分:1)
如错误消息所述,找不到处理Wagon
的消息处理程序。
您的处理程序
class WagonHandler : IHandleMessages
{
public void Handle(Wagon message)
{
Console.WriteLine($"Token {message.Token}");
Console.WriteLine($"WagonId {message.WagonId}");
}
}
Rebus无法找到,因为它查找IHandleMessages<Wagon>
的实现,并且您只使用了基本接口IHandleMessages
。
实施IHandleMessages<Wagon>
要求您稍微更改方法签名 - 它应如下所示:
class WagonHandler : IHandleMessages<Wagon>
{
public async Task Handle(Wagon message)
{
Console.WriteLine($"Token {message.Token}");
Console.WriteLine($"WagonId {message.WagonId}");
}
}