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
MINOR: Add StreamsConfig to TopologyTestDriver constructor to enable ease of testing #5344
MINOR: Add StreamsConfig to TopologyTestDriver constructor to enable ease of testing #5344
Conversation
…ig instead of Properties
@mjsax could you please take a look into it? :) |
Thanks for the PR @wlsc. Note, this would be a public API change and requires a KIP. It's not a Also note that Can you elaborate why it's easier via Spring to inject configs in |
@mjsax I use Spring and overwrite The way, in which Kafka Streams creates implementors of the interface Therefore, in case there are dependencies to the implementor of the In this regard, I would suggest applying similar logic as for It would be great if there were an opportunity to have control over creation of |
@wlsc Thanks for your reply. I am not sure if I understand completely. Why do you need to overwrite |
Hi @wlsc , It seems surprising that it's not possible to inject the desired Properties object. Can you provide a small example program demonstrating the problem(s)? Thanks, |
@vvcephei The problem is not in the demo.zip -- please take a look at both usages in two separated packages. |
Hey @wlsc , sorry; I had a distracting week. I'll look at it tomorrow. Thanks for the example! |
Ok, I've looked through your example, and I think I understand now. I think that we interpreted the comments as saying that you are not able to construct the Streams app using Spring. But it seems like what you were actually saying was that you prefer to let Spring construct the exception handler (for example) rather than having Streams do it. Just to be super clear, the situation is currently that you register the exception handler class, and Streams uses reflection to invoke the 0-arg constructor and passes the config to the new instance's "configure" method. Thus, if your exception handler needs some other dependency, you have to construct it ahead of time and insert it into the config Properties, and then get it back out inside the Your preference would be to override part of the StreamsConfig class to replace the reflection-based instantiation with Spring's mechanism. This yields two advantages:
This seems reasonable to me. Essentially, making the construction of configured classes pluggable would let anyone plug in Spring or Guice or whatever and get more featureful dependency injection than the default, reflection/configure, mechanism. Sorry it took so long to digest what you were getting at. That said, this change does need a KIP, since it alters the public interface. This is actually a good thing, since it gives you the opportunity to propose not only adding this constructor to I can also imaging the community wanting to discuss if there's a more ergonomic approach than overriding |
The KIP process is documented here: https://cwiki.apache.org/confluence/display/KAFKA/Kafka+Improvement+Proposals. Let us know if you need any help on it! |
@wlsc What is the status of this? Are you planning to do a KIP? |
@mjsax I have a great interest in writing KIP. I am not sure what would be a timeline, since It would be my first time writing a proposal like this. If there any deadlines I should be aware of, please let me know. |
Hey @wlsc , The KIP deadline is 24 Sept., so your kip would need to be voted and accepted by then. The vote itself takes at least 72 hours, per the KIP rules (https://cwiki.apache.org/confluence/display/KAFKA/Kafka+Improvement+Proposals). This might be a little tight to write your first kip, guide the discussion, and get the vote passed. But I wouldn't stress about it. If you don't get it in for 2.1, there's always 2.2+. I'd recommend to peruse a few recent Streams KIPs (https://cwiki.apache.org/confluence/display/KAFKA/Kafka+Streams) to get a feel for the pattern and just copy one as a template. Let us know if you have any questions! (Just something to think about as you design the KIP): public interface ConfiguredInstanceFactory {
public <T> T getConfiguredInstance(String key, Class<T> type);
} and then add a new StreamsConfig constructor for it: new StreamsConfig(Properties config, ConfiguredInstanceFactory configuredInstanceFactory) The main advantages here:
|
@vvcephei @mjsax hi. I've created a KIP for this and started discussion in the mailing list. |
…s-config-to-topology-test-driver # Conflicts: # streams/test-utils/src/main/java/org/apache/kafka/streams/TopologyTestDriver.java
@wlsc let's continue on the discussion thread of the KIP, and hopefully we can move forward to the voting thread soon. Personally I'm in favor of the current approach in this PR but we can keep our discussion on the mailing list. |
Closing this stale PR due to inactivity. IIRC, we never received a KIP for this change, what would be required for a public API change. |
This PR offers a simple addition to enable a possibility to pass a StreamsConfig instance for the TopologyTestDriver.
Why this was offered? In our project we have found very useful to create a StreamsConfig instance with all injected dependencies (by Spring) and then still be able to create TopologyTestDriver, which is now possible with this PR.
P.S. Sorry for so many commits -- I should have merged it first and then create a branch.