Honor startImmediately when registering a listener container - #1556
Open
dlwhdgus0810 wants to merge 1 commit into
Open
dlwhdgus0810 wants to merge 1 commit into
dlwhdgus0810 wants to merge 1 commit into
Conversation
GenericListenerEndpointRegistry#registerListenerContainer(endpoint, factory, startImmediately) ignored the startImmediately flag, so a container registered at runtime was never started, even with startImmediately set to true. Callers had to look the container up and start it themselves. Start the new container right away when startImmediately is true and either the application context has been refreshed or the container is auto-startup, as KafkaListenerEndpointRegistry does in Spring for Apache Kafka. Signed-off-by: Hyun Lee <dlwhdugs4147@gmail.com>
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.
GenericListenerEndpointRegistry#registerListenerContainer(endpoint, factory, startImmediately)accepts astartImmediatelyflag but never uses it. A container registered at runtime withstartImmediately = trueis created and stored in the registry, but it is not started, so callers have to look it up withgetListenerContainer(id)and callstart()themselves.This starts the new container right away when
startImmediatelyistrue, using the registry's existingstartIfNecessary(...): the container is started if the application context has already been refreshed or if the container is auto-startup. This is the same behavior asKafkaListenerEndpointRegistry#registerListenerContainer(endpoint, factory, startImmediately)in Spring for Apache Kafka. The two-argument overload still passesfalse, so nothing changes for existing callers that don't ask for an immediate start.Tests (new
GenericListenerEndpointRegistryTests, unit tests with mocked containers):startImmediately = truestarts an auto-startup containerstartImmediately = truestarts a non-auto-startup container once the context has been refreshedstartImmediately = truedoes not start a non-auto-startup container before the context is refreshedstartImmediately = false) does not start the containerThe first two fail without the change.
How I tested it (JDK 25):
All 11 tests in
org.springframework.pulsar.configpass and checkstyle is clean. I didn't run the broker-backed listener tests, since this only touches the registry.I noticed this while working on #1552 (#1553). The two changes touch the same class but not the same lines, and the tests are in separate files.