use of uk.gov.justice.services.eventsourcing.source.core.exception.EventStreamException in project microservice_framework by CJSCommonPlatform.
the class PublishingEventAppender method append.
/**
* Stores the event in the event store and publishes it with the given streamId and version.
*
* @param event - the event to be appended
* @param streamId - id of the stream the event will be part of
* @param version - version id of the event in the stream
*/
@Override
public void append(final JsonEnvelope event, final UUID streamId, final long version) throws EventStreamException {
try {
if (version == INITIAL_EVENT_VERSION) {
eventRepository.createEventStream(streamId);
}
final JsonEnvelope eventWithStreamIdAndVersion = eventFrom(event, streamId, version);
eventRepository.storeEvent(eventWithStreamIdAndVersion);
eventPublisher.publish(eventWithStreamIdAndVersion);
} catch (StoreEventRequestFailedException e) {
throw new EventStreamException(format("Failed to append event to the event store %s", event.metadata().id()), e);
}
}
Aggregations