mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-09-12 18:18:55 +00:00
* Add transactional-outbox module Introduce a new transactional-outbox Maven module demonstrating the Transactional Outbox pattern. Adds a Spring Boot sample app and README explaining the pattern. New code includes Order and OutboxEvent entities, OrderStatus/EventStatus enums, Spring Data repositories (OrderRepository, OutboxRepository), OrderService (atomic write of order + outbox), OutboxPublisher (scheduled poll & publish), MessageBroker interface and MessageConsumer implementation, and App entrypoint. Includes unit tests (AppTest, OrderServiceTest, OutboxPublisherTest). Root pom.xml updated to register the new module. Module uses Spring Data JPA, Spring Web, Lombok, H2 and standard test dependencies. * Add OutboxPublisher edge-case tests Add two unit tests for OutboxPublisher: one verifies processOutboxEvents returns an empty list when there are no pending events; the other simulates a MessageBroker exception to ensure the event status is set to FAILED and the repository.save is called. Added necessary Mockito and assertion imports to support the tests. * Use MockitoExtension for OutboxPublisher test Replace the legacy inline/mock-based test with a JUnit5 + MockitoExtension unit test. Adds OutboxPublisherUnitTest (uses @ExtendWith(MockitoExtension.class), @Mock and @InjectMocks) that verifies broker exceptions mark events as FAILED and that the repository.save(...) is called. Removes the duplicate inline-mocking test and unused Mockito imports from OutboxPublisherTest. * Replace Lombok @Slf4j with explicit Logger Remove Lombok's @Slf4j and add explicit org.slf4j.Logger/LoggerFactory fields in transactional-outbox classes. This makes logging explicit and removes reliance on Lombok's @Slf4j annotation. * Add scheduled wrapper for outbox publishing Introduce publishOutboxEvents() annotated with @Scheduled(fixedDelay = 5000) that delegates to the existing processOutboxEvents(). This separates the scheduling concern from the transactional processing method; processOutboxEvents() remains @Transactional and now only handles fetching and dispatching pending OutboxEvent items. * Use UTC timestamps and add OutboxPublisher ctor Use UTC for timestamps in OrderService and OutboxPublisher by switching LocalDateTime.now() to LocalDateTime.now(ZoneOffset.UTC). Replace Lombok @RequiredArgsConstructor on OutboxPublisher with an explicit constructor for dependency injection and remove the @Transactional annotation from processOutboxEvents. Update processedAt assignment to use UTC as well.
521 lines
19 KiB
XML
521 lines
19 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!--
|
|
|
|
This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
|
|
|
The MIT License
|
|
Copyright © 2014-2022 Ilkka Seppälä
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
in the Software without restriction, including without limitation the rights
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
all copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
THE SOFTWARE.
|
|
|
|
-->
|
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
<modelVersion>4.0.0</modelVersion>
|
|
<groupId>com.iluwatar</groupId>
|
|
<artifactId>java-design-patterns</artifactId>
|
|
<version>1.26.0-SNAPSHOT</version>
|
|
<packaging>pom</packaging>
|
|
<inceptionYear>2014-2022</inceptionYear>
|
|
<name>Java Design Patterns</name>
|
|
<description>Java Design Patterns</description>
|
|
<properties>
|
|
<!-- General properties -->
|
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
|
|
<!-- Spring Boot related dependencies. Keep these in sync! -->
|
|
<spring-boot.version>3.4.5</spring-boot.version>
|
|
<junit.version>5.11.4</junit.version>
|
|
<mockito.version>5.14.2</mockito.version>
|
|
<logback.version>1.5.34</logback.version>
|
|
<slf4j.version>2.0.18</slf4j.version>
|
|
|
|
<!-- Other dependencies -->
|
|
<jacoco.version>0.8.13</jacoco.version>
|
|
<commons-dbcp.version>1.4</commons-dbcp.version>
|
|
<htmlunit.version>4.17.0</htmlunit.version>
|
|
<gson.version>2.11.0</gson.version>
|
|
<guice.version>6.0.0</guice.version>
|
|
<system-lambda.version>1.1.0</system-lambda.version>
|
|
<lombok.version>1.18.38</lombok.version>
|
|
<mongo.version>5.4.0</mongo.version>
|
|
<bson.version>5.4.0</bson.version>
|
|
<h2.version>2.3.232</h2.version>
|
|
|
|
<!-- Plugins -->
|
|
<maven-surefire-plugin.version>3.5.2</maven-surefire-plugin.version>
|
|
<license-maven-plugin.version>5.0.0</license-maven-plugin.version>
|
|
<maven-compiler-plugin.version>3.14.0</maven-compiler-plugin.version>
|
|
|
|
<!-- SonarCloud -->
|
|
<sonar-maven-plugin.version>5.1.0.4751</sonar-maven-plugin.version>
|
|
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
|
|
<sonar.organization>iluwatar</sonar.organization>
|
|
<sonar.projectKey>iluwatar_java-design-patterns</sonar.projectKey>
|
|
<sonar.moduleKey>${project.artifactId}</sonar.moduleKey>
|
|
<sonar.projectName>Java Design Patterns</sonar.projectName>
|
|
</properties>
|
|
<modules>
|
|
<module>abstract-document</module>
|
|
<module>abstract-factory</module>
|
|
<module>active-object</module>
|
|
<module>acyclic-visitor</module>
|
|
<module>adapter</module>
|
|
<module>ambassador</module>
|
|
<module>anti-corruption-layer</module>
|
|
<module>arrange-act-assert</module>
|
|
<module>async-method-invocation</module>
|
|
<module>backends-for-frontends</module>
|
|
<module>balking</module>
|
|
<module>bloc</module>
|
|
<module>bridge</module>
|
|
<module>builder</module>
|
|
<module>business-delegate</module>
|
|
<module>bytecode</module>
|
|
<module>caching</module>
|
|
<module>callback</module>
|
|
<module>chain-of-responsibility</module>
|
|
<module>circuit-breaker</module>
|
|
<module>clean-architecture</module>
|
|
<module>client-session</module>
|
|
<module>collecting-parameter</module>
|
|
<module>collection-pipeline</module>
|
|
<module>combinator</module>
|
|
<module>command</module>
|
|
<module>command-query-responsibility-segregation</module>
|
|
<module>commander</module>
|
|
<module>component</module>
|
|
<module>composite</module>
|
|
<module>composite-entity</module>
|
|
<module>composite-view</module>
|
|
<module>context-object</module>
|
|
<module>converter</module>
|
|
<module>curiously-recurring-template-pattern</module>
|
|
<module>currying</module>
|
|
<module>dao-factory</module>
|
|
<module>data-access-object</module>
|
|
<module>data-bus</module>
|
|
<module>data-locality</module>
|
|
<module>data-mapper</module>
|
|
<module>data-transfer-object</module>
|
|
<module>decorator</module>
|
|
<module>delegation</module>
|
|
<module>dependency-injection</module>
|
|
<module>dirty-flag</module>
|
|
<module>domain-model</module>
|
|
<module>double-buffer</module>
|
|
<module>double-checked-locking</module>
|
|
<module>double-dispatch</module>
|
|
<module>dynamic-proxy</module>
|
|
<module>event-aggregator</module>
|
|
<module>event-based-asynchronous</module>
|
|
<module>event-driven-architecture</module>
|
|
<module>event-queue</module>
|
|
<module>event-sourcing</module>
|
|
<module>execute-around</module>
|
|
<module>extension-objects</module>
|
|
<module>facade</module>
|
|
<module>factory</module>
|
|
<module>factory-kit</module>
|
|
<module>factory-method</module>
|
|
<module>fanout-fanin</module>
|
|
<module>feature-toggle</module>
|
|
<module>filterer</module>
|
|
<module>fluent-interface</module>
|
|
<module>flux</module>
|
|
<module>flyweight</module>
|
|
<module>fork-join</module>
|
|
<module>front-controller</module>
|
|
<module>function-composition</module>
|
|
<module>game-loop</module>
|
|
<module>gateway</module>
|
|
<module>guarded-suspension</module>
|
|
<module>half-sync-half-async</module>
|
|
<module>health-check</module>
|
|
<module>hexagonal-architecture</module>
|
|
<module>identity-map</module>
|
|
<module>immutable</module>
|
|
<module>intercepting-filter</module>
|
|
<module>interpreter</module>
|
|
<module>iterator</module>
|
|
<module>layered-architecture</module>
|
|
<module>lazy-loading</module>
|
|
<module>leader-election</module>
|
|
<module>leader-followers</module>
|
|
<module>lockable-object</module>
|
|
<module>map-reduce</module>
|
|
<module>marker-interface</module>
|
|
<module>master-worker</module>
|
|
<module>mediator</module>
|
|
<module>memento</module>
|
|
<module>metadata-mapping</module>
|
|
<module>microservices-aggregrator</module>
|
|
<module>microservices-api-gateway</module>
|
|
<module>microservices-client-side-ui-composition</module>
|
|
<module>microservices-distributed-tracing</module>
|
|
<module>microservices-idempotent-consumer</module>
|
|
<module>microservices-log-aggregation</module>
|
|
<module>microservices-self-registration</module>
|
|
<module>microservices-messaging</module>
|
|
<module>model-view-controller</module>
|
|
<module>model-view-intent</module>
|
|
<module>model-view-presenter</module>
|
|
<module>model-view-viewmodel</module>
|
|
<module>monad</module>
|
|
<module>money</module>
|
|
<module>monitor</module>
|
|
<module>monolithic-architecture</module>
|
|
<module>monostate</module>
|
|
<module>multiton</module>
|
|
<module>mute-idiom</module>
|
|
<module>notification</module>
|
|
<module>null-object</module>
|
|
<module>object-mother</module>
|
|
<module>object-pool</module>
|
|
<module>observer</module>
|
|
<module>optimistic-offline-lock</module>
|
|
<module>page-controller</module>
|
|
<module>page-object</module>
|
|
<module>parameter-object</module>
|
|
<module>partial-response</module>
|
|
<module>pipeline</module>
|
|
<module>poison-pill</module>
|
|
<module>polling-publisher</module>
|
|
<module>presentation-model</module>
|
|
<module>private-class-data</module>
|
|
<module>producer-consumer</module>
|
|
<module>promise</module>
|
|
<module>property</module>
|
|
<module>prototype</module>
|
|
<module>proxy</module>
|
|
<module>publish-subscribe</module>
|
|
<module>queue-based-load-leveling</module>
|
|
<module>reactor</module>
|
|
<module>registry</module>
|
|
<module>repository</module>
|
|
<module>resource-acquisition-is-initialization</module>
|
|
<module>retry</module>
|
|
<module>role-object</module>
|
|
<module>rule-engine</module>
|
|
<module>saga</module>
|
|
<module>separated-interface</module>
|
|
<module>serialized-entity</module>
|
|
<module>serialized-lob</module>
|
|
<module>servant</module>
|
|
<module>server-session</module>
|
|
<module>service-layer</module>
|
|
<module>service-locator</module>
|
|
<module>service-stub</module>
|
|
<module>service-to-worker</module>
|
|
<module>session-facade</module>
|
|
<module>sharding</module>
|
|
<module>single-table-inheritance</module>
|
|
<module>singleton</module>
|
|
<module>spatial-partition</module>
|
|
<module>special-case</module>
|
|
<module>specification</module>
|
|
<module>state</module>
|
|
<module>step-builder</module>
|
|
<module>strangler</module>
|
|
<module>strategy</module>
|
|
<module>subclass-sandbox</module>
|
|
<module>table-inheritance</module>
|
|
<module>table-module</module>
|
|
<module>template-method</module>
|
|
<module>templateview</module>
|
|
<module>thread-pool-executor</module>
|
|
<module>thread-specific-storage</module>
|
|
<module>throttling</module>
|
|
<module>tolerant-reader</module>
|
|
<module>trampoline</module>
|
|
<module>transaction-script</module>
|
|
<module>transactional-outbox</module>
|
|
<module>twin</module>
|
|
<module>type-object</module>
|
|
<module>unit-of-work</module>
|
|
<module>update-method</module>
|
|
<module>value-object</module>
|
|
<module>version-number</module>
|
|
<module>view-helper</module>
|
|
<module>virtual-proxy</module>
|
|
<module>visitor</module>
|
|
<module>write-ahead-log</module>
|
|
<module>backpressure</module>
|
|
<module>actor-model</module>
|
|
<module>rate-limiting-pattern</module>
|
|
<module>fallback</module>
|
|
<module>onion-architecture</module>
|
|
</modules>
|
|
<repositories>
|
|
<repository>
|
|
<id>jitpack.io</id>
|
|
<url>https://jitpack.io</url>
|
|
</repository>
|
|
</repositories>
|
|
<dependencyManagement>
|
|
<dependencies>
|
|
<dependency>
|
|
<groupId>org.springframework.boot</groupId>
|
|
<artifactId>spring-boot-starter</artifactId>
|
|
<version>${spring-boot.version}</version>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>org.springframework.boot</groupId>
|
|
<artifactId>spring-boot-starter-web</artifactId>
|
|
<version>${spring-boot.version}</version>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>org.springframework.boot</groupId>
|
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
|
<version>${spring-boot.version}</version>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>org.springframework.boot</groupId>
|
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
|
<version>${spring-boot.version}</version>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>org.springframework.boot</groupId>
|
|
<artifactId>spring-boot-starter-test</artifactId>
|
|
<scope>test</scope>
|
|
<version>${spring-boot.version}</version>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>commons-dbcp</groupId>
|
|
<artifactId>commons-dbcp</artifactId>
|
|
<version>${commons-dbcp.version}</version>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>org.htmlunit</groupId>
|
|
<artifactId>htmlunit</artifactId>
|
|
<version>${htmlunit.version}</version>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>com.google.code.gson</groupId>
|
|
<artifactId>gson</artifactId>
|
|
<version>${gson.version}</version>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>com.google.inject</groupId>
|
|
<artifactId>guice</artifactId>
|
|
<version>${guice.version}</version>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>com.github.stefanbirkner</groupId>
|
|
<artifactId>system-lambda</artifactId>
|
|
<version>${system-lambda.version}</version>
|
|
<scope>test</scope>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>org.junit.jupiter</groupId>
|
|
<artifactId>junit-jupiter-engine</artifactId>
|
|
<version>${junit.version}</version>
|
|
<scope>test</scope>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>org.junit.jupiter</groupId>
|
|
<artifactId>junit-jupiter-params</artifactId>
|
|
<version>${junit.version}</version>
|
|
<scope>test</scope>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>org.junit.jupiter</groupId>
|
|
<artifactId>junit-jupiter-migrationsupport</artifactId>
|
|
<version>${junit.version}</version>
|
|
<scope>test</scope>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>org.slf4j</groupId>
|
|
<artifactId>slf4j-api</artifactId>
|
|
<version>${slf4j.version}</version>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>ch.qos.logback</groupId>
|
|
<artifactId>logback-classic</artifactId>
|
|
<version>${logback.version}</version>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>org.mockito</groupId>
|
|
<artifactId>mockito-core</artifactId>
|
|
<version>${mockito.version}</version>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>org.mockito</groupId>
|
|
<artifactId>mockito-junit-jupiter</artifactId>
|
|
<version>${mockito.version}</version>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>org.mongodb</groupId>
|
|
<artifactId>bson</artifactId>
|
|
<version>${bson.version}</version>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>org.mongodb</groupId>
|
|
<artifactId>mongodb-driver-legacy</artifactId>
|
|
<version>${mongo.version}</version>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>com.h2database</groupId>
|
|
<artifactId>h2</artifactId>
|
|
<version>${h2.version}</version>
|
|
</dependency>
|
|
</dependencies>
|
|
</dependencyManagement>
|
|
<dependencies>
|
|
<dependency>
|
|
<groupId>org.projectlombok</groupId>
|
|
<artifactId>lombok</artifactId>
|
|
<version>${lombok.version}</version>
|
|
<scope>provided</scope>
|
|
</dependency>
|
|
</dependencies>
|
|
<build>
|
|
<pluginManagement>
|
|
<plugins>
|
|
<plugin>
|
|
<groupId>org.apache.maven.plugins</groupId>
|
|
<artifactId>maven-compiler-plugin</artifactId>
|
|
<version>${maven-compiler-plugin.version}</version>
|
|
<configuration>
|
|
<source>21</source>
|
|
<target>21</target>
|
|
<annotationProcessorPaths>
|
|
<path>
|
|
<groupId>org.projectlombok</groupId>
|
|
<artifactId>lombok</artifactId>
|
|
<version>${lombok.version}</version>
|
|
</path>
|
|
</annotationProcessorPaths>
|
|
</configuration>
|
|
</plugin>
|
|
<plugin>
|
|
<groupId>org.apache.maven.plugins</groupId>
|
|
<artifactId>maven-surefire-plugin</artifactId>
|
|
<version>${maven-surefire-plugin.version}</version>
|
|
</plugin>
|
|
<plugin>
|
|
<groupId>org.springframework.boot</groupId>
|
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
|
</plugin>
|
|
<!-- Maven assembly plugin template for all child project to follow -->
|
|
<plugin>
|
|
<groupId>org.apache.maven.plugins</groupId>
|
|
<artifactId>maven-assembly-plugin</artifactId>
|
|
<executions>
|
|
<execution>
|
|
<phase>package</phase>
|
|
<goals>
|
|
<goal>single</goal>
|
|
</goals>
|
|
<configuration>
|
|
<descriptorRefs>
|
|
<descriptorRef>jar-with-dependencies</descriptorRef>
|
|
</descriptorRefs>
|
|
<!-- below two line make sure the fat jar is sharing the same name as of project name -->
|
|
<finalName>${project.artifactId}-${project.version}</finalName>
|
|
<appendAssemblyId>false</appendAssemblyId>
|
|
</configuration>
|
|
</execution>
|
|
</executions>
|
|
</plugin>
|
|
<plugin>
|
|
<groupId>org.sonarsource.scanner.maven</groupId>
|
|
<artifactId>sonar-maven-plugin</artifactId>
|
|
<version>${sonar-maven-plugin.version}</version>
|
|
</plugin>
|
|
</plugins>
|
|
</pluginManagement>
|
|
<plugins>
|
|
<plugin>
|
|
<groupId>com.mycila</groupId>
|
|
<artifactId>license-maven-plugin</artifactId>
|
|
<version>${license-maven-plugin.version}</version>
|
|
<configuration>
|
|
<licenseSets>
|
|
<licenseSet>
|
|
<multi>
|
|
<preamble><![CDATA[This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).]]></preamble>
|
|
<header>com/mycila/maven/plugin/license/templates/MIT.txt</header>
|
|
</multi>
|
|
<excludes>
|
|
<exclude>**/README</exclude>
|
|
<exclude>src/test/resources/**</exclude>
|
|
<exclude>src/main/resources/**</exclude>
|
|
<exclude>checkstyle-suppressions.xml</exclude>
|
|
<exclude>**/*.ps1</exclude>
|
|
</excludes>
|
|
</licenseSet>
|
|
</licenseSets>
|
|
<properties>
|
|
<owner>Ilkka Seppälä</owner>
|
|
<email>iluwatar@gmail.com</email>
|
|
</properties>
|
|
</configuration>
|
|
<executions>
|
|
<execution>
|
|
<id>install-format</id>
|
|
<phase>install</phase>
|
|
<goals>
|
|
<goal>format</goal>
|
|
</goals>
|
|
</execution>
|
|
</executions>
|
|
</plugin>
|
|
<plugin>
|
|
<groupId>org.jacoco</groupId>
|
|
<artifactId>jacoco-maven-plugin</artifactId>
|
|
<version>${jacoco.version}</version>
|
|
<executions>
|
|
<execution>
|
|
<id>prepare-agent</id>
|
|
<goals>
|
|
<goal>prepare-agent</goal>
|
|
</goals>
|
|
</execution>
|
|
<execution>
|
|
<id>report</id>
|
|
<goals>
|
|
<goal>report</goal>
|
|
</goals>
|
|
</execution>
|
|
</executions>
|
|
</plugin>
|
|
<plugin>
|
|
<groupId>com.diffplug.spotless</groupId>
|
|
<artifactId>spotless-maven-plugin</artifactId>
|
|
<version>3.8.0</version> <!-- Use latest version -->
|
|
<executions>
|
|
<execution>
|
|
<goals>
|
|
<goal>check</goal> <!-- Run to check formatting -->
|
|
<goal>apply</goal> <!-- Run to format automatically -->
|
|
</goals>
|
|
</execution>
|
|
</executions>
|
|
<configuration>
|
|
<java>
|
|
<googleJavaFormat>
|
|
<version>1.17.0</version> <!-- Optional: choose the GJF version -->
|
|
</googleJavaFormat>
|
|
</java>
|
|
</configuration>
|
|
</plugin>
|
|
</plugins>
|
|
</build>
|
|
</project>
|