Skip to content

Commit

Permalink
Clarify event delivery behavior without active TX
Browse files Browse the repository at this point in the history
  • Loading branch information
aahlenst committed Nov 10, 2024
1 parent d921c71 commit 1d24ed8
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/docs/antora/modules/ROOT/pages/events.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,41 @@ class InventoryManagement {
----
======

[CAUTION]
====
Spring Modulith writes events published without an ongoing transaction to the event publication log, but Spring Framework does not deliver them. They will only be delivered when incomplete event publications are retried (see <<publication-registry.managing-publications>>). To receive the events immediately, annotate the event listener with `@TransactionalEventListener(fallbackExecution = true)`:
[tabs]
======
Java::
+
[source, java, role="primary"]
----
@Component
class InventoryManagement {
@TransactionalEventListener(fallbackExecution = true)
@ApplicationModuleListener
void on(OrderCompleted event) { /* … */ }
}
----
Kotlin::
+
[source, kotlin, role="secondary"]
----
@Component
class InventoryManagement {
@TransactionalEventListener(fallbackExecution = true)
@ApplicationModuleListener
fun on(event: OrderCompleted) { /* … */ }
}
----
======
Please see Spring Framework's documentation on https://docs.spring.io/spring-framework/reference/data-access/transaction/event.html#page-title[Transaction-bound Events] for further information.
====

[[publication-registry]]
== The Event Publication Registry

Expand All @@ -204,6 +239,8 @@ On event publication, it finds out about the transactional event listeners that
.The transactional event listener arrangement before execution
image::event-publication-registry-start.png[]

IMPORTANT: While Spring Framework continues to deliver events to listener solely annotated with `@EventListener`, Modulith's event publication registry ignores them and does not write them to the event publication log. Modulith only considers methods directly or indirectly annotated with `@TransactionalEventListener`. That includes `@ApplicationModuleListener`, which is annotated with `@TransactionalEventListener`.

Each transactional event listener is wrapped into an aspect that marks that log entry as completed if the execution of the listener succeeds.
In case the listener fails, the log entry stays untouched so that retry mechanisms can be deployed depending on the application's needs.
Automatic re-publication of the events can be enabled via the xref:appendix.adoc#configuration-properties[`spring.modulith.events.republish-outstanding-events-on-restart`] property.
Expand Down

0 comments on commit 1d24ed8

Please # to comment.