GH-294 - Introduce user API to deal with completed and incomplete event publications.
Introduce a new spring-modulith-events-api artifact to contain types that are supposed to be used by application code to deal with event publications. `EventPublication` was moved into that artifact and got everything non infrastructure related extracted from it's previous incarnation. That in turn has been renamed to `TargetEventPublication`. `CompletedEventPublications` exposes API to allow purging completed publications either by a given predicate or age (in `Duration`). The interface is implemented by `DefaultEventPublicationRegistry` and thus subject for dependency injection into user code. It primarily delegates to the corresponding methods on `EventPublicationRepository` adapting the given `Duration`s to the `Clock` instance already held internally. `IncompleteEventPublications` allows triggering the re-submission of incomplete publications by the same criteria as `CEP`. The interface is implemented by `PersistentApplicationEventMulticaster` and this subject for dependency injection into user code. `EventPublicationRepository` now also allows publications to be deleted by identifiers. The existing implementations have been adapted and batch the requests for every 100 identifiers to prevent a list too large to run into limitations of the underlying data store. Polished transactional metadata declaration in JPA- and MongoDB-based repository implementations. Tightened nullability expressions here and there.
This commit is contained in:
@@ -124,6 +124,30 @@ For a more flexible arrangement, `EventPublicationRegistry` exposes a method `
|
||||
.The transactional event listener arrangement after execution
|
||||
image::event-publication-registry-end.png[]
|
||||
|
||||
[[events.managing-publications]]
|
||||
== Managing Event Publications
|
||||
|
||||
Event publications may need to be managed in a variety of ways during the runtime of an application.
|
||||
Incomplete publications might have to be re-submitted to the corresponding listeners after a given amount of time.
|
||||
Completed publications on the other hand, will likely have to be purged from the database or moved into an archive store.
|
||||
As the needs for that kind of housekeeping strongly vary from application to application, Spring Modulith offers API to deal with both kinds of publications.
|
||||
That API is available through the `spring-modulith-events-api` artifact, that you can add to your application:
|
||||
|
||||
.Using Spring Modulith Events API artifact
|
||||
[source, xml, subs="+attributes"]
|
||||
----
|
||||
<dependency>
|
||||
<groupId>org.springframework.modulith</groupId>
|
||||
<artifactId>spring-modulith-events-api</artifactId>
|
||||
<version>{projectVersion}</version>
|
||||
</dependency>
|
||||
----
|
||||
|
||||
This artifact contains two primary abstractions, that are available to application code as Spring Beans:
|
||||
|
||||
* `CompletedEventPublications` -- This interface allows accessing all completed event publications, and provides API to immediately purge all of them from the database or the completed publications older that a given duration (for example, 1 minute).
|
||||
* `IncompleteEventPublications`-- This interface allows accessing all incomplete event publications to resubmit either the ones matching a given predicate or older than a given `Duration` relative to the original publishing date.
|
||||
|
||||
[[events.publication-repositories]]
|
||||
== Event Publication Repositories
|
||||
|
||||
|
||||
@@ -67,18 +67,24 @@ a|* `spring-modulith-actuator` (runtime)
|
||||
|`spring-modulith-starter-jdbc`
|
||||
|`compile`
|
||||
a|* `spring-modulith-starter-core`
|
||||
* `spring-modulith-events-api`
|
||||
* `spring-modulith-events-core` (runtime)
|
||||
* `spring-modulith-events-jdbc` (runtime)
|
||||
* `spring-modulith-events-jackson` (runtime)
|
||||
|
||||
|`spring-modulith-starter-jpa`
|
||||
|`compile`
|
||||
a|* `spring-modulith-starter-core`
|
||||
* `spring-modulith-events-api`
|
||||
* `spring-modulith-events-core` (runtime)
|
||||
* `spring-modulith-events-jpa` (runtime)
|
||||
* `spring-modulith-events-jackson` (runtime)
|
||||
|
||||
|`spring-modulith-starter-mongodb`
|
||||
|`compile`
|
||||
a|* `spring-modulith-starter-core`
|
||||
* `spring-modulith-events-api`
|
||||
* `spring-modulith-events-core` (runtime)
|
||||
* `spring-modulith-events-mongodb` (runtime)
|
||||
* `spring-modulith-events-jackson` (runtime)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user