如果消费者关闭会怎样?(MassTransit)

What happens if consumer shutdown?(MassTransit)

我使用 MassTransit 并使用 Azure 服务总线作为传输来编写消费者。

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));
    }
}

如果发生异常,我会重新向另一个消费者发送消息。
但是如果总线发送一条消息,消费者开始处理它并且进程被关闭,会发生什么?怎么才能不丢消息?

来自google group的回答:

只有在消费者完成其工作后,消息才会被确认(确认)到传输。因此,对于任何未完成的消费者,无论是应用程序停止还是消费者发生异常,消息都将保留在队列中。这是不同的,但如果谈到适当的终止,因为一旦你要求 busHandle 到 运行 Stop() 在终止应用程序之前,它将等待所有当前正在处理的消息,通过管道 运行在允许巴士停下之前。