for (DispatchableDomainEvent event : undispatchedEvents) {
this.dispatch(event);
}
DispatchableDomainEvent withLastEventId =
undispatchedEvents.get(undispatchedEvents.size() - 1);
long lastDispatchedEventId = withLastEventId.eventId();
this.setLastDispatchedEventId(lastDispatchedEventId);
this.saveLastDispatchedEventId(connection, lastDispatchedEventId);
}