MassTransit Producer需要60秒才能完成一次活动

时间:2016-11-10 01:35:44

标签: c# rabbitmq microservices masstransit

我有两个项目:

  1. 名为Service.Endpoints
  2. 的MassTransit(Topshelf Windows服务)
  3. 尝试与之通信的控制台应用程序客户端,名为TestConsole
  4. 总体要求如下:

    1. TestConsole发送SolveProblemCommand
    2. Service.Endpoints使用命令并发布ProblemSolvedEvent
    3. TestConsole消费此活动。
    4. 问题:

      除了步骤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

      代码:

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

1 个答案:

答案 0 :(得分:0)

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