加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
index.go 1.29 KB
一键复制 编辑 原始数据 按行查看 历史
周睿 提交于 2020-08-20 17:35 . init
package gqueue
import (
"gitee.com/zr233/gqueue/adapter"
"github.com/Shopify/sarama"
)
var core = NewQueue()
var producer adapter.Producer
func init() {
_, _ = core.UseOrigin(adapter.NewOriginConfig())
}
type Queue struct {
adapter.Adaptor
}
func NewQueue() *Queue {
q := &Queue{}
return q
}
func (q *Queue) UseKafka(zkHosts []string, config *sarama.Config) (q_ *Queue, err error) {
q_ = q
q.Adaptor, err = adapter.NewKafka(zkHosts, config)
return
}
func (q *Queue) UseOrigin(cfg *adapter.OriginConfig) (q_ *Queue, err error) {
q_ = q
q.Adaptor, err = adapter.NewOrigin(cfg)
return
}
func NewMessage() *sarama.ProducerMessage {
return &sarama.ProducerMessage{}
}
func NewProducer() (p adapter.Producer, err error) {
p, err = core.NewProducer()
producer = p
return
}
// Errors is the error output channel back to the user. You MUST read from this
// channel or the Producer will deadlock when the channel is full. Alternatively,
// you can set Producer.Return.Errors in your config to false, which prevents
// errors to be returned.
func Errors() <-chan *sarama.ProducerError {
return producer.Errors()
}
func NewConsumer(topic, groupId string) (p adapter.Consumer, err error) {
return core.NewConsumer(topic, groupId)
}
func Input() chan<- *sarama.ProducerMessage {
return producer.Input()
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化