Skip to content

Honor startImmediately when registering a listener container - #1556

Open
dlwhdgus0810 wants to merge 1 commit into
spring-projects:mainfrom
dlwhdgus0810:register-start-immediately
Open

dlwhdgus0810 wants to merge 1 commit into
spring-projects:mainfrom
dlwhdgus0810:register-start-immediately

Conversation

@dlwhdgus0810

Copy link
Copy Markdown

GenericListenerEndpointRegistry#registerListenerContainer(endpoint, factory, startImmediately) accepts a startImmediately flag but never uses it. A container registered at runtime with startImmediately = true is created and stored in the registry, but it is not started, so callers have to look it up with getListenerContainer(id) and call start() themselves.

This starts the new container right away when startImmediately is true, using the registry's existing startIfNecessary(...): the container is started if the application context has already been refreshed or if the container is auto-startup. This is the same behavior as KafkaListenerEndpointRegistry#registerListenerContainer(endpoint, factory, startImmediately) in Spring for Apache Kafka. The two-argument overload still passes false, so nothing changes for existing callers that don't ask for an immediate start.

Tests (new GenericListenerEndpointRegistryTests, unit tests with mocked containers):

  • startImmediately = true starts an auto-startup container
  • startImmediately = true starts a non-auto-startup container once the context has been refreshed
  • startImmediately = true does not start a non-auto-startup container before the context is refreshed
  • the default overload (startImmediately = false) does not start the container

The first two fail without the change.

How I tested it (JDK 25):

./gradlew :spring-pulsar:test --tests 'org.springframework.pulsar.config.*' :spring-pulsar:checkstyleMain :spring-pulsar:checkstyleTest

All 11 tests in org.springframework.pulsar.config pass 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.

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>
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.

1 participant