Class OutboxEventMulticaster

  • All Implemented Interfaces:
    org.springframework.context.event.ApplicationEventMulticaster

    
    public final class OutboxEventMulticaster
     implements ApplicationEventMulticaster
                        

    Custom application event multicaster that intercepts @OutboxEvent annotated events.

    This class extends Spring's SimpleApplicationEventMulticaster to provide automatic outbox persistence for domain events. When an event marked with @OutboxEvent is published, it is automatically saved to the outbox database.

    Key Features:

    • Automatic detection of @OutboxEvent annotations

    • SpEL-based aggregateId extraction from event properties

    • Expression caching for performance optimization

    • Configurable publishing behavior (publishAfterSave flag)

    SpEL Expression Caching: Parsed SpEL expressions are cached in a ConcurrentHashMap to avoid reparsing the same expressions for every event. This significantly improves performance for high-volume event processing.

    Since:

    0.3.0

    Author:

    Roland Beisel

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      Unit multicastEvent(ApplicationEvent event, ResolvableType eventType) Intercepts and processes application events.
      Unit multicastEvent(ApplicationEvent event) Convenience override that resolves the event type automatically.
      • Methods inherited from class org.springframework.context.event.ApplicationEventMulticaster

        addApplicationListener, addApplicationListenerBean, removeAllListeners, removeApplicationListener, removeApplicationListenerBean, removeApplicationListenerBeans, removeApplicationListeners
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • multicastEvent

         Unit multicastEvent(ApplicationEvent event, ResolvableType eventType)

        Intercepts and processes application events.

        Processing flow:

        • Extracts payload if event is marked with @OutboxEvent

        • Saves event to outbox database (synchronized with transaction)

        • Optionally publishes to listeners (controlled by publishAfterSave config)

        • Handles non-outbox events normally

        Parameters:
        event - The application event to process
        eventType - The resolved event type
      • multicastEvent

         Unit multicastEvent(ApplicationEvent event)

        Convenience override that resolves the event type automatically.

        Delegates to the full multicastEvent(ApplicationEvent, ResolvableType) method with the event type resolved from the event instance.

        Parameters:
        event - The application event to process