Class OutboxEventMulticaster
-
- All Implemented Interfaces:
-
org.springframework.context.event.ApplicationEventMulticaster
public final class OutboxEventMulticaster implements ApplicationEventMulticasterCustom 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
Roland Beisel
-
-
Constructor Summary
Constructors Constructor Description OutboxEventMulticaster(SimpleApplicationEventMulticaster delegateEventMulticaster, OutboxRecordRepository outboxRecordRepository, OutboxEventSerializer outboxEventSerializer, OutboxProperties outboxProperties, Clock clock)
-
Method Summary
Modifier and Type Method Description UnitmulticastEvent(ApplicationEvent event, ResolvableType eventType)Intercepts and processes application events. UnitmulticastEvent(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
-
-
Constructor Detail
-
OutboxEventMulticaster
OutboxEventMulticaster(SimpleApplicationEventMulticaster delegateEventMulticaster, OutboxRecordRepository outboxRecordRepository, OutboxEventSerializer outboxEventSerializer, OutboxProperties outboxProperties, Clock clock)
-
-
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 processeventType- 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
-
-
-
-