Search in sources :

Example 1 with EventStreamException

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);
    }
}
Also used : StoreEventRequestFailedException(uk.gov.justice.services.eventsourcing.repository.jdbc.exception.StoreEventRequestFailedException) EventStreamException(uk.gov.justice.services.eventsourcing.source.core.exception.EventStreamException) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope)

Aggregations

StoreEventRequestFailedException (uk.gov.justice.services.eventsourcing.repository.jdbc.exception.StoreEventRequestFailedException)1 EventStreamException (uk.gov.justice.services.eventsourcing.source.core.exception.EventStreamException)1 JsonEnvelope (uk.gov.justice.services.messaging.JsonEnvelope)1