How to stop Azure worker without losing any message?

佐手、 提交于 2019-12-11 10:43:19

问题


Actually, when I want to stop my worker on azure, this function is called.

    public override void OnStop()
    {
        if (messageProvider != null)
        {
            messageProvider.StopListening();
        }

        base.OnStop();
    }

When I upgrade the worker, If there is any message beeing processed, I lose that message. Do you know how can I safely stop my worker?


回答1:


You have five minutes, from the time OnStop() is called, and before OnStop() exits, to finish your current processing (whatever that means). In your case, it looks like you have some type of message provider, and you're able to disengage from message-consumption via messageProvider.StopListening();. Since you're concerned with processing of current message, you'd likely need some type of signal to let you know that there are no messages being processed (including ones that may have been read, but not processed, by the time you called StopListening()), and that it's safe to exit from OnStop(). How you implement the signal is up to you, but you'd need to wait for the signal within Onstop().

FYI info about OnStop() and the five-minute window is here.



来源:https://stackoverflow.com/questions/32561257/how-to-stop-azure-worker-without-losing-any-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!