Skip to content

Commit bb1f020

Browse files
committed
GH-212 - Invert default for event republication to false.
This is to accommodate cluster setups and avoid multiple instances from resubmitting outstanding event publications concurrently.
1 parent 4c145dc commit bb1f020

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.springframework.modulith.events.support;
1717

18-
import java.lang.reflect.Field;
1918
import java.util.Collection;
2019
import java.util.List;
2120
import java.util.function.Consumer;
@@ -30,7 +29,6 @@
3029
import org.springframework.context.PayloadApplicationEvent;
3130
import org.springframework.context.event.AbstractApplicationEventMulticaster;
3231
import org.springframework.context.event.ApplicationEventMulticaster;
33-
import org.springframework.context.event.ApplicationListenerMethodAdapter;
3432
import org.springframework.core.ResolvableType;
3533
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
3634
import org.springframework.core.env.Environment;
@@ -118,7 +116,7 @@ public void multicastEvent(ApplicationEvent event, ResolvableType eventType) {
118116
@Override
119117
public void afterSingletonsInstantiated() {
120118

121-
if (Boolean.FALSE.equals(environment.get().getProperty(REPUBLISH_ON_RESTART, Boolean.class))) {
119+
if (!Boolean.TRUE.equals(environment.get().getProperty(REPUBLISH_ON_RESTART, Boolean.class))) {
122120
return;
123121
}
124122

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
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": "true"
13+
"defaultValue": "false"
1414
}
1515
]
1616
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@ void setUp() {
4242
this.multicaster = new PersistentApplicationEventMulticaster(() -> registry, () -> environment);
4343
}
4444

45-
@Test // GH-240
46-
void doesNotRepublishEventsOnRestartIfExplicitlyDisabled() {
47-
48-
var source = new MapPropertySource("test",
49-
Map.of(PersistentApplicationEventMulticaster.REPUBLISH_ON_RESTART, "false"));
50-
environment.getPropertySources().addFirst(source);
45+
@Test // GH-240, GH-251
46+
void doesNotRepublishEventsOnRestartByDefault() {
5147

5248
multicaster.afterSingletonsInstantiated();
5349

5450
verify(registry, never()).findIncompletePublications();
5551
}
5652

57-
@Test // GH-240
53+
@Test // GH-240, GH-251
5854
void triggersRepublicationIfExplicitlyEnabled() {
5955

56+
var source = new MapPropertySource("test",
57+
Map.of(PersistentApplicationEventMulticaster.REPUBLISH_ON_RESTART, "true"));
58+
environment.getPropertySources().addFirst(source);
59+
6060
multicaster.afterSingletonsInstantiated();
6161

6262
verify(registry).findIncompletePublications();

spring-modulith-events/spring-modulith-events-tests/src/test/java/example/events/PersistentDomainEventIntegrationTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@
2020
import lombok.Getter;
2121
import lombok.RequiredArgsConstructor;
2222

23+
import java.util.Map;
24+
2325
import org.junit.jupiter.api.Test;
2426
import org.springframework.context.ApplicationEventPublisher;
2527
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
2628
import org.springframework.context.annotation.Bean;
2729
import org.springframework.context.annotation.Configuration;
2830
import org.springframework.context.event.EventListener;
31+
import org.springframework.core.env.MapPropertySource;
2932
import org.springframework.modulith.events.EventPublication;
3033
import org.springframework.modulith.events.EventPublicationRegistry;
3134
import org.springframework.modulith.events.PublicationTargetIdentifier;
@@ -45,6 +48,8 @@ class PersistentDomainEventIntegrationTest {
4548
void exposesEventPublicationForFailedListener() throws Exception {
4649

4750
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
51+
context.getEnvironment().getPropertySources().addFirst(
52+
new MapPropertySource("test", Map.of("spring.modulith.republish-outstanding-events-on-restart", "true")));
4853
context.register(ApplicationConfiguration.class, InfrastructureConfiguration.class);
4954
context.refresh();
5055

0 commit comments

Comments
 (0)