go-queue
go-queue copied to clipboard
push.close() 后程序退出丢失消息
-
https://github.com/zeromicro/go-queue/blob/master/kq/pusher.go
-
p.Push()
后Push.Close()
没有等数据发送完就返回了, 这个时候程序退出 , 消息并没有发送出去就没了 -
运行环境
go version go1.19.2 linux/amd64
- 示例
package main
import (
"fmt"
"log"
"time"
"github.com/zeromicro/go-queue/kq"
)
func main() {
push := kq.NewPusher([]string{"localhost:9092"}, "pushtest",
kq.WithChunkSize(5000000),
kq.WithFlushInterval(5 * time.Second))
defer push.Close()
for i:=0; i<10; i++ {
err := push.Push(fmt.Sprintf("Hello world: %d", i))
if err != nil {
log.Panic(err)
}
}
}