-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Create topology before kafka streams start. #3172
Create topology before kafka streams start. #3172
Conversation
@chickenchickenlove There are checkstyle issues and test failures in the build. Please take a look. |
Aye, i will check it. thanks for your comment 🙇♂️ |
Hi, @sobychacko ! Please take a look when you have some free time! 🙇♂️ |
} | ||
catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} |
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.
It might be better to add this to the afterPropertiesSet()
method instead of here. Doing it here adds more responsibilities to the isAutoStartup()
method, which should technically only return the current autoStartup
status. Also, we need to call the configureTopology(topology)
method immediately after the topology creation so that some clients, such as the TopologyTestDriver
, may use a fully configured topology.
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.
Also, please add your name as an author
of this class.
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.
Looks like this comment is not addressed? https://github.com/spring-projects/spring-kafka/pull/3172/files#r1546662939
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.
@sobychacko, I'm so sorry, i missed this comments.
It might be better to add this to the afterPropertiesSet() method instead of here. Doing it here adds more responsibilities to the isAutoStartup() method, which should technically only return the current autoStartup status. Also, we need to call the configureTopology(topology) method immediately after the topology creation so that some clients, such as the TopologyTestDriver, may use a fully configured topology.
IMHO, afterPropertiesSet()
is not proper workaround.
streamBuilder#stream()
seems to be called after StreamsBuilderFactoryBean#afterPropertiesSet()
are executed.
When StreamsBuilderFactoryBean#afterPropertiesSet()
is called, no stream declarations are made in the StreamBuilder
yet. Therefore, executing StreamsBuilder.build()
at the time of the afterPropertiesSet() call does not create any topology.
And, Unfortunately, it seems that there is no appropriate hooking point. (spring-projects/spring-framework#32554)
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.
And i agree that isAutoStartup()
has much responsibilities in this case.
If we move configureTopology(topology)
to isAutoStartup()
, much responsibilities as well.
However, as i said above, we cannot execute streamsBuilder#build()
properly in scope of afterPropertiesSet()
.
Please refer to image above.
This is timeline of KafkaStreams
with spring-kafka
.
As you can see, In StreamsBuilderFactoryBean#afterPropertiesSet()
, streamsBuilder
is just about to be created and streamsBuilder
does not have any stream DSL.
Thus streamsBuilder#build()
is executed in StreamsBuilderFactoryBean#afterPropertiesSet()
, there is no DSL to build on streamsBuilder
.
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.
Just commented on your issue in Spring Framework.
Let's see if SmartInitializingSingleton.afterSingletonsInstantiated()
implementation help us somehow!
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.
@artembilan Hi!
Thanks your comment. SmartInitializingSingleton.afterSingletonsInstantiated()
works well.
I modified code to use SmartInitializingSingleton.afterSingletonsInstantiated()
and test code as well.
Please Take a look. 🙇♂️
CC. @sobychacko
@@ -92,20 +92,56 @@ public void testCleanupStreams() throws IOException { | |||
} |
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.
Can you add your name as an author
of this class?
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.
Aye, i added my name classes below.
StreamsBuilderFactoryBean
StreamsBuilderFactoryBeanTests
StreamsBuilderFactoryLateConfigTests
Please take a look 🙇♂️
@@ -1,5 +1,5 @@ | |||
/* | |||
* Copyright 2018-2020 the original author or authors. | |||
* Copyright 2018-2024 the original author or authors. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. |
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.
Missing author
tag.
} | ||
catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} |
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.
Looks like this comment is not addressed? https://github.com/spring-projects/spring-kafka/pull/3172/files#r1546662939
}; | ||
streamsBuilderFactoryBean.afterPropertiesSet(); | ||
StreamsBuilder builder = streamsBuilderFactoryBean.getObject(); | ||
builder.stream(Pattern.compile("foo")); |
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.
Try not to use names like foo
in the new code that we add.
@chickenchickenlove The new updates look good, but the PR build still has some checkstyle issues. See more details here: https://github.com/spring-projects/spring-kafka/actions/runs/8532654028/job/23411166278?pr=3172. |
@sobychacko |
@chickenchickenlove Thanks for the PR. It is now merged upstream. |
Nice work @chickenchickenlove !! |
Introduction
Hi, Spring kafka Team.
This is chickenchickenlove, huge fan of you guys.
I saw this issue (#3020). i want to resolve this problem by myself!
Background
Topology
ofkafka streams
are initialized beforeStreamsBuilderFactoryBean#start()
, it will be very helpful to Test code forspring kafka-streams
.TopologyTestDriver
is very efficient to test comparing toTestContainers
.To reviewer
StreamsBuilder
as aBean
in a different scope, however, it will introduce many changes toStreamsBuilderFactoryBean
,AbstractBuilderFactoryBean
as well. I have made modifications to minimize the changes.Changes
kafka-streams topology
move toStreamsBuilderFactoryBean#isAutoStartup()
.@PostConstruct
orStreamsBuilderFactoryBean#afterPropertiesSet()
Does not work well in this case. Why?StreamsBuilderFactoryBean#afterPropertiesSet()
are called.StreamBuilder
is initialized in that time by this code. (StreamsBuilderFactoryBean#afterPropertiesSet()
->StreamsBuilderFactoryBean#createInstance()
-> finally,StreamsBuilder
are intialized!)StreamsBuilder
in this time. you can refer to this topology code below.is executed after
StreamsBuilderFactoryBean#afterPropertiesSet()called. After this step,
StreamsBuildercan return valid
topology. Before this step,
StreamsBuilderwill return invalid
topology` always.### Why am i used toisAutoStart()
?- AFAIK, There is no hooking point for this. even,ContextRefreshedEvent
will be called afterSmartLifeCycle#isAutoStart()
- IMHO, this is best simple modification. In common use case, Spring will callSmartLifeCycle#isAutoStart()
only once. I did send request to spring team whether if they can implement new hooking point such like it. (link)Any Other workaround?
- IMHO,StreamsBuilder
should be registered as bean other scope (not inStreamsBuilderFactoryBean scope
). But it will involves a lot of changes to theStreamsBuilderFactoryBean
.- I was wrong. IMHO, there is no workaround, i guess 😢 .SmartInitializingSingleton.afterSingletonsInstantiated()
to resolve this issue.