spring-projects / spring-projects/spring-framework
Add support for batching event delivery in @EventListener and @TransactionalEventListener
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 60.2k
- Forks
- 38.8k
- Avg merge
- 5d 2h
- Merged PRs (30d)
- 27
Description
Description
Currently, Spring invokes @EventListener and @TransactionalEventListener methods once per published event. When multiple events of the same type are published within a single transaction, each results in a separate listener invocation.
It would be useful to support batched event delivery, allowing listeners to receive all events of the same type published during the transaction as a single List.
Use Case
Within a transactional service, multiple updates are performed, and corresponding domain events are published.
Each event triggers a separate listener call, resulting in multiple update statements and row locks.
Batch delivery would allow a single @TransactionalEventListener(phase = BEFORE_COMMIT) method to process all pending events together, enabling a single batched update.
Proposed Enhancement
Support for batched listener signatures such as:
@TransactionalEventListener(phase = TransactionPhase.BEFORE_COMMIT)
public void handleEvents(List<AppEvent> events) {
batchUpdate(events);
}
The framework could accumulate events per transaction (e.g., using TransactionSynchronizationManager) and dispatch them together before commit.
Benefits
- Reduces redundant database updates
- Minimizes row locking and improves transaction efficiency
- Simplifies batching logic for domain event processing
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the @EventListener and @TransactionalEventListener handling described in the issue, then examine how TransactionSynchronizationManager could collect events during a transaction. Done means listeners accepting List can receive same-type events together, including BEFORE_COMMIT transactional delivery, while preserving existing single-event behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100