Class EventExternalizationConfiguration.Router
java.lang.Object
org.springframework.modulith.events.EventExternalizationConfiguration.Router
- Enclosing interface:
- EventExternalizationConfiguration
API to define the event routing.
- Since:
- 1.1
- Author:
- Oliver Drotbohm
-
Constructor Summary
ConstructorDescriptionCreates a newEventExternalizationConfiguration.Router
for the given selector filter.Router
(Predicate<Object> filter, Function<Object, Object> mapper, Function<Object, RoutingTarget> router) Creates a newEventExternalizationConfiguration.Router
for the given selectorPredicate
and mapper and routerFunction
s. -
Method Summary
Modifier and TypeMethodDescriptionbuild()
Creates a newEventExternalizationConfiguration
refelcting the current configuration.Registers a type-specific mapping function.Registers a new mappingFunction
replacing the old one entirely.route
(Class<T> type, Function<T, RoutingTarget> router) Registers a router function for the events of the given specific type.routeAll
(Function<Object, RoutingTarget> router) Routes all events based on the given function.routeAllByType
(Function<Class<?>, RoutingTarget> router) Routes all messages based on the event type only.Registers aBiFunction
to resolve the key for aRoutingTarget
based on the event instance.Configures the routing to rather use the mapping result rather than the original event instance.routeOptional
(Function<Object, Optional<RoutingTarget>> router) Routes by extracting anOptional
route from the event.routeOptionalByType
(Function<Class<?>, Optional<RoutingTarget>> router) Routes by extracting anOptional
route from the event type.
-
Constructor Details
-
Router
Router(Predicate<Object> filter, Function<Object, Object> mapper, Function<Object, RoutingTarget> router) Creates a newEventExternalizationConfiguration.Router
for the given selectorPredicate
and mapper and routerFunction
s.- Parameters:
filter
- must not be null.mapper
- must not be null.router
- must not be null.
-
Router
Creates a newEventExternalizationConfiguration.Router
for the given selector filter.- Parameters:
filter
- must not be null.
-
-
Method Details
-
mapping
Registers a new mappingFunction
replacing the old one entirely.- Parameters:
mapper
- must not be null.- Returns:
- will never be null.
- See Also:
-
mapping
public <T> EventExternalizationConfiguration.Router mapping(Class<T> type, Function<T, Object> mapper) Registers a type-specific mapping function. Events not matching that type will still fall back to the global mapping function defined.- Type Parameters:
T
- the type to handle.- Parameters:
type
- the type to handle, must not be null.mapper
- the mapping function, must not be null.- Returns:
- will never be null.
- See Also:
-
routeMapped
Configures the routing to rather use the mapping result rather than the original event instance.- Returns:
- will never be null.
-
routeAll
Routes all events based on the given function.- Parameters:
router
- must not be null.- Returns:
- will never be null.
-
route
public <T> EventExternalizationConfiguration.Router route(Class<T> type, Function<T, RoutingTarget> router) Registers a router function for the events of the given specific type.- Type Parameters:
T
- the type to handle- Parameters:
type
- must not be null.router
- must not be null.- Returns:
- will never be null.
-
routeKey
public <T> EventExternalizationConfiguration.Router routeKey(Class<T> type, Function<T, String> extractor) Registers aBiFunction
to resolve the key for aRoutingTarget
based on the event instance. The actual target will have been resolved through the currently configured, global router. To dynamically define full, type-specific resolution of aRoutingTarget
, seeroute(Class, Function)
.- Type Parameters:
T
- the type to handle.- Parameters:
type
- the type to configure the key extraction for, must not be null.extractor
- the key extractor, must not be null.- Returns:
- will never be null.
- See Also:
-
routeOptional
public EventExternalizationConfiguration routeOptional(Function<Object, Optional<RoutingTarget>> router) Routes by extracting anOptional
route from the event. IfOptional.empty()
is returned by the function, we will fall back to the configured default routing.- Parameters:
router
- must not be null.- Returns:
- will never be null.
-
routeOptionalByType
public EventExternalizationConfiguration routeOptionalByType(Function<Class<?>, Optional<RoutingTarget>> router) Routes by extracting anOptional
route from the event type. IfOptional.empty()
is returned by the function, we will fall back to the configured general routing.- Parameters:
router
- must not be null.- Returns:
- will never be null.
-
routeAllByType
public EventExternalizationConfiguration.Router routeAllByType(Function<Class<?>, RoutingTarget> router) Routes all messages based on the event type only.- Parameters:
router
- must not be null.- Returns:
- will never be null.
-
build
Creates a newEventExternalizationConfiguration
refelcting the current configuration.- Returns:
- will never be null.
-