summaryrefslogtreecommitdiff
path: root/docs/usage.rst
diff options
context:
space:
mode:
Diffstat (limited to 'docs/usage.rst')
-rw-r--r--docs/usage.rst12
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()