Skip to content

Commit 4db2e87

Browse files
committed
Clarify event delivery behavior without active TX
1 parent d921c71 commit 4db2e87

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/docs/antora/modules/ROOT/pages/events.adoc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,41 @@ class InventoryManagement {
195195
----
196196
======
197197

198+
[CAUTION]
199+
====
200+
Spring Modulith writes events published without an ongoing transaction to the event publication log, but Spring Framework does not deliver them immediately. They will only be delivered when incomplete event publications are retried (see <<publication-registry>>). To receive the events immediately, annotate the event handler with `@TransactionalEventListener(fallbackExecution = true)`:
201+
202+
[tabs]
203+
======
204+
Java::
205+
+
206+
[source, java, role="primary"]
207+
----
208+
@Component
209+
class InventoryManagement {
210+
211+
@TransactionalEventListener(fallbackExecution = true)
212+
@ApplicationModuleListener
213+
void on(OrderCompleted event) { /* … */ }
214+
}
215+
----
216+
Kotlin::
217+
+
218+
[source, kotlin, role="secondary"]
219+
----
220+
@Component
221+
class InventoryManagement {
222+
223+
@TransactionalEventListener(fallbackExecution = true)
224+
@ApplicationModuleListener
225+
fun on(event: OrderCompleted) { /* … */ }
226+
}
227+
----
228+
======
229+
230+
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.
231+
====
232+
198233
[[publication-registry]]
199234
== The Event Publication Registry
200235

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

242+
IMPORTANT: While Spring Framework continues to deliver events to handlers annotated with `@EventListener` alone, the event publication registry ignores them and does not write them to the event publication log. The event publication registry only considers methods annotated with `@TransactionalEventListener` or one of its subclasses, like `@ApplicationModuleListener`.
243+
207244
Each transactional event listener is wrapped into an aspect that marks that log entry as completed if the execution of the listener succeeds.
208245
In case the listener fails, the log entry stays untouched so that retry mechanisms can be deployed depending on the application's needs.
209246
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.

0 commit comments

Comments
 (0)