From 5e040ac4a28ca8fcab3b4ccabe6b0b1c100155bf Mon Sep 17 00:00:00 2001 From: Hyun Lee Date: Sat, 26 Sep 2026 22:09:22 -0500 Subject: [PATCH] Honor startImmediately when registering a listener container 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 --- .../GenericListenerEndpointRegistry.java | 4 + .../GenericListenerEndpointRegistryTests.java | 78 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 spring-pulsar/src/test/java/org/springframework/pulsar/config/GenericListenerEndpointRegistryTests.java diff --git a/spring-pulsar/src/main/java/org/springframework/pulsar/config/GenericListenerEndpointRegistry.java b/spring-pulsar/src/main/java/org/springframework/pulsar/config/GenericListenerEndpointRegistry.java index 7a027b4a1..8704dc471 100644 --- a/spring-pulsar/src/main/java/org/springframework/pulsar/config/GenericListenerEndpointRegistry.java +++ b/spring-pulsar/src/main/java/org/springframework/pulsar/config/GenericListenerEndpointRegistry.java @@ -60,6 +60,7 @@ * @author Soby Chacko * @author Christophe Bornet * @author Chris Bono + * @author Hyun Lee */ public class GenericListenerEndpointRegistry> implements PulsarListenerContainerRegistry, DisposableBean, SmartLifecycle, ApplicationContextAware, @@ -135,6 +136,9 @@ public void registerListenerContainer(E endpoint, ListenerContainerFactory registerContainer(boolean autoStartup, + boolean startImmediately) { + var endpoint = mock(PulsarListenerEndpoint.class); + when(endpoint.getId()).thenReturn("foo"); + ConcurrentPulsarMessageListenerContainer container = mock(); + when(container.isAutoStartup()).thenReturn(autoStartup); + var factory = mock(PulsarListenerContainerFactory.class); + when(factory.createRegisteredContainer(endpoint)).thenReturn(container); + this.registry.registerListenerContainer(endpoint, factory, startImmediately); + return container; + } + +}