Andy
Andy

Reputation: 11

RabbitMq Consumers do Not Consume

 public class RequestConsumer :
    IConsumer<StartFlowCommand>,
    IConsumer<List<StartAndNextCommand>>
{
    readonly IWorkFlowHandler _flowHandler;
    public RequestConsumer(IContainer container)
    {
        _flowHandler = container.Resolve<IWorkFlowHandler>();
    }

    public async Task Consume(ConsumeContext<StartAndNextCommand> context)
    {
        var result =await  _flowHandler.WorkFlowStartNext(context.Message);
        await context.RespondAsync(result);
    }


    public async Task Consume(ConsumeContext<List<StartAndNextCommand>> context)
    {
        var result = await Task.Run(() => _flowHandler.WorkFlowStartNextBatch(context.Message));
        await context.RespondAsync(result);
    }

Message type of StartAndNextCommand can consume,but type of List are unable to consume,why?

Upvotes: 1

Views: 291

Answers (1)

Alexey Zimarev
Alexey Zimarev

Reputation: 19610

This is by design. We can only consume one message. You can have a new contract, like:

public interface StartAndNextBatch
{
    IList<StartAndNextCommand> Commands { get; }
}

and then have a consumer for that message type

public async Task Consume(ConsumeContext<StartAndNextBatch> context)

but you also need to publish that message type

await bus.Publish<StartAndNextBatch>(
    new { Commands = ... }
);

Upvotes: 1

Related Questions