Transaction Synchronization and Spring Application Events
summary
Creates a Customer entity, publishes a CustomerCreated event after saving with Spring Data JPA and an embedded H2, and attempts token generation in a listener; initial test shows token is missing because the listener runs in the same transaction and afterCommit callbacks still see original transaction resources. Solution options shown: mark the listener with REQUIRES_NEW to create an autonomous transaction or run the handler with @Async; unit tests fail first then pass after changing to REQUIRES_NEW or async.
AI-written summary · about
chapters (20)
- 0:00Introduction
- 1:39Agenda
- 5:07IDE
- 5:43Customer class
- 7:42Why not use simple gathers and setters
- 9:24Service method
- 10:02Transactional method
- 10:40Spring Boot Test
- 12:40Token Generation
- 15:52Customer ID
- 16:25Publisher
- 18:58Test
- 19:43Transactional EvenListener
- 21:10Synchronization Phases
- 21:41Testing
- 23:36Autonomous Transaction
- 24:16Synchronization
- 25:41Enabling ancing
- 26:18Static wait
- 27:58Reliability and Data Consistency
related talks
42mEffective transaction management with Spring
33mEffective Transactions Management with Spring
01h 17mUsing @Transactional Like a Pro
50mThe harsh reality of Event Sourcing - mitigated with Spring and Axon on Tanzu Application Platform
56mEvents on the outside, on the inside and at the core
48mTesting Your Message-Driven Application
51mNot Just Events: Developing Asynchronous Microservices
41mTransactions in Your Micro-Services Architecture
