func publishEvents(client publisher.Client, events []common.MapStr) { // Sends event to beat (outputs). // Wait/Repeat until all events are published for { ok := client.PublishEvents(events, publisher.Confirm) if ok { break } } }
func (ab *AmqpBeat) publishStream(stream <-chan []*AmqpEvent, client publisher.Client, wg *sync.WaitGroup, isDryRun bool, dryRunsLeft int) { pubCount := int64(0) for evList := range stream { evCount := len(evList) payloads := make([]common.MapStr, evCount) for i, ev := range evList { payloads[i] = ev.body } logp.Debug("flow", "Publishing %d events", len(evList)) success := client.PublishEvents(payloads, publisher.Sync) pubCount += int64(evCount) ab.metrics <- &metric{"published.count", pubCount} for _, ev := range evList { if success { if isDryRun { dryRunsLeft-- if dryRunsLeft >= 0 { logp.Info("Suppressing Ack due to DryRun. %d dry runs left.", dryRunsLeft) } ev.acknowledger.Nack(ev.deliveryTag, false, true) if dryRunsLeft == 0 { // Stop and let the remaining messages get nack'ed ab.Stop() } } else { logp.Debug("flow", "Acked event") ev.acknowledger.Ack(ev.deliveryTag, false) } } else { logp.Err("Failed to publish event: %v", ev.body) ev.acknowledger.Nack(ev.deliveryTag, false, true) } } } wg.Done() }