Skip to content

Commit

Permalink
fix: event should be trigger AFTER commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Thibault committed May 31, 2024
1 parent e3edd97 commit b87be00
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>com.sipios</groupId>
<artifactId>spring-data-event</artifactId>
<version>0.1.0</version>
<version>0.2.0</version>
<name>com.sipios:spring-data-event</name>

<description>A Java library offering the @DataEventEntity annotation for publishing database entity changes to a Kafka queue, enabling straightforward event-driven architectures by automating event publication upon entity persistence.</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.springframework.stereotype.Component;

@Component
public class DataEventListener implements PostInsertEventListener, PostUpdateEventListener, PostDeleteEventListener {
public class DataEventListener implements PostCommitInsertEventListener, PostCommitUpdateEventListener, PostCommitDeleteEventListener {

private final DataEventBroadcaster dataEventBroadcaster;
private final EntityManagerFactory entityManagerFactory;
Expand All @@ -20,9 +20,9 @@ public class DataEventListener implements PostInsertEventListener, PostUpdateEve
private void init() {
SessionFactoryImpl sessionFactory = entityManagerFactory.unwrap(SessionFactoryImpl.class);
EventListenerRegistry registry = sessionFactory.getServiceRegistry().getService(EventListenerRegistry.class);
registry.getEventListenerGroup(EventType.POST_INSERT).appendListener(this);
registry.getEventListenerGroup(EventType.POST_UPDATE).appendListener(this);
registry.getEventListenerGroup(EventType.POST_DELETE).appendListener(this);
registry.getEventListenerGroup(EventType.POST_COMMIT_INSERT).appendListener(this);
registry.getEventListenerGroup(EventType.POST_COMMIT_UPDATE).appendListener(this);
registry.getEventListenerGroup(EventType.POST_COMMIT_DELETE).appendListener(this);
}

public DataEventListener(DataEventBroadcaster dataEventBroadcaster, EntityManagerFactory entityManagerFactory) {
Expand Down Expand Up @@ -58,4 +58,17 @@ public void onPostUpdate(PostUpdateEvent event) {
public boolean requiresPostCommitHandling(EntityPersister persister) {
return true;
}

@Override
public void onPostInsertCommitFailed(PostInsertEvent event) {
}

@Override
public void onPostDeleteCommitFailed(PostDeleteEvent event) {

}

@Override
public void onPostUpdateCommitFailed(PostUpdateEvent event) {
}
}

0 comments on commit b87be00

Please sign in to comment.