hofnarwillie hofnarwillie - 23 days ago 7
C# Question

MassTransit Producer takes 60 seconds to Consume an event

I have 2 projects:


  1. A MassTransit (Topshelf Windows Service) called
    Service.Endpoints

  2. A Console App client trying to communicate with it called
    TestConsole
    .



The overall requirement is as follows:


  1. TestConsole
    sends
    SolveProblemCommand

  2. Service.Endpoints
    Consumes the command and Publishes
    ProblemSolvedEvent

  3. TestConsole
    Consumes the event.



The problem:



All the above steps work fine except that step 3 (
TestConsole
consuming the event) only happens around 60 seconds after the event is published. The following error is displayed first (after 60 seconds) and then the Consumer received the call.

Timeout waiting for consumer to exit: rabbitmq://localhost:5672/bus-PC-NAME-TestConsole.vshost-4sboyydjz6ne6mz6bdky1b7ad4?durable=false&autodelete=true&prefetch=16


Timeout waiting for consumer to exit: rabbitmq://localhost:5672/problemsolved.queue?prefetch=16

The code:



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

Answer

In the TestConsole.csproj project I reuse the same IBusControl object to send the command and to consume the event. Once I created two separate bus objects it worked as expected.