docs: clarify KafkaProducer.send() return value methods #2658
+6
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR improves the documentation for the
KafkaProducer.send()
method by clarifying what methods are available on the returnedFutureRecordMetadata
object.Motivation
While practising the Kafka Python package by trying to build a consumer, I have tried to understand what was is that KafkaProducer.send() method was returning as an object.
Currently, the documentation, as per generated by Sphinx + autodoc did not display such information, states that
send()
returns aFutureRecordMetadata
that "resolves to RecordMetadata", but it doesn't explain how to actually use this future object. Users need to dig through the source code to discover methods likeget()
,add_callback()
, andadd_errback()
.Changes
Returns
section ofKafkaProducer.send()
docstringget(timeout=None)
: for synchronous/blocking behavioradd_callback(fn)
: for handling successful sends asynchronouslyadd_errback(fn)
: for handling failed sends asynchronouslyTesting
Notes
I considered adding more detailed documentation directly on the
FutureRecordMetadata
class, but since it's not part of the public API (not exported in__init__.py
), I kept the changes minimal and focused on the user-facingsend()
method.Thank you for considering this contribution!