Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify event delivery behavior #929

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading