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.
This commit is contained in:
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.modulith.events.support;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
@@ -30,7 +29,6 @@ import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.PayloadApplicationEvent;
|
||||
import org.springframework.context.event.AbstractApplicationEventMulticaster;
|
||||
import org.springframework.context.event.ApplicationEventMulticaster;
|
||||
import org.springframework.context.event.ApplicationListenerMethodAdapter;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
||||
import org.springframework.core.env.Environment;
|
||||
@@ -118,7 +116,7 @@ public class PersistentApplicationEventMulticaster extends AbstractApplicationEv
|
||||
@Override
|
||||
public void afterSingletonsInstantiated() {
|
||||
|
||||
if (Boolean.FALSE.equals(environment.get().getProperty(REPUBLISH_ON_RESTART, Boolean.class))) {
|
||||
if (!Boolean.TRUE.equals(environment.get().getProperty(REPUBLISH_ON_RESTART, Boolean.class))) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
"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": "true"
|
||||
"defaultValue": "false"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -42,21 +42,21 @@ class PersistentApplicationEventMulticasterUnitTests {
|
||||
this.multicaster = new PersistentApplicationEventMulticaster(() -> registry, () -> environment);
|
||||
}
|
||||
|
||||
@Test // GH-240
|
||||
void doesNotRepublishEventsOnRestartIfExplicitlyDisabled() {
|
||||
|
||||
var source = new MapPropertySource("test",
|
||||
Map.of(PersistentApplicationEventMulticaster.REPUBLISH_ON_RESTART, "false"));
|
||||
environment.getPropertySources().addFirst(source);
|
||||
@Test // GH-240, GH-251
|
||||
void doesNotRepublishEventsOnRestartByDefault() {
|
||||
|
||||
multicaster.afterSingletonsInstantiated();
|
||||
|
||||
verify(registry, never()).findIncompletePublications();
|
||||
}
|
||||
|
||||
@Test // GH-240
|
||||
@Test // GH-240, GH-251
|
||||
void triggersRepublicationIfExplicitlyEnabled() {
|
||||
|
||||
var source = new MapPropertySource("test",
|
||||
Map.of(PersistentApplicationEventMulticaster.REPUBLISH_ON_RESTART, "true"));
|
||||
environment.getPropertySources().addFirst(source);
|
||||
|
||||
multicaster.afterSingletonsInstantiated();
|
||||
|
||||
verify(registry).findIncompletePublications();
|
||||
|
||||
@@ -20,12 +20,15 @@ import static org.assertj.core.api.Assertions.*;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
import org.springframework.modulith.events.EventPublication;
|
||||
import org.springframework.modulith.events.EventPublicationRegistry;
|
||||
import org.springframework.modulith.events.PublicationTargetIdentifier;
|
||||
@@ -45,6 +48,8 @@ class PersistentDomainEventIntegrationTest {
|
||||
void exposesEventPublicationForFailedListener() throws Exception {
|
||||
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
context.getEnvironment().getPropertySources().addFirst(
|
||||
new MapPropertySource("test", Map.of("spring.modulith.republish-outstanding-events-on-restart", "true")));
|
||||
context.register(ApplicationConfiguration.class, InfrastructureConfiguration.class);
|
||||
context.refresh();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user