# Safely publish an event using libbeat

**URL:** <https://discuss.elastic.co/t/safely-publish-an-event-using-libbeat/52395>\
**Category:** Beats\
**Created:** [June 10, 2016, 1:23am UTC](https://discuss.elastic.co/t/safely-publish-an-event-using-libbeat/52395 "2016-06-10T01:23:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lukejolly](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukejolly/32/9951_2.png) [@lukejolly](https://discuss.elastic.co/u/lukejolly)\
**Post date:** [June 10, 2016, 1:23am UTC](https://discuss.elastic.co/t/safely-publish-an-event-using-libbeat/52395/1 "2016-06-10T01:23:42Z")

</div>

So I'm at a loss on how to go about publishing an event and being sure it was a success. If I use publisher.Client.PublishEvent(m, publisher.Sync) and the output (in my test case logstash) isn't up, it blocks forever instead of timing out and returing false. This hangs the beat requiring a SIGKILL to stop it. Am I doing something wrong or is this a bug?

---

<div class="post-metadata">

**Author:** ![ruflin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ruflin/32/3116_2.png) [@ruflin](https://discuss.elastic.co/u/ruflin)\
**Post date:** [June 10, 2016, 6:31am UTC](https://discuss.elastic.co/t/safely-publish-an-event-using-libbeat/52395/2 "2016-06-10T06:31:59Z")

</div>

The client has a Close() method which must be used in the case of sync publisher. See here the implementation in Filebeat: [https://github.com/elastic/beats/blob/master/filebeat/beater/publish.go#L125](https://github.com/elastic/beats/blob/master/filebeat/beater/publish.go#L125)

Here are the docs for the client: [https://godoc.org/github.com/elastic/beats/libbeat/publisher#Client](https://godoc.org/github.com/elastic/beats/libbeat/publisher#Client)

---

<div class="post-metadata">

**Author:** ![steffens](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/steffens/32/79630_2.png) [@steffens](https://discuss.elastic.co/u/steffens)\
**Post date:** [June 10, 2016, 10:52am UTC](https://discuss.elastic.co/t/safely-publish-an-event-using-libbeat/52395/3 "2016-06-10T10:52:51Z")

</div>

options understood by `Publish`:

- `publisher.Sync`: block PublishEvent until either event has been send or event is dropped due to max\_retries
- `publisher.Guaranteed`: Never drop event. Keep event in output pipeline until ACKed by output. Can be used without sync for async guaranteed publishing.
- `publisher.Signal`: Callback for publish requests. E.g. used in filebeat in conjunction with `publisher.Guaranteed` to update file state offsets once events have been ACKed by output.

Filebeat supports both mode. Sync publishing: [https://github.com/elastic/beats/blob/master/filebeat/beater/publish.go#L110](https://github.com/elastic/beats/blob/master/filebeat/beater/publish.go#L110)  
and async publishing: [https://github.com/elastic/beats/blob/master/filebeat/beater/publish.go#L166](https://github.com/elastic/beats/blob/master/filebeat/beater/publish.go#L166)

If output (logstash/elasticsearch/...) is unresponsive and buffers in publisher pipeline (both, in sync and async mode) are full, PublishEvent(s) will block. In order to guarantee proper shutdown one has to dicsonnect from publisher pipeline via `Close`. Once `Close` is called, the publisher pipeline will not give any guarantees to events being queued. Events might be send or not.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 1, 2016, 1:23am UTC](https://discuss.elastic.co/t/safely-publish-an-event-using-libbeat/52395/4 "2016-07-01T01:23:52Z")

</div>

This topic was automatically closed after 21 days. New replies are no longer allowed.
