Class TransactionalEventPublisher

java.lang.Object
org.springframework.transaction.reactive.TransactionalEventPublisher

public class TransactionalEventPublisher extends Object
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 Details

    • TransactionalEventPublisher

      public TransactionalEventPublisher(ApplicationEventPublisher eventPublisher)
      Create a new delegate for publishing transactional events in a reactive setup.
      Parameters:
      eventPublisher - the actual event publisher to use, typically a Spring ApplicationContext
  • 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 (the TransactionContext) to the event instance.
      Parameters:
      eventCreationFunction - a function mapping the source object to the event instance, e.g. source -> new PayloadApplicationEvent&lt;&gt;(source, "myPayload")
      Returns:
      the Reactor Mono for the transactional event publication
    • publishEvent

      public reactor.core.publisher.Mono<Void> publishEvent(Object payload)
      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