Skip to content

Commit

Permalink
Adds add_callback/add_errback example to docs (#1441)
Browse files Browse the repository at this point in the history
  • Loading branch information
Berkodev authored and dpkp committed Mar 29, 2018
1 parent 4c87d11 commit 4267ed5
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ KafkaProducer
for _ in range(100):
producer.send('my-topic', b'msg')
def on_send_success(record_metadata):
print(record_metadata.topic)
print(record_metadata.partition)
print(record_metadata.offset)
def on_send_error(excp):
log.error('I am an errback', exc_info=excp)
# handle exception
# produce asynchronously with callbacks
producer.send('my-topic', b'raw_bytes').add_callback(on_send_success).add_errback(on_send_error)
# block until all async messages are sent
producer.flush()
Expand Down

0 comments on commit 4267ed5

Please # to comment.