Class ChannelRouter
java.lang.Object
software.spool.publisher.api.utils.ChannelRouter
Routes events to named channels based on their type.
A ChannelRouter maintains a mapping from event types to channel
names. When resolve(Event) is called, it returns the channel
registered for the event's class, or the default channel "spool"
if no mapping exists.
ChannelRouter router = new ChannelRouter()
.route(OrderReceived.class, "orders")
.route(PaymentProcessed.class, "payments");
String channel = router.resolve(event); // "orders", "payments", or "spool"
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
ChannelRouter
public ChannelRouter()
-
-
Method Details
-
route
public <T extends software.spool.core.model.Event> ChannelRouter route(Class<T> eventType, String channel) Registers a channel mapping for the given event type.- Type Parameters:
T- the event type- Parameters:
eventType- the event class to route; must not benullchannel- the target channel name; must not benull- Returns:
- this router for chaining
-
resolve
Resolves the channel for the given event.- Parameters:
event- the event to resolve; must not benull- Returns:
- the registered channel name, or
"spool"if no mapping exists
-