Skip to content

Commit

Permalink
GH-823 - Move spring.modulith.republish-outstanding-events-on-restart…
Browse files Browse the repository at this point in the history
… into spring.modulith.events namespace.
  • Loading branch information
odrotbohm committed Sep 13, 2024
1 parent bec0a35 commit db4ab8f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.time.Duration;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.Supplier;
Expand Down Expand Up @@ -68,7 +69,8 @@ public class PersistentApplicationEventMulticaster extends AbstractApplicationEv
private static final Method SHOULD_HANDLE = ReflectionUtils.findMethod(ApplicationListenerMethodAdapter.class,
"shouldHandle", ApplicationEvent.class);

static final String REPUBLISH_ON_RESTART = "spring.modulith.republish-outstanding-events-on-restart";
static final String REPUBLISH_ON_RESTART = "spring.modulith.events.republish-outstanding-events-on-restart";
static final String REPUBLISH_ON_RESTART_LEGACY = "spring.modulith.republish-outstanding-events-on-restart";

private final @NonNull Supplier<EventPublicationRegistry> registry;
private final @NonNull Supplier<Environment> environment;
Expand Down Expand Up @@ -169,7 +171,12 @@ public void resubmitIncompletePublicationsOlderThan(Duration duration) {
@Override
public void afterSingletonsInstantiated() {

if (!Boolean.TRUE.equals(environment.get().getProperty(REPUBLISH_ON_RESTART, Boolean.class))) {
var env = environment.get();

Boolean republishOnRestart = Optional.ofNullable(env.getProperty(REPUBLISH_ON_RESTART, Boolean.class))
.orElseGet(() -> env.getProperty(REPUBLISH_ON_RESTART_LEGACY, Boolean.class));

if (!Boolean.TRUE.equals(republishOnRestart)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
"name": "spring.modulith.republish-outstanding-events-on-restart",
"type": "java.lang.Boolean",
"description": "Whether to republish outstanding event publications on restarts of the application.",
"defaultValue": "false"
"defaultValue": "false",
"deprecation": {
"replacement": "spring.modulith.events.republish-outstanding-events-on-restart",
"reason": "Moved to spring.modulit.events namespace. To be removed in 1.4.",
"since" : "1.3"
}
},
{
"name": "spring.modulith.events.externalization.enabled",
Expand All @@ -23,6 +28,12 @@
"type": "org.springframework.modulith.events.support.CompletionMode",
"description": "How to complete event publications.",
"defaultValue": "update"
},
{
"name": "spring.modulith.events.republish-outstanding-events-on-restart",
"type": "java.lang.Boolean",
"description": "Whether to republish outstanding event publications on restarts of the application.",
"defaultValue": "false"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ void triggersRepublicationIfExplicitlyEnabled() {
verify(registry).processIncompletePublications(any(), any(), any());
}

@Test // GH-240, GH-251, GH-823
void triggersRepublicationIfLegacyConfigExplicitlyEnabled() {

var source = new MapPropertySource("test",
Map.of(PersistentApplicationEventMulticaster.REPUBLISH_ON_RESTART_LEGACY, "true"));
environment.getPropertySources().addFirst(source);

multicaster.afterSingletonsInstantiated();

verify(registry).processIncompletePublications(any(), any(), any());
}

@Test // GH-277
void honorsListenerCondition() throws Exception {

Expand Down

0 comments on commit db4ab8f

Please sign in to comment.