Add read-only config attribute to Consumer, Producer, ShareConsumer - #2342
Open
Paradox (i-am-paradox) wants to merge 2 commits into
Open
Add read-only config attribute to Consumer, Producer, ShareConsumer#2342Paradox (i-am-paradox) wants to merge 2 commits into
Paradox (i-am-paradox) wants to merge 2 commits into
Conversation
Expose the effective configuration of a client instance through a read-only config attribute, so applications can inspect the values actually in use without tracking the dict passed to the constructor. The dict is built from rd_kafka_conf() on the client instance and rd_kafka_conf_dump(), so it reflects librdkafka defaults applied on top of the user configuration. Properties that hold internal non-string values in the dump (callback pointers, opaque) are left out, they are bindings implementation details. Values are reported as strings, which is what librdkafka's config dump returns. Fixes confluentinc#465
Paradox (i-am-paradox)
requested review from
a team and
Matthew Seal (MSeal)
as code owners
August 31, 2026 03:45
|
Please sign the Contributor License Agreement here before this PR can be approved. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This adds a read-only
configattribute toConsumer,ProducerandShareConsumer, as requested in #465. The AIO wrappers keep their own composition style and are not touched.The attribute returns a dict of the effective configuration of the instance: it is built from
rd_kafka_conf()on the client handle followed byrd_kafka_conf_dump(), so it shows the values actually in use, including librdkafka defaults applied on top of the dict passed to the constructor. The dict is a fresh copy on every access, mutating it does not affect the client.Two notes on the behaviour:
*_cbpointers set by the bindings,opaque,socket_cbandopen_cb. Callbacks passed by the application in the config dict never appear in the dump anyway.rd_kafka_conf_dump()returns.client.idcomes back as the configured string,session.timeout.msas'1000'and so on. I kept them as-is rather than trying to parse known numeric keys, the round-trip throughint()looked like more guessing than value, but I can convert the well-known numeric properties if that's preferred.bootstrap.serverscan come back asNonein the dump when it was consumed into the instance, that is how librdkafka reports it, I left the value untouched.Tests are in
tests/test_misc.pyand run without a broker: reading the config of a Producer and a Consumer and checking configured values against the dump, checking that a librdkafka default (api.version.request) is present, that the dict is a detached copy, that the attribute has no setter, and thaterror_cbpassed in the config dict does not show up.On this machine the unit test files give the same result before and after this change (36 pre-existing failures in the AIO tests, they need dependencies I don't have set up locally), with the 4 new tests passing on top.
Fixes #465