E - the specific ApplicationEvent subclass to listen topublic interface TransactionalApplicationListener<E extends ApplicationEvent> extends ApplicationListener<E>, Ordered
ApplicationListener that is invoked according to a TransactionPhase.
This is a programmatic equivalent of the TransactionalEventListener annotation.
Adding Ordered to your listener implementation
allows you to prioritize that listener amongst other listeners running before or after
transaction completion.
NOTE: Transactional event listeners only work with thread-bound transactions
managed by a PlatformTransactionManager. A reactive transaction managed by a
ReactiveTransactionManager
uses the Reactor context instead of thread-local variables, so from the perspective of
an event listener, there is no compatible active transaction that it can participate in.
TransactionalEventListener,
TransactionalApplicationListenerAdapter,
forPayload(java.util.function.Consumer<T>)| Modifier and Type | Interface and Description |
|---|---|
static interface |
TransactionalApplicationListener.SynchronizationCallback
Callback to be invoked on synchronization-driven event processing,
wrapping the target listener invocation (
processEvent(E)). |
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE| Modifier and Type | Method and Description |
|---|---|
void |
addCallback(TransactionalApplicationListener.SynchronizationCallback callback)
Add a callback to be invoked on processing within transaction synchronization,
i.e.
|
static <T> TransactionalApplicationListener<PayloadApplicationEvent<T>> |
forPayload(Consumer<T> consumer)
Create a new
TransactionalApplicationListener for the given payload consumer,
to be applied in the default phase TransactionPhase.AFTER_COMMIT. |
static <T> TransactionalApplicationListener<PayloadApplicationEvent<T>> |
forPayload(TransactionPhase phase,
Consumer<T> consumer)
Create a new
TransactionalApplicationListener for the given payload consumer. |
default String |
getListenerId()
Return an identifier for the listener to be able to refer to it individually.
|
default int |
getOrder()
Return the execution order within transaction synchronizations.
|
default TransactionPhase |
getTransactionPhase()
Return the
TransactionPhase in which the listener will be invoked. |
void |
processEvent(E event)
Immediately process the given
ApplicationEvent. |
onApplicationEventdefault int getOrder()
Default is Ordered.LOWEST_PRECEDENCE.
getOrder in interface OrderedTransactionSynchronization.getOrder()default String getListenerId()
It might be necessary for specific completion callback implementations to provide a specific id, whereas for other scenarios an empty String (as the common default value) is acceptable as well.
default TransactionPhase getTransactionPhase()
TransactionPhase in which the listener will be invoked.
The default phase is TransactionPhase.AFTER_COMMIT.
void addCallback(TransactionalApplicationListener.SynchronizationCallback callback)
processEvent(E) is being triggered during actual transactions.callback - the synchronization callback to applyvoid processEvent(E event)
ApplicationEvent. In contrast to
ApplicationListener.onApplicationEvent(ApplicationEvent), a call to this method will
directly process the given event without deferring it to the associated
transaction phase.event - the event to process through the target listener implementationstatic <T> TransactionalApplicationListener<PayloadApplicationEvent<T>> forPayload(Consumer<T> consumer)
TransactionalApplicationListener for the given payload consumer,
to be applied in the default phase TransactionPhase.AFTER_COMMIT.forPayload in interface ApplicationListener<E extends ApplicationEvent>T - the type of the event payloadconsumer - the event payload consumerTransactionalApplicationListener instancePayloadApplicationEvent.getPayload(),
TransactionalApplicationListenerAdapterstatic <T> TransactionalApplicationListener<PayloadApplicationEvent<T>> forPayload(TransactionPhase phase, Consumer<T> consumer)
TransactionalApplicationListener for the given payload consumer.T - the type of the event payloadphase - the transaction phase in which to invoke the listenerconsumer - the event payload consumerTransactionalApplicationListener instancePayloadApplicationEvent.getPayload(),
TransactionalApplicationListenerAdapter