GH-863 - Add convenience method for creating a default EventExternalizationConfiguration.
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user