Skip to content

signals

Tony edited this page Jul 6, 2022 · 2 revisions

信号处理

通过发送 TERM 或 INT 信号可非强杀方式(gracefully shutdown)关停队列消费者。

kill -TERM <pid> # 关停队列消费者

可结合 giant-stone/go/gracequit 包快速实现通用服务端进程信号处理

	import (
		"github.com/giant-stone/go/gracequit"
	)

	// ...
	quitAfterSecs := 2
	gq := gracequit.New(
		"path/to/pid",
		quitAfterSecs,
	)
	gq.FuncCallBeforeQuit = myDeadwordsFunc
	ctx := gq.Init()

	srv := gmq.NewServer(ctx)

	// ...
Clone this wiki locally