Class ChannelRouter

java.lang.Object
software.spool.publisher.api.utils.ChannelRouter

public class ChannelRouter extends Object
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 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 be null
      channel - the target channel name; must not be null
      Returns:
      this router for chaining
    • resolve

      public String resolve(software.spool.core.model.Event event)
      Resolves the channel for the given event.
      Parameters:
      event - the event to resolve; must not be null
      Returns:
      the registered channel name, or "spool" if no mapping exists