Skip to content

Commit 4267ed5

Browse files
Berkodevdpkp
authored andcommitted
Adds add_callback/add_errback example to docs (#1441)
1 parent 4c87d11 commit 4267ed5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

docs/usage.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,18 @@ KafkaProducer
9191
for _ in range(100):
9292
producer.send('my-topic', b'msg')
9393
94+
def on_send_success(record_metadata):
95+
print(record_metadata.topic)
96+
print(record_metadata.partition)
97+
print(record_metadata.offset)
98+
99+
def on_send_error(excp):
100+
log.error('I am an errback', exc_info=excp)
101+
# handle exception
102+
103+
# produce asynchronously with callbacks
104+
producer.send('my-topic', b'raw_bytes').add_callback(on_send_success).add_errback(on_send_error)
105+
94106
# block until all async messages are sent
95107
producer.flush()
96108

0 commit comments

Comments
 (0)