Skip to content

Commit db4ab8f

Browse files
committed
GH-823 - Move spring.modulith.republish-outstanding-events-on-restart into spring.modulith.events namespace.
1 parent bec0a35 commit db4ab8f

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

spring-modulith-events/spring-modulith-events-core/src/main/java/org/springframework/modulith/events/support/PersistentApplicationEventMulticaster.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.time.Duration;
2020
import java.util.Collection;
2121
import java.util.List;
22+
import java.util.Optional;
2223
import java.util.function.Consumer;
2324
import java.util.function.Predicate;
2425
import java.util.function.Supplier;
@@ -68,7 +69,8 @@ public class PersistentApplicationEventMulticaster extends AbstractApplicationEv
6869
private static final Method SHOULD_HANDLE = ReflectionUtils.findMethod(ApplicationListenerMethodAdapter.class,
6970
"shouldHandle", ApplicationEvent.class);
7071

71-
static final String REPUBLISH_ON_RESTART = "spring.modulith.republish-outstanding-events-on-restart";
72+
static final String REPUBLISH_ON_RESTART = "spring.modulith.events.republish-outstanding-events-on-restart";
73+
static final String REPUBLISH_ON_RESTART_LEGACY = "spring.modulith.republish-outstanding-events-on-restart";
7274

7375
private final @NonNull Supplier<EventPublicationRegistry> registry;
7476
private final @NonNull Supplier<Environment> environment;
@@ -169,7 +171,12 @@ public void resubmitIncompletePublicationsOlderThan(Duration duration) {
169171
@Override
170172
public void afterSingletonsInstantiated() {
171173

172-
if (!Boolean.TRUE.equals(environment.get().getProperty(REPUBLISH_ON_RESTART, Boolean.class))) {
174+
var env = environment.get();
175+
176+
Boolean republishOnRestart = Optional.ofNullable(env.getProperty(REPUBLISH_ON_RESTART, Boolean.class))
177+
.orElseGet(() -> env.getProperty(REPUBLISH_ON_RESTART_LEGACY, Boolean.class));
178+
179+
if (!Boolean.TRUE.equals(republishOnRestart)) {
173180
return;
174181
}
175182

spring-modulith-events/spring-modulith-events-core/src/main/resources/META-INF/spring-configuration-metadata.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
"name": "spring.modulith.republish-outstanding-events-on-restart",
1111
"type": "java.lang.Boolean",
1212
"description": "Whether to republish outstanding event publications on restarts of the application.",
13-
"defaultValue": "false"
13+
"defaultValue": "false",
14+
"deprecation": {
15+
"replacement": "spring.modulith.events.republish-outstanding-events-on-restart",
16+
"reason": "Moved to spring.modulit.events namespace. To be removed in 1.4.",
17+
"since" : "1.3"
18+
}
1419
},
1520
{
1621
"name": "spring.modulith.events.externalization.enabled",
@@ -23,6 +28,12 @@
2328
"type": "org.springframework.modulith.events.support.CompletionMode",
2429
"description": "How to complete event publications.",
2530
"defaultValue": "update"
31+
},
32+
{
33+
"name": "spring.modulith.events.republish-outstanding-events-on-restart",
34+
"type": "java.lang.Boolean",
35+
"description": "Whether to republish outstanding event publications on restarts of the application.",
36+
"defaultValue": "false"
2637
}
2738
]
2839
}

spring-modulith-events/spring-modulith-events-core/src/test/java/org/springframework/modulith/events/support/PersistentApplicationEventMulticasterUnitTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ void triggersRepublicationIfExplicitlyEnabled() {
7676
verify(registry).processIncompletePublications(any(), any(), any());
7777
}
7878

79+
@Test // GH-240, GH-251, GH-823
80+
void triggersRepublicationIfLegacyConfigExplicitlyEnabled() {
81+
82+
var source = new MapPropertySource("test",
83+
Map.of(PersistentApplicationEventMulticaster.REPUBLISH_ON_RESTART_LEGACY, "true"));
84+
environment.getPropertySources().addFirst(source);
85+
86+
multicaster.afterSingletonsInstantiated();
87+
88+
verify(registry).processIncompletePublications(any(), any(), any());
89+
}
90+
7991
@Test // GH-277
8092
void honorsListenerCondition() throws Exception {
8193

0 commit comments

Comments
 (0)