Skip to content

Commit 5ae169b

Browse files
committed
[GH-3208] Feat: Allow configuring 'autoStartup' in RedisMessageListenerContainer
Signed-off-by: Su Ko <[email protected]>
1 parent 982b789 commit 5ae169b

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/main/java/org/springframework/data/redis/listener/RedisMessageListenerContainer.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab
170170
private @Nullable Subscriber subscriber;
171171

172172
private int phase = Integer.MAX_VALUE;
173+
private boolean autoStartup = true;
173174

174175
/**
175176
* Set an ErrorHandler to be invoked in case of any uncaught exceptions thrown while processing a Message. By default,
@@ -637,6 +638,22 @@ public void setPhase(int phase) {
637638
this.phase = phase;
638639
}
639640

641+
@Override
642+
public boolean isAutoStartup() {
643+
return this.autoStartup;
644+
}
645+
646+
/**
647+
* Configure if this Lifecycle connection factory should get started automatically by the container at the time that
648+
* the containing ApplicationContext gets refreshed.
649+
* The default is {@code true}.
650+
*
651+
* @see SmartLifecycle#isAutoStartup()
652+
*/
653+
public void setAutoStartup(boolean autoStartup) {
654+
this.autoStartup = autoStartup;
655+
}
656+
640657
private void initMapping(Map<? extends MessageListener, Collection<? extends Topic>> listeners) {
641658

642659
// stop the listener if currently running

src/test/java/org/springframework/data/redis/listener/RedisMessageListenerContainerUnitTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,16 @@ void shouldApplyConfiguredPhase() {
250250
container.setPhase(3208);
251251
assertThat(container.getPhase()).isEqualTo(3208);
252252
}
253+
254+
@Test // GH-3208
255+
void defaultAutoStartupShouldBeMaxValue() {
256+
assertThat(container.isAutoStartup()).isEqualTo(true);
257+
}
258+
259+
@Test // GH-3208
260+
void shouldApplyConfiguredAutoStartup() {
261+
container.setAutoStartup(false);
262+
assertThat(container.isAutoStartup()).isEqualTo(false);
263+
}
264+
253265
}

0 commit comments

Comments
 (0)