本文整理匯總了Golang中h12/me/kpax/model.Cluster類的典型用法代碼示例。如果您正苦於以下問題:Golang Cluster類的具體用法?Golang Cluster怎麽用?Golang Cluster使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Cluster類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Exec
func (cmd *TailCommand) Exec(cl model.Cluster) error {
if cmd.Format == "" {
var err error
cmd.Format, err = formatDetector{cl, cmd.Topic}.detect()
if err != nil {
return err
}
}
var partitions []int32
if cmd.Partition == -1 {
var err error
partitions, err = cl.Partitions(cmd.Topic)
if err != nil {
return err
}
} else {
partitions = []int32{int32(cmd.Partition)}
}
cr := consumer.New(cl)
var wg sync.WaitGroup
wg.Add(len(partitions))
for _, partition := range partitions {
start, err := cr.FetchOffsetByTime(cmd.Topic, partition, proto.Earliest)
if err != nil {
return err
}
end, err := cr.FetchOffsetByTime(cmd.Topic, partition, proto.Latest)
if err != nil {
return err
}
if start < end-int64(cmd.Count) {
start = end - int64(cmd.Count)
}
go func(partition int32, start, end int64) {
defer wg.Done()
offset := start
for offset < end {
messages, err := cr.Consume(cmd.Topic, partition, offset)
if err != nil {
log.Println(err)
return
}
if len(messages) == 0 {
break
}
for _, msg := range messages {
line, err := cmd.Format.Sprint(msg.Value)
if err != nil {
log.Println(err)
break
}
fmt.Println(line)
}
offset = messages[len(messages)-1].Offset + 1
}
}(partition, start, end)
}
wg.Wait()
return nil
}
示例2: Produce
func (p *Payload) Produce(c model.Cluster) error {
leader, err := c.Leader(p.Topic, p.Partition)
if err != nil {
return err
}
if err := p.DoProduce(leader); err != nil {
if IsNotLeader(err) {
c.LeaderIsDown(p.Topic, p.Partition)
}
return err
}
return nil
}
示例3: Commit
func (o *Offset) Commit(c model.Cluster) error {
coord, err := c.Coordinator(o.Group)
if err != nil {
return err
}
if err := o.DoCommit(coord); err != nil {
if IsNotCoordinator(err) {
c.CoordinatorIsDown(o.Group)
}
return err
}
return nil
}
示例4: Fetch
func (o *OffsetByTime) Fetch(c model.Cluster) (int64, error) {
leader, err := c.Leader(o.Topic, o.Partition)
if err != nil {
return -1, err
}
offset, err := o.DoFetch(leader)
if err != nil {
if IsNotLeader(err) {
c.LeaderIsDown(o.Topic, o.Partition)
}
return -1, err
}
return offset, nil
}
示例5: Consume
func (m *Messages) Consume(c model.Cluster) (MessageSet, error) {
leader, err := c.Leader(m.Topic, m.Partition)
if err != nil {
return nil, err
}
ms, err := m.DoConsume(leader)
if err != nil {
if IsNotLeader(err) {
c.LeaderIsDown(m.Topic, m.Partition)
}
return nil, err
}
return ms, nil
}