我有两个项目:
Service.Endpoints
TestConsole
。总体要求如下:
TestConsole
发送SolveProblemCommand
Service.Endpoints
使用命令并发布ProblemSolvedEvent
TestConsole
消费此活动。除了步骤3(消耗事件的TestConsole
)仅在事件发布后大约60秒发生时,上述所有步骤都能正常工作。首先显示以下错误(60秒后),然后消费者接到呼叫。
Timeout waiting for consumer to exit: rabbitmq://localhost:5672/bus-PC-NAME-TestConsole.vshost-4sboyydjz6ne6mz6bdky1b7ad4?durable=false&autodelete=true&prefetch=16
超时等待消费者退出:rabbitmq:// localhost:5672 / problemsolved.queue?prefetch = 16
bus = BusConfigurator.ConfigureBus(new AppSettings(), (cfg, host) =>
{
cfg.ReceiveEndpoint(host, RabbitMqConstants.SolveProblemQueue, e =>
{
e.Consumer<SolveProblemCommandConsumer>(NinjectConfig.CurrentKernel);
});
});
bus.Start();
class SolveProblemCommandConsumer : IConsumer<SolveProblemCommand>
{
public async Task Consume(ConsumeContext<SolveProblemCommand> context)
{
var controller = new Controller(context.Message.Problem);
var results = await controller.Start(context.Message.Options);
await context.Publish(new ProblemSolvedEvent(results));
}
}
var bus = BusConfigurator.ConfigureBus(new AppSettings(), (cfg, host) =>
{
cfg.ReceiveEndpoint(host, RabbitMqConstants.ProblemSolvedQueue, e =>
{
e.Consumer<ProblemSolvedEventConsumer>();
});
});
var sendToUri = new Uri($"{RabbitMqConstants.RabbitMqUri}{RabbitMqConstants.SolveProblemQueue}");
var endpoint = await bus.GetSendEndpoint(sendToUri);
bus.Start();
await endpoint.Send(someMessage);
class ProblemSolvedEventConsumer : IConsumer<ProblemSolvedEvent>
{
public async Task Consume(ConsumeContext<ProblemSolvedEvent> context)
{
...
}
}
答案 0 :(得分:0)
在TestConsole.csproj
项目中,我重用相同的IBusControl
对象来发送命令并使用该事件。一旦我创建了两个独立的总线对象,它就按预期工作了。