1616package org .springframework .data .redis .stream ;
1717
1818import java .time .Duration ;
19+ import java .util .Optional ;
1920import java .util .OptionalInt ;
2021import java .util .concurrent .Executor ;
2122import java .util .function .Predicate ;
107108 * @author Christoph Strobl
108109 * @author Christian Rest
109110 * @author DongCheol Kim
111+ * @author Su Ko
110112 * @param <K> Stream key and Stream field type.
111113 * @param <V> Stream value type.
112114 * @since 2.2
@@ -503,12 +505,14 @@ class StreamMessageListenerContainerOptions<K, V extends Record<K, ?>> {
503505 private final @ Nullable HashMapper <Object , Object , Object > hashMapper ;
504506 private final ErrorHandler errorHandler ;
505507 private final Executor executor ;
508+ private final @ Nullable Integer phase ;
509+ private final @ Nullable Boolean autoStartup ;
506510
507511 @ SuppressWarnings ({ "unchecked" , "rawtypes" })
508512 private StreamMessageListenerContainerOptions (Duration pollTimeout , @ Nullable Integer batchSize ,
509513 RedisSerializer <K > keySerializer , RedisSerializer <Object > hashKeySerializer ,
510514 RedisSerializer <Object > hashValueSerializer , @ Nullable Class <?> targetType ,
511- @ Nullable HashMapper <V , ?, ?> hashMapper , ErrorHandler errorHandler , Executor executor ) {
515+ @ Nullable HashMapper <V , ?, ?> hashMapper , ErrorHandler errorHandler , Executor executor , @ Nullable Integer phase , @ Nullable Boolean autoStartup ) {
512516 this .pollTimeout = pollTimeout ;
513517 this .batchSize = batchSize ;
514518 this .keySerializer = keySerializer ;
@@ -518,6 +522,8 @@ private StreamMessageListenerContainerOptions(Duration pollTimeout, @Nullable In
518522 this .hashMapper = (HashMapper ) hashMapper ;
519523 this .errorHandler = errorHandler ;
520524 this .executor = executor ;
525+ this .phase = phase ;
526+ this .autoStartup = autoStartup ;
521527 }
522528
523529 /**
@@ -598,6 +604,21 @@ public Executor getExecutor() {
598604 return executor ;
599605 }
600606
607+ /**
608+ * @return the phase.
609+ * @since 4.0
610+ */
611+ public OptionalInt getPhase () {
612+ return phase != null ? OptionalInt .of (phase ) : OptionalInt .empty ();
613+ }
614+
615+ /**
616+ * @return the autoStartup.
617+ * @since 4.0
618+ */
619+ public Optional <Boolean > isAutoStartup () {
620+ return autoStartup != null ? Optional .of (autoStartup ) : Optional .empty ();
621+ }
601622 }
602623
603624 /**
@@ -618,6 +639,8 @@ class StreamMessageListenerContainerOptionsBuilder<K, V extends Record<K, ?>> {
618639 private @ Nullable Class <?> targetType ;
619640 private ErrorHandler errorHandler = LoggingErrorHandler .INSTANCE ;
620641 private Executor executor = new SimpleAsyncTaskExecutor ();
642+ private @ Nullable Integer phase ;
643+ private @ Nullable Boolean autoStartup ;
621644
622645 @ SuppressWarnings ("NullAway" )
623646 private StreamMessageListenerContainerOptionsBuilder () {}
@@ -679,6 +702,28 @@ public StreamMessageListenerContainerOptionsBuilder<K, V> errorHandler(ErrorHand
679702 return this ;
680703 }
681704
705+ /**
706+ * Configure a phase for the {@link SmartLifecycle}
707+ *
708+ * @return {@code this} {@link StreamMessageListenerContainerOptionsBuilder}.
709+ * @since 4.0
710+ */
711+ public StreamMessageListenerContainerOptionsBuilder <K , V > phase (int phase ) {
712+ this .phase = phase ;
713+ return this ;
714+ }
715+
716+ /**
717+ * Configure a autoStartup for the {@link SmartLifecycle}
718+ *
719+ * @return {@code this} {@link StreamMessageListenerContainerOptionsBuilder}.
720+ * @since 4.0
721+ */
722+ public StreamMessageListenerContainerOptionsBuilder <K , V > autoStartup (boolean autoStartup ) {
723+ this .autoStartup = autoStartup ;
724+ return this ;
725+ }
726+
682727 /**
683728 * Configure a key, hash key and hash value serializer.
684729 *
@@ -796,7 +841,7 @@ public StreamMessageListenerContainerOptions<K, V> build() {
796841 Assert .notNull (hashValueSerializer , "Hash Value Serializer must not be null" );
797842
798843 return new StreamMessageListenerContainerOptions <>(pollTimeout , batchSize , keySerializer , hashKeySerializer ,
799- hashValueSerializer , targetType , hashMapper , errorHandler , executor );
844+ hashValueSerializer , targetType , hashMapper , errorHandler , executor , phase , autoStartup );
800845 }
801846
802847 }
0 commit comments