Skip to content

Enable auto-startup for DefaultMessageListenerContainer #4976

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
*
* @author Christoph Strobl
* @author Mark Paluch
* @author Junhyeok Lee
* @since 2.1
*/
public class DefaultMessageListenerContainer implements MessageListenerContainer {
Expand All @@ -62,6 +63,7 @@ public class DefaultMessageListenerContainer implements MessageListenerContainer
private final Lock subscriptionWrite = Lock.of(subscriptionMonitor.writeLock());

private boolean running = false;
private boolean autoStartup = true;

/**
* Create a new {@link DefaultMessageListenerContainer}.
Expand Down Expand Up @@ -105,7 +107,16 @@ public DefaultMessageListenerContainer(MongoTemplate template, Executor taskExec

@Override
public boolean isAutoStartup() {
return false;
return this.autoStartup;
}

/**
* Set whether to auto-start this container.
* <p>Default is {@code true}.
* @param autoStartup {@code true} to auto-start.
*/
public void setAutoStartup(boolean autoStartup) {
this.autoStartup = autoStartup;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* Unit tests for {@link DefaultMessageListenerContainer}.
*
* @author Christoph Strobl
* @author Junhyeok Lee
*/
@ExtendWith(MockitoExtension.class)
class DefaultMessageListenerContainerUnitTests {
Expand Down Expand Up @@ -80,6 +81,17 @@ void removeSubscriptionWhileRunning() throws Throwable {
runOnce(new RemoveSubscriptionWhileRunning(container));
}

@Test // GH-4403
void shouldHaveAutoStartupEnabledByDefault() {
assertThat(container.isAutoStartup()).isTrue();
}

@Test // GH-4403
void shouldAllowDisablingAutoStartup() {
container.setAutoStartup(false);
assertThat(container.isAutoStartup()).isFalse();
}

private static class RemoveSubscriptionWhileRunning extends MultithreadedTestCase {

DefaultMessageListenerContainer container;
Expand Down