1 Star 0 Fork 0

zhangjungang/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
sync.go 1.18 KB
一键复制 编辑 原始数据 按行查看 历史
urso 提交于 2016-01-20 15:27 . Filebeat async publisher support
package publisher
import (
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/outputs"
)
type syncPublisher struct {
pub *PublisherType
}
type syncClient func(message) bool
func newSyncPublisher(pub *PublisherType, hwm, bulkHWM int) *syncPublisher {
return &syncPublisher{pub: pub}
}
func (p *syncPublisher) client() eventPublisher {
return p
}
func (p *syncPublisher) PublishEvent(ctx Context, event common.MapStr) bool {
msg := message{context: ctx, event: event}
return p.send(msg)
}
func (p *syncPublisher) PublishEvents(ctx Context, events []common.MapStr) bool {
msg := message{context: ctx, events: events}
return p.send(msg)
}
func (p *syncPublisher) send(m message) bool {
if p.pub.disabled {
debug("publisher disabled")
outputs.SignalCompleted(m.context.Signal)
return true
}
signal := m.context.Signal
sync := outputs.NewSyncSignal()
if len(p.pub.Output) > 1 {
m.context.Signal = outputs.NewSplitSignaler(sync, len(p.pub.Output))
} else {
m.context.Signal = sync
}
for _, o := range p.pub.Output {
o.send(m)
}
ok := sync.Wait()
if ok {
outputs.SignalCompleted(signal)
} else if signal != nil {
signal.Failed()
}
return ok
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangjungang/beats.git
git@gitee.com:zhangjungang/beats.git
zhangjungang
beats
beats
v1.1.0

搜索帮助