Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
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,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 <b>no</b> ErrorHandler so that error-level logging is the only result.
Expand Down Expand Up @@ -618,6 +622,38 @@ 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;
}

@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()
*/
public void setAutoStartup(boolean autoStartup) {
this.autoStartup = autoStartup;
}

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,27 @@ 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);
}

@Test // GH-3208
void defaultAutoStartupShouldBeMaxValue() {
assertThat(container.isAutoStartup()).isEqualTo(true);
}

@Test // GH-3208
void shouldApplyConfiguredAutoStartup() {
container.setAutoStartup(false);
assertThat(container.isAutoStartup()).isEqualTo(false);
}

}