-
Notifications
You must be signed in to change notification settings - Fork 901
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support rd_kafka_memberid() from python clients #1154
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright 2021 Confluent Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limit | ||
|
||
|
||
def test_consumer_memberid(kafka_cluster): | ||
""" | ||
Test consumer memberid. | ||
""" | ||
|
||
consumer_conf = {'group.id': 'test'} | ||
|
||
topic = "testmemberid" | ||
|
||
kafka_cluster.create_topic(topic) | ||
|
||
consumer = kafka_cluster.consumer(consumer_conf) | ||
|
||
jliunyu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert consumer is not None | ||
assert len(consumer.memberid()) == 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you should check that the memberid is None rather than have a 0 length (which could be an empty string or some other type). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi Magnus, thanks for reviewing. I found that the consumer.memberid() is "" here when I do the test. But do you think None should be the expected result or "" is also Okay? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question. I think it should be None as that seems more Pythonic. |
||
kafka_cluster.seed_topic(topic, value_source=[b'memberid']) | ||
|
||
consumer.subscribe([topic]) | ||
msg = consumer.poll(10) | ||
assert msg is not None | ||
assert msg.value() == b'memberid' | ||
assert isinstance(consumer.memberid(), str) is True | ||
assert len(consumer.memberid()) > 0 | ||
jliunyu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
consumer.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't expose the librdkafka name here, but the python one, so something like:
- Added consumer.memberid() method to retrieve the consumer's group member id (#1154)