MassTransit Producer 需要 60 秒来消费一个事件

MassTransit Producer takes 60 seconds to Consume an event

我有 2 个项目:

  1. MassTransit(顶架 Windows 服务)称为 Service.Endpoints
  2. 试图与其通信的控制台应用程序客户端名为 TestConsole

总体要求如下:

  1. TestConsole 发送 SolveProblemCommand
  2. Service.Endpoints 使用命令并发布 ProblemSolvedEvent
  3. TestConsole 消耗事件。

问题:

除了第 3 步(TestConsole 使用事件)仅在事件发布后约 60 秒发生,上述所有步骤都可以正常工作。先显示如下错误(60秒后),然后Consumer接到电话。

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

代码:

Service.Endpoints.csproj

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

TestConsole.csproj

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)
    {
        ...
    }
}

TestConsole.csproj 项目中,我重复使用相同的 IBusControl 对象来发送命令和使用事件。一旦我创建了两个单独的总线对象,它就会按预期工作。