spring-projects / spring-projects/spring-data-commons

DomainEvent emitted again in EventListener

Open
#2,575 2 comments 1 reaction 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Mar 28, 2022.

status: feedback-provided
Dominant language
Java
Stars
838
Forks
730
PR merge metrics
No merged PRs in 30d

Description

A DomainEvent is emitted again when calling save or delete on the emitting Entity in the EventListener.
there is an Entity

  • implementing AbstractAggregateRoot
  • with a method registering a DomainEvent

a Service

  • is calling the method registering a DomainEvent
  • saving the Entity with the repository
    in a @EventListener method
  • the entity is taken from the event or looked up via repository
  • the entity is saved or deleted via the repository
  • the DomainEvent is emitted again
    an infinite loop is starting

If save or delete is called more then one time the event is emitted only once.
There is a demo attached showing the behavior.
demo-reemit-event-in-listener.zip

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.