Ai
2 Star 0 Fork 1

JUMEI_ARCH/go-plugins
暂停

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
options.go 1.59 KB
一键复制 编辑 原始数据 按行查看 历史
wuxinfei 提交于 2018-07-09 16:47 +08:00 . rename variable name
package nsq
import (
"context"
"time"
"github.com/micro/go-micro/broker"
nsq "github.com/nsqio/go-nsq"
)
type concurrentHandlerKey struct{}
type maxInFlightKey struct{}
type asyncPublishKey struct{}
type deferredPublishKey struct{}
type lookupdAddrsKey struct{}
type consumerOptsKey struct{}
func WithConcurrentHandlers(n int) broker.SubscribeOption {
return func(o *broker.SubscribeOptions) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, concurrentHandlerKey{}, n)
}
}
func WithMaxInFlight(n int) broker.SubscribeOption {
return func(o *broker.SubscribeOptions) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, maxInFlightKey{}, n)
}
}
func WithAsyncPublish(doneChan chan *nsq.ProducerTransaction) broker.PublishOption {
return func(o *broker.PublishOptions) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, asyncPublishKey{}, doneChan)
}
}
func WithDeferredPublish(delay time.Duration) broker.PublishOption {
return func(o *broker.PublishOptions) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, deferredPublishKey{}, delay)
}
}
func WithLookupdAddrs(addrs []string) broker.Option {
return func(o *broker.Options) {
o.Context = context.WithValue(o.Context, lookupdAddrsKey{}, addrs)
}
}
func WithConsumerOpts(consumerOpts []string) broker.Option {
return func(o *broker.Options) {
o.Context = context.WithValue(o.Context, consumerOptsKey{}, consumerOpts)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/JMArch/go-plugins.git
git@gitee.com:JMArch/go-plugins.git
JMArch
go-plugins
go-plugins
v0.14.1

搜索帮助