Skip to content

Allow injecting clients into Kafka Consumers and Producers. #735

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

Closed
wants to merge 3 commits into from

Conversation

Julian
Copy link

@Julian Julian commented Jun 21, 2016

We use the older interfaces and are considering evaluating the newer ones, but in order to do any testing, we need to be able to inject fake clients into consumers and producers to prevent them from doing networking.

It would also be nice to prevent some of the other side effects that happen in init on these newer objects, but that work isn't done yet here.

Love to hear your thoughts obviously. Cheers.


This change is Reviewable

@@ -201,6 +204,8 @@ class KafkaConsumer(six.Iterator):
}

def __init__(self, *topics, **configs):
client = configs.pop("client", None)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pattern we've been using so far is to put this in the class-level DEFAULT_CONFIG dict. Just add an entry for 'client': None

@dpkp
Copy link
Owner

dpkp commented Jun 21, 2016

Just a few comments inline re: how to set default config values

@Julian
Copy link
Author

Julian commented Jun 21, 2016

Moved. Thanks.

@dpkp
Copy link
Owner

dpkp commented Jun 21, 2016

Thanks -- I'll wait for tests to pass and then merge.

@@ -270,7 +274,7 @@ def __init__(self, **configs):
if self.config['acks'] == 'all':
self.config['acks'] = -1

client = KafkaClient(**self.config)
self.client = self.config['client'] or KafkaClient(**self.config)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should just be client = not self.client

@dpkp
Copy link
Owner

dpkp commented Jul 8, 2016

tests are failing

@jeffwidman
Copy link
Contributor

@Julian I know this is super late, but are you still interested in updating this or should we close it?

I think it's a good idea, although if your rationale is injecting fake clients purely for testing purposes, the work of #1032 / #1230 (rationale in #560) may make your life easier for testing the protocol layer separate from the network layer.

@Julian
Copy link
Author

Julian commented Oct 7, 2017

@jeffwidman that looks promising! It looks like I've already seen #560 before (we currently use afkak for the Twisted case) so definite +1 from me. Afkak's internal interfaces are very clearly super close to what's in here, so being able to separate the protocol parts separately definitely sounds like it'd help.

Given that we've never been able to upgrade to the newer kafka-python versions/clients because of this issue (and have stuck with the older versions) I suspect it's still relevant for us, but will have to spend a few minutes reviewing the patch here and reviewing our Kafka fake (which I'd also love to upstream :).

I suspect I would still like to get this merged if possible, so assuming that's the case, I'll have a look and see where this is.

@dpkp
Copy link
Owner

dpkp commented Dec 21, 2017

Apologies, our test suite was broken due to upstream dependency changes in pylint and lz4. I've pinned the versions in master. Do you mind doing a rebase or merge and push for a new test run?

@Julian
Copy link
Author

Julian commented Jan 30, 2018

@dpkp done

@jeffwidman
Copy link
Contributor

Afraid tests are failing...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants