Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -103,6 +103,7 @@
* @author Mark Paluch
* @author John Blum
* @author Seongjun Lee
* @author Su Ko
* @see MessageListener
* @see SubscriptionListener
*/
Expand Down Expand Up @@ -168,6 +169,8 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab

private @Nullable Subscriber subscriber;

private int phase = Integer.MAX_VALUE;

/**
* Set an ErrorHandler to be invoked in case of any uncaught exceptions thrown while processing a Message. By default,
* there will be <b>no</b> ErrorHandler so that error-level logging is the only result.
Expand Down Expand Up @@ -618,6 +621,22 @@ 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()
*/
public void setPhase(int phase) {
this.phase = phase;
}

private void initMapping(Map<? extends MessageListener, Collection<? extends Topic>> listeners) {

// stop the listener if currently running
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,15 @@ void shouldRemoveAllListenersWhenListenerIsNull() {

assertThatNoException().isThrownBy(() -> container.removeMessageListener(null, Collections.singletonList(topic)));
}

@Test // GH-3208
void defaultPhaseShouldBeMaxValue() {
assertThat(container.getPhase()).isEqualTo(Integer.MAX_VALUE);
}

@Test // GH-3208
void shouldApplyConfiguredPhase() {
container.setPhase(3208);
assertThat(container.getPhase()).isEqualTo(3208);
}
}