3 Star 5 Fork 3

三三物联网/ssiot-core

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
queue.go 1.59 KB
一键复制 编辑 原始数据 按行查看 历史
三三物联网 提交于 2023-04-03 00:22 . 重构
package config
import (
"gitee.com/sansaniot/ssiot-core/storage"
"gitee.com/sansaniot/ssiot-core/storage/queue"
"github.com/go-redis/redis/v7"
"github.com/robinjoseph08/redisqueue/v2"
"time"
)
type Queue struct {
Redis *QueueRedis
Memory *QueueMemory
NSQ *QueueNSQ `json:"nsq" yaml:"nsq"`
}
type QueueRedis struct {
RedisConnectOptions
Producer *redisqueue.ProducerOptions
Consumer *redisqueue.ConsumerOptions
}
type QueueMemory struct {
PoolSize uint
}
type QueueNSQ struct {
NSQOptions
ChannelPrefix string
}
var QueueConfig = new(Queue)
// Empty 空设置
func (e Queue) Empty() bool {
return e.Memory == nil && e.Redis == nil && e.NSQ == nil
}
// Setup 启用顺序 redis > 其他 > memory
func (e Queue) Setup() (storage.AdapterQueue, error) {
if e.Redis != nil {
e.Redis.Consumer.ReclaimInterval = e.Redis.Consumer.ReclaimInterval * time.Second
e.Redis.Consumer.BlockingTimeout = e.Redis.Consumer.BlockingTimeout * time.Second
e.Redis.Consumer.VisibilityTimeout = e.Redis.Consumer.VisibilityTimeout * time.Second
client := GetRedisClient()
if client == nil {
options, err := e.Redis.RedisConnectOptions.GetRedisOptions()
if err != nil {
return nil, err
}
client = redis.NewClient(options)
_redis = client
}
e.Redis.Producer.RedisClient = client
e.Redis.Consumer.RedisClient = client
return queue.NewRedis(e.Redis.Producer, e.Redis.Consumer)
}
if e.NSQ != nil {
cfg, err := e.NSQ.GetNSQOptions()
if err != nil {
return nil, err
}
return queue.NewNSQ(e.NSQ.Addresses, cfg, e.NSQ.ChannelPrefix)
}
return queue.NewMemory(e.Memory.PoolSize), nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sansaniot/ssiot-core.git
git@gitee.com:sansaniot/ssiot-core.git
sansaniot
ssiot-core
ssiot-core
v1.6.8

搜索帮助

0d507c66 1850385 C8b1a773 1850385