chore(queue): support Redis pub/sub (#652)

This commit is contained in:
Bo-Yi Wu
2022-01-01 23:04:13 +08:00
committed by GitHub
parent ccbe874bf4
commit 3f411ebe89
8 changed files with 68 additions and 12 deletions

View File

@@ -63,7 +63,7 @@ huawei:
max_retry: 0 # resend fail notification, default value zero is disabled
queue:
engine: "local" # support "local", "nsq", default value is "local"
engine: "local" # support "local", "nsq", "nats" and "redis" default value is "local"
nsq:
addr: 127.0.0.1:4150
topic: gorush
@@ -72,6 +72,10 @@ queue:
addr: 127.0.0.1:4222
subj: gorush
queue: gorush
redis:
addr: 127.0.0.1:6379
channel: gorush
size: 1024
ios:
enabled: false
@@ -216,9 +220,10 @@ type SectionStat struct {
// SectionQueue is sub section of config.
type SectionQueue struct {
Engine string `yaml:"engine"`
NSQ SectionNSQ `yaml:"nsq"`
NATS SectionNATS `yaml:"nats"`
Engine string `yaml:"engine"`
NSQ SectionNSQ `yaml:"nsq"`
NATS SectionNATS `yaml:"nats"`
Redis SectionRedisQueue `yaml:"redis"`
}
// SectionNSQ is sub section of config.
@@ -235,6 +240,13 @@ type SectionNATS struct {
Queue string `yaml:"queue"`
}
// SectionRedisQueue is sub section of config.
type SectionRedisQueue struct {
Addr string `yaml:"addr"`
Channel string `yaml:"channel"`
Size int `yaml:"size"`
}
// SectionRedis is sub section of config.
type SectionRedis struct {
Cluster bool `yaml:"cluster"`
@@ -391,6 +403,9 @@ func LoadConf(confPath ...string) (*ConfYaml, error) {
conf.Queue.NATS.Addr = viper.GetString("queue.nats.addr")
conf.Queue.NATS.Subj = viper.GetString("queue.nats.subj")
conf.Queue.NATS.Queue = viper.GetString("queue.nats.queue")
conf.Queue.Redis.Addr = viper.GetString("queue.redis.addr")
conf.Queue.Redis.Channel = viper.GetString("queue.redis.channel")
conf.Queue.Redis.Size = viper.GetInt("queue.redis.size")
// Stat Engine
conf.Stat.Engine = viper.GetString("stat.engine")

View File

@@ -107,6 +107,10 @@ func (suite *ConfigTestSuite) TestValidateConfDefault() {
assert.Equal(suite.T(), "gorush", suite.ConfGorushDefault.Queue.NATS.Subj)
assert.Equal(suite.T(), "gorush", suite.ConfGorushDefault.Queue.NATS.Queue)
assert.Equal(suite.T(), "127.0.0.1:6379", suite.ConfGorushDefault.Queue.Redis.Addr)
assert.Equal(suite.T(), "gorush", suite.ConfGorushDefault.Queue.Redis.Channel)
assert.Equal(suite.T(), 1024, suite.ConfGorushDefault.Queue.Redis.Size)
// log
assert.Equal(suite.T(), "string", suite.ConfGorushDefault.Log.Format)
assert.Equal(suite.T(), "stdout", suite.ConfGorushDefault.Log.AccessLog)

View File

@@ -50,7 +50,7 @@ huawei:
max_retry: 0 # resend fail notification, default value zero is disabled
queue:
engine: "local" # support "local", "nsq" and "nats " default value is "local"
engine: "local" # support "local", "nsq", "nats" and "redis" default value is "local"
nsq:
addr: 127.0.0.1:4150
topic: gorush
@@ -59,6 +59,10 @@ queue:
addr: 127.0.0.1:4222
subj: gorush
queue: gorush
redis:
addr: 127.0.0.1:6379
channel: gorush
size: 1024
ios:
enabled: false