3 Star 6 Fork 0

Gitee 极速下载/Spring-Modulith

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
.github
.mvn
etc
spring-modulith-actuator
spring-modulith-api
spring-modulith-apt
spring-modulith-benchmarks
spring-modulith-bom
spring-modulith-core
spring-modulith-distribution
spring-modulith-docs
spring-modulith-events
spring-modulith-events-amqp
spring-modulith-events-api
spring-modulith-events-core
spring-modulith-events-jackson
spring-modulith-events-jdbc
spring-modulith-events-jms
spring-modulith-events-jpa
spring-modulith-events-kafka
spring-modulith-events-messaging
spring-modulith-events-mongodb
spring-modulith-events-neo4j
spring-modulith-events-tests
pom.xml
readme.adoc
spring-modulith-examples
spring-modulith-integration-test
spring-modulith-junit
spring-modulith-moments
spring-modulith-observability
spring-modulith-runtime
spring-modulith-starters
spring-modulith-test
src/docs
.git-authors
.gitignore
CONTRIBUTING.adoc
LICENSE
application.yml
lombok.config
mvnw
mvnw.cmd
pom.xml
readme.adoc
settings.xml
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/spring-projects-experimental/spring-modulith
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

Spring (reliable) Domain Events

Build Status

The Problem

Spring allows applications to publish events via its ApplicationEventPublisher API. With a transaction in place, these events can either be consumed within the transaction (using @EventListener) or in a dedicated transaction completion phase (using @TransactionalEventListener, defaulting to after transaction commit). While an application failure for an in-transaction event listener is not a problem as the transaction has not been committed, a failure during the publication of events to transactional event listeners will mean that the event is lost and the notification of those listeners cannot be guaranteed.

The idea

As we already have a transactional datastore in place, we could also store publication information about all transactional event listeners with the transaction that publishes one or more events. We can then wrap the transactional event listeners to be able to remove those registrations on successful listener invocation and completion. This allows us to re-publish the events to transactional listeners that either haven’t been notified yet or didn’t successfully complete the message handling in case of an application failure (on either a restart or in a scheduled way).

Building blocks of the prototype

  • The EventPublicationRegistry — the core interface to register publications and mark them completed. It allows different implementations (JPA, JDBC).

  • The EventSerializer — a component to serialize the actual domain event so that it can be kept around in the publication. Again, to allow pluggable implementations (Jackson etc.)

  • PersistentApplicationEventMulticaster — a replacement for Spring’s default ApplicationEventMulticaster that stores publications via the EventPublicationRegistry.

  • CompletionRegisteringBeanPostProcessor — a BeanPostProcessor that wraps @TransactionalEventListener instances with an interceptor to mark publications as completed.

  • @EnablePersistentDomainEvents — registers the multicaster and includes configuration classes for EventPublicationConfigurationExtension (to register the registry) and EventSerializationConfigurationExtension (to register an EventSerializer) via spring.factories.

Implementation modules

  • core — multicaster implementation, general and configuration infrastructure and SPI interfaces.

  • jackson — a rudimentary Jackson-based EventSerializer implementation.

  • jpa — a JPA-based EventPublicationRegistry.

  • test — a sample integration test featuring two successful and one failing listener to show the registry exposes the publication of the failed listener after the failure.

马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/mirrors/Spring-Modulith.git
git@gitee.com:mirrors/Spring-Modulith.git
mirrors
Spring-Modulith
Spring-Modulith
main

搜索帮助