Search in sources :

Example 1 with StoreEventRequestFailedException

use of uk.gov.justice.services.eventsourcing.repository.jdbc.exception.StoreEventRequestFailedException in project microservice_framework by CJSCommonPlatform.

the class DefaultEventRepository method storeEvent.

@Override
@Transactional(dontRollbackOn = OptimisticLockingRetryException.class)
public void storeEvent(final JsonEnvelope envelope) throws StoreEventRequestFailedException {
    try {
        final Event event = eventConverter.eventOf(envelope);
        logger.trace("Storing event {} into stream {} at position {}", event.getName(), event.getStreamId(), event.getSequenceId());
        eventJdbcRepository.insert(event);
    } catch (InvalidPositionException ex) {
        throw new StoreEventRequestFailedException(String.format("Could not store event for position %d of stream %s", envelope.metadata().position().orElse(null), envelope.metadata().streamId().orElse(null)), ex);
    }
}
Also used : StoreEventRequestFailedException(uk.gov.justice.services.eventsourcing.repository.jdbc.exception.StoreEventRequestFailedException) Event(uk.gov.justice.services.eventsourcing.repository.jdbc.event.Event) InvalidPositionException(uk.gov.justice.services.eventsourcing.repository.jdbc.exception.InvalidPositionException) Transactional(javax.transaction.Transactional)

Example 2 with StoreEventRequestFailedException

use of uk.gov.justice.services.eventsourcing.repository.jdbc.exception.StoreEventRequestFailedException 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)2 Transactional (javax.transaction.Transactional)1 Event (uk.gov.justice.services.eventsourcing.repository.jdbc.event.Event)1 InvalidPositionException (uk.gov.justice.services.eventsourcing.repository.jdbc.exception.InvalidPositionException)1 EventStreamException (uk.gov.justice.services.eventsourcing.source.core.exception.EventStreamException)1 JsonEnvelope (uk.gov.justice.services.messaging.JsonEnvelope)1