diff --git a/src/main/java/org/springframework/data/redis/listener/RedisMessageListenerContainer.java b/src/main/java/org/springframework/data/redis/listener/RedisMessageListenerContainer.java
index 3487a61f1d..5773cf4389 100644
--- a/src/main/java/org/springframework/data/redis/listener/RedisMessageListenerContainer.java
+++ b/src/main/java/org/springframework/data/redis/listener/RedisMessageListenerContainer.java
@@ -103,6 +103,7 @@
* @author Mark Paluch
* @author John Blum
* @author Seongjun Lee
+ * @author Su Ko
* @see MessageListener
* @see SubscriptionListener
*/
@@ -168,6 +169,9 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab
private @Nullable Subscriber subscriber;
+ private int phase = Integer.MAX_VALUE;
+ private boolean autoStartup = true;
+
/**
* Set an ErrorHandler to be invoked in case of any uncaught exceptions thrown while processing a Message. By default,
* there will be no ErrorHandler so that error-level logging is the only result.
@@ -618,6 +622,40 @@ public void removeMessageListener(MessageListener listener) {
removeMessageListener(listener, Collections.emptySet());
}
+ @Override
+ public int getPhase() {
+ return this.phase;
+ }
+
+ /**
+ * Specify the lifecycle phase for this container.
+ * Lower values start earlier and stop later.
+ * The default is {@code Integer.MAX_VALUE}.
+ *
+ * @see SmartLifecycle#getPhase()
+ * @since 4.0
+ */
+ public void setPhase(int phase) {
+ this.phase = phase;
+ }
+
+ @Override
+ public boolean isAutoStartup() {
+ return this.autoStartup;
+ }
+
+ /**
+ * Configure if this Lifecycle connection factory should get started automatically by the container at the time that
+ * the containing ApplicationContext gets refreshed.
+ * The default is {@code true}.
+ *
+ * @see SmartLifecycle#isAutoStartup()
+ * @since 4.0
+ */
+ public void setAutoStartup(boolean autoStartup) {
+ this.autoStartup = autoStartup;
+ }
+
private void initMapping(Map extends MessageListener, Collection extends Topic>> listeners) {
// stop the listener if currently running
diff --git a/src/main/java/org/springframework/data/redis/stream/DefaultStreamMessageListenerContainer.java b/src/main/java/org/springframework/data/redis/stream/DefaultStreamMessageListenerContainer.java
index 12635762b9..9be3ae51f7 100644
--- a/src/main/java/org/springframework/data/redis/stream/DefaultStreamMessageListenerContainer.java
+++ b/src/main/java/org/springframework/data/redis/stream/DefaultStreamMessageListenerContainer.java
@@ -50,6 +50,7 @@
*
* @author Mark Paluch
* @author Christoph Strobl
+ * @author Su Ko
* @since 2.2
*/
class DefaultStreamMessageListenerContainer> implements StreamMessageListenerContainer {
@@ -67,6 +68,9 @@ class DefaultStreamMessageListenerContainer> implement
private boolean running = false;
+ private int phase = Integer.MAX_VALUE;
+ private boolean autoStartup = false;
+
/**
* Create a new {@link DefaultStreamMessageListenerContainer}.
*
@@ -90,6 +94,14 @@ class DefaultStreamMessageListenerContainer> implement
} else {
this.streamOperations = this.template.opsForStream();
}
+
+ if(containerOptions.isAutoStartup().isPresent()){
+ this.autoStartup = containerOptions.isAutoStartup().get();
+ }
+
+ if(containerOptions.getPhase().isPresent()){
+ this.phase = containerOptions.getPhase().getAsInt();
+ }
}
private static StreamReadOptions getStreamReadOptions(StreamMessageListenerContainerOptions, ?> options) {
@@ -123,9 +135,21 @@ private RedisTemplate createRedisTemplate(RedisConnectionFactory connectio
@Override
public boolean isAutoStartup() {
- return false;
+ return this.autoStartup;
}
+ /**
+ * Configure if this Lifecycle connection factory should get started automatically by the container at the time that
+ * the containing ApplicationContext gets refreshed.
+ * The default is {@code false}.
+ *
+ * @see org.springframework.context.SmartLifecycle#isAutoStartup()
+ * @since 4.0
+ */
+ public void setAutoStartup(boolean autoStartup) {
+ this.autoStartup = autoStartup;
+ }
+
@Override
public void stop(Runnable callback) {
@@ -177,9 +201,21 @@ public boolean isRunning() {
@Override
public int getPhase() {
- return Integer.MAX_VALUE;
+ return this.phase;
}
+ /**
+ * Specify the lifecycle phase for this container.
+ * Lower values start earlier and stop later.
+ * The default is {@code Integer.MAX_VALUE}.
+ *
+ * @see org.springframework.context.SmartLifecycle#getPhase()
+ * @since 4.0
+ */
+ public void setPhase(int phase) {
+ this.phase = phase;
+ }
+
@Override
public Subscription register(StreamReadRequest streamRequest, StreamListener listener) {
diff --git a/src/main/java/org/springframework/data/redis/stream/StreamMessageListenerContainer.java b/src/main/java/org/springframework/data/redis/stream/StreamMessageListenerContainer.java
index 009d6c3f93..f30e81d07a 100644
--- a/src/main/java/org/springframework/data/redis/stream/StreamMessageListenerContainer.java
+++ b/src/main/java/org/springframework/data/redis/stream/StreamMessageListenerContainer.java
@@ -16,6 +16,7 @@
package org.springframework.data.redis.stream;
import java.time.Duration;
+import java.util.Optional;
import java.util.OptionalInt;
import java.util.concurrent.Executor;
import java.util.function.Predicate;
@@ -107,6 +108,7 @@
* @author Christoph Strobl
* @author Christian Rest
* @author DongCheol Kim
+ * @author Su Ko
* @param Stream key and Stream field type.
* @param Stream value type.
* @since 2.2
@@ -503,12 +505,14 @@ class StreamMessageListenerContainerOptions> {
private final @Nullable HashMapper