diff options
author | Berkodev <saar.berk@gmail.com> | 2018-03-29 22:39:04 +0300 |
---|---|---|
committer | Dana Powers <dana.powers@gmail.com> | 2018-03-29 12:39:04 -0700 |
commit | 4267ed582e6be6d599ddd54ce3e5a5921651fcad (patch) | |
tree | b8d1daf28e4f9d97692f7caee2722da81bae17cd /docs/usage.rst | |
parent | 4c87d11c26e2aa5a60de0b2213dd8caa3b16d553 (diff) | |
download | kafka-python-4267ed582e6be6d599ddd54ce3e5a5921651fcad.tar.gz |
Adds add_callback/add_errback example to docs (#1441)
Diffstat (limited to 'docs/usage.rst')
-rw-r--r-- | docs/usage.rst | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/docs/usage.rst b/docs/usage.rst index 22fe20d..1cf1aa4 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -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() |