GH-863 - Add convenience method for creating a default EventExternalizationConfiguration.

This commit is contained in:
Oliver Drotbohm
2024-10-08 15:07:39 +02:00
parent e3077a7abd
commit 42a9c48e80
2 changed files with 21 additions and 2 deletions

View File

@@ -19,6 +19,7 @@ import static org.springframework.core.annotation.AnnotatedElementUtils.*;
import java.lang.annotation.Annotation;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.function.BiFunction;
import java.util.function.BiPredicate;
@@ -68,6 +69,25 @@ public interface EventExternalizationConfiguration {
.routeAll(router);
}
/**
* Creates a default {@link DefaultEventExternalizationConfiguration} with the following characteristics:
* <ul>
* <li>Only events that reside in any of the given packages and that are annotated with any supported
* {@code Externalized} annotation will be considered.</li>
* <li>Routing information is discovered from the {code Externalized} annotation and, if missing, will default to the
* application-local name of the event type. In other words, an event type {@code com.acme.myapp.mymodule.MyEvent}
* will result in a route {@code mymodule.MyEvent}.</li>
* </ul>
*
* @param packages must not be {@literal null} or empty.
* @return will never be {@literal null}.
* @see Externalized
* @since 1.3
*/
public static Router defaults(String... packages) {
return defaults(List.of(packages));
}
/**
* Creates a new {@link Selector} to define which events to externalize.
*

View File

@@ -22,7 +22,6 @@ import lombok.RequiredArgsConstructor;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;
import org.junit.jupiter.api.Test;
@@ -120,7 +119,7 @@ class EventExternalizationConfigurationUnitTests {
@Test // GH-248
void defaultSetup() {
var configuration = defaults(List.of("org.springframework.modulith")).build();
var configuration = defaults("org.springframework.modulith").build();
var target = configuration.determineTarget(new AnotherSampleEvent());