From 25f789f2989709cf8824f5ba2ecf20f05be3d08c Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Thu, 22 Dec 2022 23:12:50 +0100 Subject: [PATCH] GH-80 - Renamed ApplicationModuleIntegrationListener to ApplicationModuleListener. --- ...er.java => ApplicationModuleListener.java} | 4 +- .../inventory/InventoryManagement.java | 4 +- .../order/EventPublicationRegistryTests.java | 4 +- src/docs/asciidoc/40-events.adoc | 37 +++++++------------ 4 files changed, 20 insertions(+), 29 deletions(-) rename spring-modulith-api/src/main/java/org/springframework/modulith/{ApplicationModuleIntegrationListener.java => ApplicationModuleListener.java} (93%) diff --git a/spring-modulith-api/src/main/java/org/springframework/modulith/ApplicationModuleIntegrationListener.java b/spring-modulith-api/src/main/java/org/springframework/modulith/ApplicationModuleListener.java similarity index 93% rename from spring-modulith-api/src/main/java/org/springframework/modulith/ApplicationModuleIntegrationListener.java rename to spring-modulith-api/src/main/java/org/springframework/modulith/ApplicationModuleListener.java index 735de209..3204dd89 100644 --- a/spring-modulith-api/src/main/java/org/springframework/modulith/ApplicationModuleIntegrationListener.java +++ b/spring-modulith-api/src/main/java/org/springframework/modulith/ApplicationModuleListener.java @@ -28,7 +28,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.event.TransactionalEventListener; /** - * An {@link ApplicationModuleIntegrationListener} is an {@link Async} Spring {@link TransactionalEventListener} that + * An {@link ApplicationModuleListener} is an {@link Async} Spring {@link TransactionalEventListener} that * runs in a transaction itself. Thus, the annotation serves as syntactic sugar for the generally recommend setup to * integrate application modules via events. The setup makes sure that an original business transaction completes * successfully and the integration asynchronously runs in a transaction itself to decouple the integration as much as @@ -47,7 +47,7 @@ import org.springframework.transaction.event.TransactionalEventListener; @Documented @Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE }) @Retention(RetentionPolicy.RUNTIME) -public @interface ApplicationModuleIntegrationListener { +public @interface ApplicationModuleListener { /** * Whether the transaction to be run for the event listener is supposed to be read-only (default {@literal false}). diff --git a/spring-modulith-example/src/main/java/example/inventory/InventoryManagement.java b/spring-modulith-example/src/main/java/example/inventory/InventoryManagement.java index 78d33f96..144644cd 100644 --- a/spring-modulith-example/src/main/java/example/inventory/InventoryManagement.java +++ b/spring-modulith-example/src/main/java/example/inventory/InventoryManagement.java @@ -19,7 +19,7 @@ import example.order.OrderCompleted; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.modulith.ApplicationModuleIntegrationListener; +import org.springframework.modulith.ApplicationModuleListener; import org.springframework.stereotype.Service; /** @@ -34,7 +34,7 @@ public class InventoryManagement { private final InventoryInternal dependency; - @ApplicationModuleIntegrationListener + @ApplicationModuleListener void on(OrderCompleted event) throws InterruptedException { var orderId = event.getOrderId(); diff --git a/spring-modulith-example/src/test/java/example/order/EventPublicationRegistryTests.java b/spring-modulith-example/src/test/java/example/order/EventPublicationRegistryTests.java index b971a641..ddc23c10 100644 --- a/spring-modulith-example/src/test/java/example/order/EventPublicationRegistryTests.java +++ b/spring-modulith-example/src/test/java/example/order/EventPublicationRegistryTests.java @@ -22,7 +22,7 @@ import lombok.RequiredArgsConstructor; import org.junit.jupiter.api.Test; import org.springframework.context.annotation.Import; -import org.springframework.modulith.ApplicationModuleIntegrationListener; +import org.springframework.modulith.ApplicationModuleListener; import org.springframework.modulith.events.EventPublicationRegistry; import org.springframework.modulith.test.ApplicationModuleTest; import org.springframework.test.annotation.DirtiesContext; @@ -56,7 +56,7 @@ class EventPublicationRegistryTests { static class FailingAsyncTransactionalEventListener { - @ApplicationModuleIntegrationListener + @ApplicationModuleListener void foo(OrderCompleted event) { throw new IllegalStateException(); } diff --git a/src/docs/asciidoc/40-events.adoc b/src/docs/asciidoc/40-events.adoc index 64e3c4e4..37345f7e 100644 --- a/src/docs/asciidoc/40-events.adoc +++ b/src/docs/asciidoc/40-events.adoc @@ -62,15 +62,12 @@ A different way of approaching this is by moving the event consumption to asynch .An async, transactional event listener [source, java] ---- -@Service -@RequiredArgsConstructor -public class InventoryManagement { +@Component +class InventoryManagement { @Async @TransactionalEventListener - void on(OrderCompleted event) { - - } + void on(OrderCompleted event) { /* … */ } } ---- @@ -79,39 +76,33 @@ While this avoids the expansion of the original business transaction, it also cr Even worse, that doesn't even fully work, as the system might fail before the method is even invoked. [[events.amil]] -== Application Module Integration Listener +== Application Module Listener -To run a transactional event listener in a transaction itself, it would need to be annotated with `@Transactional` itself. +To run a transactional event listener in a transaction itself, it would need to be annotated with `@Transactional` in turn. .An async, transactional event listener running in a transaction itself [source, java] ---- -@Service -@RequiredArgsConstructor -public class InventoryManagement { +@Component +class InventoryManagement { @Async @Transactional @TransactionalEventListener - void on(OrderCompleted event) { - - } + void on(OrderCompleted event) { /* … */ } } ---- -To ease the declaration of what is supposed to describe the default way of integrating modules via events, Spring Modulith provides `@ApplicationModuleIntegrationListener` to shortcut the declaration +To ease the declaration of what is supposed to describe the default way of integrating modules via events, Spring Modulith provides `@ApplicationModuleListener` to shortcut the declaration -.An application module integration listener +.An application module listener [source, java] ---- -@Service -@RequiredArgsConstructor -public class InventoryManagement { +@Component +class InventoryManagement { - @ApplicationModuleIntegrationListener - void on(OrderCompleted event) { - - } + @ApplicationModuleListener + void on(OrderCompleted event) { /* … */ } } ----