Package org.springframework.transaction.reactive

# 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:
  - `publishEvent(Function)`
  - `publishEvent(Object)`
  - `ApplicationEventPublisher`

## Constructor Summary

Constructors
Constructor
Description
`TransactionalEventPublisher(org.springframework.context.ApplicationEventPublisher eventPublisher)`
Create a new delegate for publishing transactional events in a reactive setup.

## Method Summary

Modifier and Type
Method
Description
`reactor.core.publisher.Mono<Void>`
`publishEvent(Object payload)`
Publish an event created for the given payload.
`reactor.core.publisher.Mono<Void>`
`publishEvent(Function<TransactionContext,org.springframework.context.ApplicationEvent> eventCreationFunction)`
Publish an event created through the given function which maps the transaction source object (the `TransactionContext`) to the event instance.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### TransactionalEventPublisher

public TransactionalEventPublisher(org.springframework.context.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,org.springframework.context.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, for example, `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