Top Description Fields Constructors Methods
org.springframework.transaction.reactive

public Class TransactionalEventPublisher

extends Object
Class Inheritance
Imports
java.util.function.Function, reactor.core.publisher.Mono, org.springframework.context.ApplicationEvent, .ApplicationEventPublisher, .PayloadApplicationEvent

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 org.springframework.context.ApplicationContext:

TransactionContextManager.currentContext()
    .map(source -> new PayloadApplicationEvent<>(source, "myPayload"))
    .doOnSuccess(this.eventPublisher::publishEvent)
Author
Juergen Hoeller
Since
6.1
See Also
publishEvent(Function), publishEvent(Object), ApplicationEventPublisher

Field Summary

Modifier and TypeField and Description
private final ApplicationEventPublisher

Constructor Summary

AccessConstructor and Description
public
TransactionalEventPublisher(ApplicationEventPublisher
the actual event publisher to use, typically a Spring org.springframework.context.ApplicationContext
eventPublisher
)

Create a new delegate for publishing transactional events in a reactive setup.

Method Summary

Modifier and TypeMethod and Description
public Mono<Void>

Returns:

the Reactor Mono for the transactional event publication
publishEvent
(Function<TransactionContext, ApplicationEvent>
a function mapping the source object to the event instance, e.g. source -> new PayloadApplicationEvent<>(source, "myPayload")
eventCreationFunction
)

Publish an event created through the given function which maps the transaction source object (the TransactionContext) to the event instance.

public Mono<Void>

Returns:

the Reactor Mono for the transactional event publication
publishEvent
(Object
the payload to publish as an event
payload
)

Publish an event created for the given payload.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

eventPublisherback to summary
private final ApplicationEventPublisher eventPublisher

Constructor Detail

TransactionalEventPublisherback to summary
public TransactionalEventPublisher(ApplicationEventPublisher eventPublisher)

Create a new delegate for publishing transactional events in a reactive setup.

Parameters
eventPublisher:ApplicationEventPublisher

the actual event publisher to use, typically a Spring org.springframework.context.ApplicationContext

Method Detail

publishEventback to summary
public 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:Function<TransactionContext, ApplicationEvent>

a function mapping the source object to the event instance, e.g. source -> new PayloadApplicationEvent<>(source, "myPayload")

Returns:Mono<Void>

the Reactor Mono for the transactional event publication

publishEventback to summary
public Mono<Void> publishEvent(Object payload)

Publish an event created for the given payload.

Parameters
payload:Object

the payload to publish as an event

Returns:Mono<Void>

the Reactor Mono for the transactional event publication