Class TransactionalEventPublisher
java.lang.Object
org.springframework.transaction.reactive.TransactionalEventPublisher
A delegate for publishing transactional events in a reactive setup.
Includes the current Reactor-managed
TransactionContext
as
a source object for every ApplicationEvent
to be published.
This delegate is just a convenience. The current TransactionContext
can be directly included as the event source as well, and then published
through an ApplicationEventPublisher
such as the Spring
ApplicationContext
:
TransactionContextManager.currentContext() .map(source -> new PayloadApplicationEvent<>(source, "myPayload")) .doOnSuccess(this.eventPublisher::publishEvent)
- Since:
- 6.1
- Author:
- Juergen Hoeller
- See Also:
-
Constructor Summary
ConstructorDescriptionTransactionalEventPublisher
(ApplicationEventPublisher eventPublisher) Create a new delegate for publishing transactional events in a reactive setup. -
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Mono<Void>
publishEvent
(Object payload) Publish an event created for the given payload.reactor.core.publisher.Mono<Void>
publishEvent
(Function<TransactionContext, ApplicationEvent> eventCreationFunction) Publish an event created through the given function which maps the transaction source object (theTransactionContext
) to the event instance.
-
Constructor Details
-
TransactionalEventPublisher
Create a new delegate for publishing transactional events in a reactive setup.- Parameters:
eventPublisher
- the actual event publisher to use, typically a SpringApplicationContext
-
-
Method Details
-
publishEvent
public reactor.core.publisher.Mono<Void> publishEvent(Function<TransactionContext, ApplicationEvent> eventCreationFunction) Publish an event created through the given function which maps the transaction source object (theTransactionContext
) to the event instance.- Parameters:
eventCreationFunction
- a function mapping the source object to the event instance, for example,source -> new PayloadApplicationEvent<>(source, "myPayload")
- Returns:
- the Reactor
Mono
for the transactional event publication
-
publishEvent
Publish an event created for the given payload.- Parameters:
payload
- the payload to publish as an event- Returns:
- the Reactor
Mono
for the transactional event publication
-