消费者关闭后会发生什么?(MassTransit)

时间:2016-11-21 11:24:34

标签: c# azure azureservicebus masstransit

我使用MassTransit编写消费者并使用Azure Service Bus作为传输。

public async Task Consume(ConsumeContext<ISimpleRequest> context)
{
    try
    {
        _log.InfoFormat("Strated working on {0}", context.Message.CustomerId);
        Thread.Sleep(500);
        _log.InfoFormat("Returning name for {0}", context.Message.CustomerId);
    }
    catch(Exception ex) 
    {
        await context.Redeliver(TimeSpan.FromSeconds(1));
    }
}

如果发生异常,我会将消息重新发送给其他消费者 但是如果总线发送消息,消费者开始处理它并且进程被关闭会发生什么?我怎能不丢失信息?

1 个答案:

答案 0 :(得分:0)

来自google group的答案:

仅在消费者完成其工作后才向传输确认(确认)消息。因此,对于任何未完成的使用者,如果是消费者中的应用程序停止或异常,该消息将保留在队列中。如果谈到正确的终止,这是不同的,因为一旦你需要busHandle在终止应用程序之前运行Stop(),它将等待当前正在处理的所有消息,在允许总线停止之前运行管道。

相关问题