提交 697a2420 authored 作者: 张立波's avatar 张立波

nsq

上级 d6a45a44
...@@ -7,15 +7,20 @@ import ( ...@@ -7,15 +7,20 @@ import (
) )
type NsqConfig struct { type NsqConfig struct {
Topic string Topic string
Channel string Channel string
Addr string Addr string
Handler nsq.Handler MaxInFlight int
Handler nsq.Handler
} }
func InitConsumer(consumer *NsqConfig) { func InitConsumer(consumer *NsqConfig) {
cfg := nsq.NewConfig() cfg := nsq.NewConfig()
cfg.LookupdPollInterval = time.Second * 30 //设置重连时间 cfg.LookupdPollInterval = time.Second * 30
if consumer.MaxInFlight > 0 {
cfg.MaxInFlight = consumer.MaxInFlight
}
//设置重连时间
c, err := nsq.NewConsumer(consumer.Topic, consumer.Channel, cfg) // 新建一个消费者 c, err := nsq.NewConsumer(consumer.Topic, consumer.Channel, cfg) // 新建一个消费者
if logs.CheckErr(err, "InitConsumer") { if logs.CheckErr(err, "InitConsumer") {
return return
...@@ -30,6 +35,9 @@ func InitConsumer(consumer *NsqConfig) { ...@@ -30,6 +35,9 @@ func InitConsumer(consumer *NsqConfig) {
func InitBatchConsumer(consumer *NsqConfig, clientNum int) { func InitBatchConsumer(consumer *NsqConfig, clientNum int) {
cfg := nsq.NewConfig() cfg := nsq.NewConfig()
if consumer.MaxInFlight > 0 {
cfg.MaxInFlight = consumer.MaxInFlight
}
cfg.LookupdPollInterval = time.Second * 30 //设置重连时间 cfg.LookupdPollInterval = time.Second * 30 //设置重连时间
c, err := nsq.NewConsumer(consumer.Topic, consumer.Channel, cfg) // 新建一个消费者 c, err := nsq.NewConsumer(consumer.Topic, consumer.Channel, cfg) // 新建一个消费者
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论