【问题标题】:RabbitMq Consumers do Not ConsumeRabbitMq 消费者不消费
【发布时间】:2017-09-08 08:54:26
【问题描述】:
 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);
    }

消息类型StartAndNextCommand可以消费,而List类型不能消费,为什么?

【问题讨论】:

  • 但是 List 的类型无法消费

标签: masstransit consumer


【解决方案1】:

这是设计使然。我们只能消费一条消息。您可以签订新合同,例如:

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

然后拥有该消息类型的消费者

public async Task Consume(ConsumeContext<StartAndNextBatch> context)

但您还需要发布该消息类型

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

【讨论】: