- Spring Modulith Implementation
- Data Setup
- Learnings
- How Spring Modulith Behaves when there are multiple instance of same application deployed (Without
@Externalized
) - After Using
@Externalized
annotation - How Spring Modulith Behaves when we have
@Externalized
event to kafka and also has one event listener in Application - Postman Collection for API's present in Project
- Useful Commands
- Reference
- Navigate to
datasetup
directory. - Run
./setupData.sh
file. - After successful execution of step-2 it adds sample data.
- For each listener annotated with
@ApplicationModuleListener
/@TransactionalEventListener
it created one entry inevent_publication
table - When we use simple
@EventListener
it doesn't create entry inevent_publication
table. it publishes event synchronously. - When we remove
@Transactional
from the method which is publishing the event then event is stored inevent_publication
table but not consumed by listener methods annotated with@ApplicationModuleListener
/@TransactionalEventListener
/@EventListener
.
How Spring Modulith Behaves when there are multiple instance of same application deployed (Without @Externalized
)
- When
instance 1
andinstance 2
of applications are deployed together - The event published by
instance 1
will be consumed by consumer in sameinstance 1
- If
instance 1
publishes the event, and before it is consumed by consumer ifinstance 1
terminated then event won't be consumed byinstance 2
's consumer. - If
instance 1
publishes the event, and before it is consumed by consumer ifinstance 1
terminated then the new instanceinstance 3
that will be spin up can republish the outstanding messages ifspring.modulith.republish-outstanding-events-on-restart=true
property is enabled . - In order to handle republishing of outstanding events on demand we can use
IncompleteEventPublications
to resubmit outstanding events.
- With
@Externalized
annotation we can publish messages to various targets as given in spring modulith documentation. - When
@Externalized
annotation is used and Modulith starts publishing events to Kafka. In order to see the published message on topicFoodOrderPlaced
mention astarget
in@Externalized(target = "FoodOrderPlaced")
event record. We can used below kafka console consumer command to consume kafka messageskafka-console-consumer --bootstrap-server localhost:29092 --topic FoodOrderPlaced --from-beginning
How Spring Modulith Behaves when we have @Externalized
event to kafka and also has one event listener in Application
- It creates one event of type
org.springframework.modulith.events.support.DelegatingEventExternalizer.externalize(java.lang.Object)
for kafka and another event for event listener in Application inevent_publication
table
- Navigate to
Postman collection
directory. - Import
FoodDelivery.postman_collection.json
file in postman.
- To make container service up
podman-compose up -d
- To make container service down
podman-compose down