chore(queue): Support NATS as backend (#618)
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
@@ -67,7 +67,11 @@ queue:
|
||||
nsq:
|
||||
addr: 127.0.0.1:4150
|
||||
topic: gorush
|
||||
channel: ch
|
||||
channel: gorush
|
||||
nats:
|
||||
addr: 127.0.0.1:4222
|
||||
subj: gorush
|
||||
queue: gorush
|
||||
|
||||
ios:
|
||||
enabled: false
|
||||
@@ -211,8 +215,9 @@ type SectionStat struct {
|
||||
|
||||
// SectionQueue is sub section of config.
|
||||
type SectionQueue struct {
|
||||
Engine string `yaml:"engine"`
|
||||
NSQ SectionNSQ `yaml:"nsq"`
|
||||
Engine string `yaml:"engine"`
|
||||
NSQ SectionNSQ `yaml:"nsq"`
|
||||
NATS SectionNATS `yaml:"nats"`
|
||||
}
|
||||
|
||||
// SectionNSQ is sub section of config.
|
||||
@@ -222,6 +227,13 @@ type SectionNSQ struct {
|
||||
Channel string `yaml:"channel"`
|
||||
}
|
||||
|
||||
// SectionNATS is sub section of config.
|
||||
type SectionNATS struct {
|
||||
Addr string `yaml:"addr"`
|
||||
Subj string `yaml:"subj"`
|
||||
Queue string `yaml:"queue"`
|
||||
}
|
||||
|
||||
// SectionRedis is sub section of config.
|
||||
type SectionRedis struct {
|
||||
Addr string `yaml:"addr"`
|
||||
@@ -367,6 +379,9 @@ func LoadConf(confPath ...string) (ConfYaml, error) {
|
||||
conf.Queue.NSQ.Addr = viper.GetString("queue.nsq.addr")
|
||||
conf.Queue.NSQ.Topic = viper.GetString("queue.nsq.topic")
|
||||
conf.Queue.NSQ.Channel = viper.GetString("queue.nsq.channel")
|
||||
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")
|
||||
|
||||
// Stat Engine
|
||||
conf.Stat.Engine = viper.GetString("stat.engine")
|
||||
|
||||
@@ -92,7 +92,11 @@ func (suite *ConfigTestSuite) TestValidateConfDefault() {
|
||||
assert.Equal(suite.T(), "local", suite.ConfGorushDefault.Queue.Engine)
|
||||
assert.Equal(suite.T(), "127.0.0.1:4150", suite.ConfGorushDefault.Queue.NSQ.Addr)
|
||||
assert.Equal(suite.T(), "gorush", suite.ConfGorushDefault.Queue.NSQ.Topic)
|
||||
assert.Equal(suite.T(), "ch", suite.ConfGorushDefault.Queue.NSQ.Channel)
|
||||
assert.Equal(suite.T(), "gorush", suite.ConfGorushDefault.Queue.NSQ.Channel)
|
||||
|
||||
assert.Equal(suite.T(), "127.0.0.1:4222", suite.ConfGorushDefault.Queue.NATS.Addr)
|
||||
assert.Equal(suite.T(), "gorush", suite.ConfGorushDefault.Queue.NATS.Subj)
|
||||
assert.Equal(suite.T(), "gorush", suite.ConfGorushDefault.Queue.NATS.Queue)
|
||||
|
||||
// log
|
||||
assert.Equal(suite.T(), "string", suite.ConfGorushDefault.Log.Format)
|
||||
|
||||
8
config/testdata/config.yml
vendored
8
config/testdata/config.yml
vendored
@@ -50,11 +50,15 @@ 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" and "nats " default value is "local"
|
||||
nsq:
|
||||
addr: 127.0.0.1:4150
|
||||
topic: gorush
|
||||
channel: ch
|
||||
channel: gorush
|
||||
nats:
|
||||
addr: 127.0.0.1:4222
|
||||
subj: gorush
|
||||
queue: gorush
|
||||
|
||||
ios:
|
||||
enabled: false
|
||||
|
||||
Reference in New Issue
Block a user