Skip to content

Commit 0e59f19

Browse files
committed
[GH-3208] Feat: Allow configuring 'autoStartup' and 'phase' in DefaultStreamMessageListenerContainer
Signed-off-by: Su Ko <[email protected]>
1 parent 1f2df57 commit 0e59f19

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

src/main/java/org/springframework/data/redis/stream/DefaultStreamMessageListenerContainer.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
*
5151
* @author Mark Paluch
5252
* @author Christoph Strobl
53+
* @author Su Ko
5354
* @since 2.2
5455
*/
5556
class DefaultStreamMessageListenerContainer<K, V extends Record<K, ?>> implements StreamMessageListenerContainer<K, V> {
@@ -67,6 +68,9 @@ class DefaultStreamMessageListenerContainer<K, V extends Record<K, ?>> implement
6768

6869
private boolean running = false;
6970

71+
private int phase = Integer.MAX_VALUE;
72+
private boolean autoStartup = false;
73+
7074
/**
7175
* Create a new {@link DefaultStreamMessageListenerContainer}.
7276
*
@@ -123,9 +127,21 @@ private RedisTemplate<K, V> createRedisTemplate(RedisConnectionFactory connectio
123127

124128
@Override
125129
public boolean isAutoStartup() {
126-
return false;
130+
return this.autoStartup;
127131
}
128132

133+
/**
134+
* Configure if this Lifecycle connection factory should get started automatically by the container at the time that
135+
* the containing ApplicationContext gets refreshed.
136+
* The default is {@code false}.
137+
*
138+
* @see org.springframework.context.SmartLifecycle#isAutoStartup()
139+
* @since 4.0.0
140+
*/
141+
public void setAutoStartup(boolean autoStartup) {
142+
this.autoStartup = autoStartup;
143+
}
144+
129145
@Override
130146
public void stop(Runnable callback) {
131147

@@ -177,9 +193,21 @@ public boolean isRunning() {
177193

178194
@Override
179195
public int getPhase() {
180-
return Integer.MAX_VALUE;
196+
return this.phase;
181197
}
182198

199+
/**
200+
* Specify the lifecycle phase for this container.
201+
* Lower values start earlier and stop later.
202+
* The default is {@code Integer.MAX_VALUE}.
203+
*
204+
* @see org.springframework.context.SmartLifecycle#getPhase()
205+
* @since 4.0.0
206+
*/
207+
public void setPhase(int phase) {
208+
this.phase = phase;
209+
}
210+
183211
@Override
184212
public Subscription register(StreamReadRequest<K> streamRequest, StreamListener<K, V> listener) {
185213

0 commit comments

Comments
 (0)