go: diskqueue磁盘队列使用 创建队列 ``` import "github.com/nsqio/go-diskqueue" buffer := diskqueue.New( name, // 很重要,关系到队列缓存文件的名字 config.GlobalLocalConfig.DiskQueueDir, 1024*1024*512*1, // 单个文件512M 4, // 最小4字节 1024*1024*4, // 最大消息4M 1000, // 每1000次写入同步 5*time.Second, // 每5s同步 func(lvl diskqueue.LogLevel, f string, args ...interface{}) { if lvl == diskqueue.INFO { log.Infof(f, args...) } else if lvl >= diskqueue.WARN { log.Errorf(f, args...) } }) ``` 读取队列: ``` select { case <-p.ctx.Done(): return case msg, ok := <-p.bufferQueue.ReadChan(): if !ok { log.Fatal("diskqueue read nil") return } // do sth on msg } ``` 来自 大脸猪 写于 2022-08-25 17:23 -- 更新于2022-08-25 17:34 -- 0 条评论