kawabatas技術ブログ

試してみたことを書いていきます

PubSubのPullサブスクライバーのグレースフルシャットダウンについて

先日、Cloud PubSub の Pull サブスクライバーとして機能している Worker が終了するときに、処理であれば処理を終えてから停止してほしいなと思い(グレースフルシャットダウン)、調べていたところ、下の issue を発見した。

github.com

I roughly understand the want for this: that you'd want to close the connection to halt any further messages arriving and finish processing all in-memory messages, all preceding a shutdown of the application. However, Pub/Sub's model being what it is, I'm struggling to see why it would not be sufficient to nack all in-memory messages for some other consumer to process (or the application to process once it has restarted).

なるほど。

処理が途中で終わった場合、Ack を返さないので、PubSub はメッセージを再度送信する。

なので、Worker の処理を冪等を担保した実装にしてさえいれば、特にグレースフルシャットダウンについては考えなくても良さそう。