Exemplo n.º 1
0
        public BoundedContextListener(
            BoundedContextListenerConfiguration configuration,
            IEventConverter eventConverter,
            IUncommittedEventStreamCoordinator uncommittedEventStreamCoordinator,
            ILogger logger,
            IApplicationResourceIdentifierConverter applicationResourceIdentifierConverter,
            IImplementationsOf <IEvent> eventTypes,
            IEventStore eventStore,
            IEventEnvelopes eventEnvelopes,
            IEventSequenceNumbers eventSequenceNumbers,
            IEventSourceVersions eventSourceVersions,
            ICommittedEventStreamBridge committedEventStreamBridge,
            IConsumer consumer)
        {
            _eventConverter = eventConverter;
            _uncommittedEventStreamCoordinator = uncommittedEventStreamCoordinator;
            _logger = logger;
            _applicationResourceIdentifierConverter = applicationResourceIdentifierConverter;
            _eventTypes                 = eventTypes;
            _eventSequenceNumbers       = eventSequenceNumbers;
            _eventStore                 = eventStore;
            _eventEnvelopes             = eventEnvelopes;
            _eventSourceVersions        = eventSourceVersions;
            _committedEventStreamBridge = committedEventStreamBridge;
            _consumer = consumer;

            _serializer    = new JsonSerializer();
            _configuration = configuration;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of <see cref="Serializer"/>
 /// </summary>
 /// <param name="container">A <see cref="IContainer"/> used to create instances of types during serialization</param>
 /// <param name="applicationResourceIdentifierConverter"><see cref="IApplicationResourceIdentifierConverter"/> for converting string representations of <see cref="IApplicationResourceIdentifier"/></param>
 public Serializer(IContainer container, IApplicationResourceIdentifierConverter applicationResourceIdentifierConverter)
 {
     _container = container;
     _applicationResourceIdentifierConverter = applicationResourceIdentifierConverter;
     _cacheAutoTypeName = new ConcurrentDictionary <ISerializationOptions, JsonSerializer>();
     _cacheNoneTypeName = new ConcurrentDictionary <ISerializationOptions, JsonSerializer>();
 }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of <see cref="EventSequenceNumbers"/>
        /// </summary>
        /// <param name="configuration"><see cref="EventSequenceNumbersConfiguration">Configuration</see></param>
        /// <param name="applicationResourceIdentifierConverter">Converter for converting <see cref="IApplicationResourceIdentifier"/> "/></param>
        public EventSequenceNumbers(
            EventSequenceNumbersConfiguration configuration,
            IApplicationResourceIdentifierConverter applicationResourceIdentifierConverter)
        {
            _applicationResourceIdentifierConverter = applicationResourceIdentifierConverter;

            var redis = ConnectionMultiplexer.Connect(string.Join(";", configuration.ConnectionStrings));

            _database = redis.GetDatabase();
        }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of <see cref="EventSequenceNumbers"/>
 /// </summary>
 /// <param name="configuration"><see cref="EventSequenceNumbersConfiguration">Configuration</see>"/></param>
 /// <param name="applicationResourceIdentifierConverter"><see cref="IApplicationResourceIdentifierConverter"/> for getting string representation of <see cref="IApplicationResourceIdentifier"/></param>
 /// <param name="files"><see cref="IFiles"/> to work with files</param>
 /// <param name="logger"><see cref="ILogger"/> for logging</param>
 public EventSequenceNumbers(
     EventSequenceNumbersConfiguration configuration,
     IApplicationResourceIdentifierConverter applicationResourceIdentifierConverter,
     IFiles files,
     ILogger logger)
 {
     _configuration = configuration;
     _applicationResourceIdentifierConverter = applicationResourceIdentifierConverter;
     _files = files;
     logger.Information($"Using path : {configuration.Path}");
 }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of <see cref="EventSourceVersions"/>
        /// </summary>
        /// <param name="configuration"><see cref="EventSourceVersionsConfiguration">Configuration</see></param>
        /// <param name="eventStore"><see cref="IEventStore"/> for getting information if not in the database</param>
        /// <param name="applicationResourceIdentifierConverter">Converter for converting <see cref="IApplicationResourceIdentifier"/> "/></param>
        public EventSourceVersions(
            EventSourceVersionsConfiguration configuration,
            IEventStore eventStore,
            IApplicationResourceIdentifierConverter applicationResourceIdentifierConverter)
        {
            _applicationResourceIdentifierConverter = applicationResourceIdentifierConverter;
            _eventStore = eventStore;

            var redis = ConnectionMultiplexer.Connect(string.Join(";", configuration.ConnectionStrings));

            _database = redis.GetDatabase();
        }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of <see cref="EventSourceVersions"/>
 /// </summary>
 /// <param name="files">A system to work with <see cref="IFiles"/></param>
 /// <param name="eventStore"><see cref="IEventStore"/> for getting information if not found in file system</param>
 /// <param name="applicationResourceIdentifierConverter">Converter for converting <see cref="IApplicationResourceIdentifier"/> "/></param>
 /// <param name="pathProvider">A delegate that can provide path to store <see cref="EventSourceVersion"/> for <see cref="IEventSource"/> - see <see cref="ICanProvideEventSourceVersionsPath"/></param>
 /// <param name="logger"><see cref="ILogger"/> for logging</param>
 public EventSourceVersions(
     IFiles files,
     IEventStore eventStore,
     IApplicationResourceIdentifierConverter applicationResourceIdentifierConverter,
     ICanProvideEventSourceVersionsPath pathProvider,
     ILogger logger)
 {
     _files      = files;
     _eventStore = eventStore;
     _applicationResourceIdentifierConverter = applicationResourceIdentifierConverter;
     _path = pathProvider();
     logger.Information($"Using path : {_path}");
 }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of <see cref="EventStore"/>
 /// </summary>
 /// <param name="configuration"><see cref="EventStoreConfiguration"/> to use as configuration</param>
 /// <param name="applicationResources"><see cref="IApplicationResources"/> for working with <see cref="IApplicationResource">application resources</see></param>
 /// <param name="applicationResourceIdentifierConverter"><see cref="IApplicationResourceIdentifierConverter"/> for working with conversion of <see cref="IApplicationResourceIdentifier"/></param>
 /// <param name="applicationResourceResolver"><see cref="IApplicationResourceResolver"/> for resolving <see cref="IApplicationResourceIdentifier"/> to concrete types</param>
 /// <param name="eventEnvelopes"><see cref="IEventEnvelopes"/> for working with <see cref="EventEnvelope"/></param>
 /// <param name="serializer"><see cref="ISerializer"/> to use for serialization</param>
 public EventStore(
     EventStoreConfiguration configuration,
     IApplicationResources applicationResources,
     IApplicationResourceIdentifierConverter applicationResourceIdentifierConverter,
     IApplicationResourceResolver applicationResourceResolver,
     IEventEnvelopes eventEnvelopes,
     ISerializer serializer)
 {
     _configuration        = configuration;
     _eventEnvelopes       = eventEnvelopes;
     _applicationResources = applicationResources;
     _applicationResourceIdentifierConverter = applicationResourceIdentifierConverter;
     _applicationResourceResolver            = applicationResourceResolver;
     _serializer = serializer;
 }
Exemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of <see cref="ProcessMethodEventProcessors"/>
        /// </summary>
        /// <param name="applicationResources"><see cref="IApplicationResources"/> for identifying <see cref="IEvent">events</see> </param>
        /// <param name="applicationResourcesIdentifierConverter"><see cref="IApplicationResourceIdentifierConverter"/> for converting <see cref="IApplicationResourceIdentifier"/> to and from different formats</param>
        /// <param name="typeFinder"><see cref="ITypeFinder"/> for discovering implementations of <see cref="IProcessEvents"/></param>
        /// <param name="container"><see cref="IContainer"/> for the implementation <see cref="ProcessMethodEventProcessor"/> when acquiring instances of implementations of <see cref="IProcessEvents"/></param>
        /// <param name="systemClock"><see cref="ISystemClock"/> for timing <see cref="IEventProcessors"/></param>
        public ProcessMethodEventProcessors(
            IApplicationResources applicationResources,
            IApplicationResourceIdentifierConverter applicationResourcesIdentifierConverter,
            ITypeFinder typeFinder,
            IContainer container,
            ISystemClock systemClock)
        {
            _applicationResources = applicationResources;
            _applicationResourcesIdentifierConverter = applicationResourcesIdentifierConverter;
            _typeFinder  = typeFinder;
            _container   = container;
            _systemClock = systemClock;

            PopulateEventProcessors();
        }
Exemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of <see cref="CommittedEventStreamCoordinator"/>
        /// </summary>
        /// <param name="serializer"><see cref="ISerializer"/> to use for deserializing <see cref="IEvent">events</see></param>
        /// <param name="applicationResourceIdentifierConverter"><see cref="IApplicationResourceIdentifierConverter"/> used for converting resource identifiers</param>
        /// <param name="applicationResourceResolver"><see cref="IApplicationResourceResolver"/> used for resolving types from <see cref="IApplicationResourceIdentifier"/></param>
        /// <param name="connectionStringProvider"><see cref="ICanProvideConnectionStringToReceiver">Provider</see> of connection string</param>
        public CommittedEventStreamReceiver(
            ISerializer serializer,
            IApplicationResourceIdentifierConverter applicationResourceIdentifierConverter,
            IApplicationResourceResolver applicationResourceResolver,
            ICanProvideConnectionStringToReceiver connectionStringProvider)
        {
            _serializer = serializer;
            _applicationResourceIdentifierConverter = applicationResourceIdentifierConverter;
            _applicationResourceResolver            = applicationResourceResolver;

            var connectionString = connectionStringProvider();

            _queueClient = new QueueClient(connectionString, Constants.QueueName, ReceiveMode.PeekLock);
            _queueClient.RegisterMessageHandler(Receive);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Initializes a new instance of <see cref="EventStore"/>
        /// </summary>
        /// <param name="applicationResources">System for dealing with <see cref="IApplicationResources">Application Resources</see></param>
        /// <param name="applicationResourceIdentifierConverter"><see cref="IApplicationResourceIdentifierConverter">Converter</see> for converting to and from string representations</param>
        /// <param name="connectionStringProvider"><see cref="ICanProvideConnectionString">ConnectionString provider</see></param>
        public EventStore(
            IApplicationResources applicationResources,
            IApplicationResourceIdentifierConverter applicationResourceIdentifierConverter,
            ICanProvideConnectionString connectionStringProvider)
        {
            _applicationResources = applicationResources;
            _applicationResourceIdentifierConverter = applicationResourceIdentifierConverter;
            var connectionString = connectionStringProvider();

            var account     = CloudStorageAccount.Parse(connectionString);
            var tableClient = account.CreateCloudTableClient();

            _table = tableClient.GetTableReference(EventStoreTable);

            _table.CreateIfNotExistsAsync();
        }
Exemplo n.º 11
0
        public CommandProxies(
            IApplicationResources applicationResources,
            IApplicationResourceIdentifierConverter applicationResourceIdentifierConverter,
            ITypeFinder typeFinder,
            IInstancesOf <ICanExtendCommandProperty> commandPropertyExtenders,
            ICodeGenerator codeGenerator,
            WebConfiguration configuration)
        {
            _applicationResources = applicationResources;
            _applicationResourceIdentifierConverter = applicationResourceIdentifierConverter;
            _typeFinder = typeFinder;
            _commandPropertyExtenders = commandPropertyExtenders;
            _codeGenerator            = codeGenerator;

            _configuration = configuration;
        }
        /// <summary>
        /// Initializes a new instance of <see cref="ProcessMethodEventProcessors"/>
        /// </summary>
        /// <param name="applicationResources"><see cref="IApplicationResources"/> for identifying <see cref="IEvent">events</see> </param>
        /// <param name="applicationResourcesIdentifierConverter"><see cref="IApplicationResourceIdentifierConverter"/> for converting <see cref="IApplicationResourceIdentifier"/> to and from different formats</param>
        /// <param name="typeDiscoverer"><see cref="ITypeDiscoverer"/> for discovering implementations of <see cref="IProcessEvents"/></param>
        /// <param name="container"><see cref="IContainer"/> for the implementation <see cref="ProcessMethodEventProcessor"/> when acquiring instances of implementations of <see cref="IProcessEvents"/></param>
        /// <param name="systemClock"><see cref="ISystemClock"/> for timing <see cref="IEventProcessors"/></param>
        /// <param name="logger"><see cref="ILogger"/> to use for logging</param>
        public ProcessMethodEventProcessors(
            IApplicationResources applicationResources,
            IApplicationResourceIdentifierConverter applicationResourcesIdentifierConverter,
            ITypeDiscoverer typeDiscoverer,
            IContainer container,
            ISystemClock systemClock,
            ILogger logger)
        {
            _applicationResources = applicationResources;
            _applicationResourcesIdentifierConverter = applicationResourcesIdentifierConverter;
            _typeDiscoverer = typeDiscoverer;
            _container      = container;
            _systemClock    = systemClock;
            _logger         = logger;

            PopulateEventProcessors();
        }
Exemplo n.º 13
0
 /// <summary>
 /// Initializes a new instance of <see cref="EventStore"/>
 /// </summary>
 /// <param name="configuration"><see cref="EventStoreConfiguration"/> to use as configuration</param>
 /// <param name="applicationResources"><see cref="IApplicationResources"/> for working with <see cref="IApplicationResource">application resources</see></param>
 /// <param name="applicationResourceIdentifierConverter"><see cref="IApplicationResourceIdentifierConverter"/> for working with conversion of <see cref="IApplicationResourceIdentifier"/></param>
 /// <param name="applicationResourceResolver"><see cref="IApplicationResourceResolver"/> for resolving <see cref="IApplicationResourceIdentifier"/> to concrete types</param>
 /// <param name="eventEnvelopes"><see cref="IEventEnvelopes"/> for working with <see cref="EventEnvelope"/></param>
 /// <param name="serializer"><see cref="ISerializer"/> to use for serialization</param>
 /// <param name="files"><see cref="IFiles"/> to work with files</param>
 /// <param name="logger"><see cref="ILogger"/> for logging</param>
 public EventStore(
     EventStoreConfiguration configuration,
     IApplicationResources applicationResources,
     IApplicationResourceIdentifierConverter applicationResourceIdentifierConverter,
     IApplicationResourceResolver applicationResourceResolver,
     IEventEnvelopes eventEnvelopes,
     ISerializer serializer,
     IFiles files,
     ILogger logger)
 {
     logger.Information($"Using path : {configuration.Path}");
     _configuration        = configuration;
     _eventEnvelopes       = eventEnvelopes;
     _applicationResources = applicationResources;
     _applicationResourceIdentifierConverter = applicationResourceIdentifierConverter;
     _applicationResourceResolver            = applicationResourceResolver;
     _serializer = serializer;
     _files      = files;
 }
Exemplo n.º 14
0
        /// <summary>
        /// Initializes a new instance of <see cref="EventStore"/>
        /// </summary>
        /// <param name="applicationResources">System for dealing with <see cref="IApplicationResources">Application Resources</see></param>
        /// <param name="applicationResourceIdentifierConverter"><see cref="IApplicationResourceIdentifierConverter">Converter</see> for converting to and from string representations</param>
        /// <param name="applicationResourceResolver"><see cref="IApplicationResourceResolver"/> for resolving types from <see cref="IApplicationResourceIdentifier">identifiers</see></param>
        /// <param name="connectionStringProvider"><see cref="ICanProvideConnectionString">ConnectionString provider</see></param>
        public EventStore(
            IApplicationResources applicationResources,
            IApplicationResourceIdentifierConverter applicationResourceIdentifierConverter,
            IApplicationResourceResolver applicationResourceResolver,
            ICanProvideConnectionString connectionStringProvider)
        {
            _applicationResources = applicationResources;
            _applicationResourceIdentifierConverter = applicationResourceIdentifierConverter;
            _applicationResourceResolver            = applicationResourceResolver;
            var connectionString = connectionStringProvider();

            var account = CloudStorageAccount.Parse(connectionString);

            var tableClient = account.CreateCloudTableClient();

            tableClient.DefaultRequestOptions.RetryPolicy = new ExponentialRetry(TimeSpan.FromMilliseconds(100), 5);
            _table = tableClient.GetTableReference(EventStoreTable);

            _table.CreateIfNotExistsAsync();
        }
 /// <summary>
 /// Initializes a new instance of <see cref="ApplicationResourceIdentifierJsonConverter"/>
 /// </summary>
 /// <param name="converter"></param>
 public ApplicationResourceIdentifierJsonConverter(IApplicationResourceIdentifierConverter converter)
 {
     _converter = converter;
 }
Exemplo n.º 16
0
 /// <summary>
 /// Initializes a new instance
 /// </summary>
 /// <param name="applicationResourceIdentifierConverter"><see cref="IApplicationResourceIdentifierConverter"/> for converting to and from <see cref="IApplicationResourceIdentifier"/></param>
 public ConvertersProvider(IApplicationResourceIdentifierConverter applicationResourceIdentifierConverter)
 {
     _applicationResourceIdentifierConverter = applicationResourceIdentifierConverter;
 }
 /// <summary>
 /// Initializes a new instance of <see cref="EventSequenceNumbers"/>
 /// </summary>
 /// <param name="configuration"><see cref="EventSequenceNumbersConfiguration">Configuration</see>"/></param>
 /// <param name="applicationResourceIdentifierConverter"><see cref="IApplicationResourceIdentifierConverter"/> for getting string representation of <see cref="IApplicationResourceIdentifier"/></param>
 public EventSequenceNumbers(EventSequenceNumbersConfiguration configuration, IApplicationResourceIdentifierConverter applicationResourceIdentifierConverter)
 {
     _configuration = configuration;
     _applicationResourceIdentifierConverter = applicationResourceIdentifierConverter;
 }
        /// <summary>
        /// Initializes a new instance of <see cref="CommittedEventStreamCoordinator"/>
        /// </summary>
        /// <param name="serializer"><see cref="ISerializer"/> to use for deserializing <see cref="IEvent">events</see></param>
        /// <param name="applicationResourceIdentifierConverter"><see cref="IApplicationResourceIdentifierConverter"/> used for converting resource identifiers</param>
        /// <param name="applicationResourceResolver"><see cref="IApplicationResourceResolver"/> used for resolving types from <see cref="IApplicationResourceIdentifier"/></param>
        /// <param name="connectionStringProvider"><see cref="ICanProvideConnectionStringToReceiver">Provider</see> of connection string</param>
        public CommittedEventStreamReceiver(
            ISerializer serializer,
            IApplicationResourceIdentifierConverter applicationResourceIdentifierConverter,
            IApplicationResourceResolver applicationResourceResolver,
            ICanProvideConnectionStringToReceiver connectionStringProvider)
        {
            _serializer = serializer;
            var factory = new ConnectionFactory();

            factory.Uri = connectionStringProvider();

            var connection   = factory.CreateConnection();
            var exchangeName = "Events";
            var routingKey   = "RoutingKey";
            var queueName    = "Events";

            var model = connection.CreateModel();

            model.ExchangeDeclare(exchangeName, ExchangeType.Direct);
            model.QueueDeclare(queueName, false, false, false, null);
            model.QueueBind(queueName, exchangeName, routingKey, null);

            var consumer = new EventingBasicConsumer(model);

            consumer.Received += (ch, ea) =>
            {
                try
                {
                    var dynamicEventsAndEnvelopes = new List <dynamic>();
                    var json = System.Text.Encoding.UTF8.GetString(ea.Body);

                    _serializer.FromJson(dynamicEventsAndEnvelopes, json);

                    var eventsAndEnvelopes = new List <EventAndEnvelope>();

                    foreach (var dynamicEventAndEnvelope in dynamicEventsAndEnvelopes)
                    {
                        var env = dynamicEventAndEnvelope.Envelope;

                        var correlationId              = (TransactionCorrelationId)Guid.Parse(env.CorrelationId.ToString());
                        var eventId                    = (EventId)Guid.Parse(env.EventId.ToString());
                        var sequenceNumber             = (EventSequenceNumber)long.Parse(env.SequenceNumber.ToString());
                        var sequenceNumberForEventType = (EventSequenceNumber)long.Parse(env.SequenceNumberForEventType.ToString());
                        var generation                 = (EventGeneration)long.Parse(env.Generation.ToString());
                        var @event        = applicationResourceIdentifierConverter.FromString(env.Event.ToString());
                        var eventSourceId = (EventSourceId)Guid.Parse(env.EventSourceId.ToString());
                        var eventSource   = applicationResourceIdentifierConverter.FromString(env.EventSource.ToString());
                        var version       = (EventSourceVersion)EventSourceVersion.FromCombined(double.Parse(env.Version.ToString()));
                        var causedBy      = (CausedBy)env.CausedBy.ToString();
                        var occurred      = DateTimeOffset.Parse(env.Occurred.ToString());

                        var envelope = new EventEnvelope(
                            correlationId,
                            eventId,
                            sequenceNumber,
                            sequenceNumberForEventType,
                            generation,
                            @event,
                            eventSourceId,
                            eventSource,
                            version,
                            causedBy,
                            occurred
                            );

                        var eventType     = applicationResourceResolver.Resolve(@event);
                        var eventInstance = Activator.CreateInstance(eventType, new object[] { eventSourceId }) as IEvent;
                        var e             = dynamicEventAndEnvelope.Event.ToString();

                        _serializer.FromJson(eventInstance, e);

                        eventsAndEnvelopes.Add(new EventAndEnvelope(envelope, eventInstance));
                    }

                    var stream = new CommittedEventStream(eventsAndEnvelopes.First().Envelope.EventSourceId, eventsAndEnvelopes);
                    Received(stream);

                    model.BasicAck(ea.DeliveryTag, false);
                }
                catch
                {
                }
                finally
                {
                }
            };

            Task.Run(() => model.BasicConsume(queueName, false, consumer));
        }
        public BoundedContextListener(
            KafkaConnectionString connectionString,
            ListenerConfiguration configuration,
            IEventConverter eventConverter,
            IUncommittedEventStreamCoordinator uncommittedEventStreamCoordinator,
            ISerializer serializer,
            ILogger logger,
            IApplicationResourceIdentifierConverter applicationResourceIdentifierConverter,
            IImplementationsOf <IEvent> eventTypes,
            IEventStore eventStore,
            IEventEnvelopes eventEnvelopes,
            IEventSequenceNumbers eventSequenceNumbers,
            IEventSourceVersions eventSourceVersions,
            ICommittedEventStreamBridge committedEventStreamBridge)
        {
            _serializer     = serializer;
            _eventConverter = eventConverter;
            _uncommittedEventStreamCoordinator = uncommittedEventStreamCoordinator;
            _logger = logger;
            _applicationResourceIdentifierConverter = applicationResourceIdentifierConverter;
            _eventTypes                 = eventTypes;
            _eventSequenceNumbers       = eventSequenceNumbers;
            _eventStore                 = eventStore;
            _eventEnvelopes             = eventEnvelopes;
            _eventSourceVersions        = eventSourceVersions;
            _committedEventStreamBridge = committedEventStreamBridge;



            logger.Information($"Listening on topic '{configuration.Topic}' from '{connectionString}'");

            var config = new Dictionary <string, object>
            {
                { "bootstrap.servers", connectionString },
                { "group.id", "simple-consumer" },
                { "enable.auto.commit", true },
                { "auto.commit.interval.ms", 1000 },
                {
                    "default.topic.config",
                    new Dictionary <string, object>()
                    {
                        { "auto.offset.reset", "smallest" }
                    }
                }
            };

            _consumer = new Consumer <Ignore, string>(config, null, new StringDeserializer(Encoding.UTF8));
            _consumer.Assign(new [] { new TopicPartition(configuration.Topic, 0) });
            _consumer.OnMessage += (_, msg) =>
            {
                try
                {
                    logger.Trace($"Message received '{msg.Value}'");
                    var raw = _serializer.FromJson <dynamic[]>(msg.Value);

                    foreach (var rawContentAndEnvelope in raw)
                    {
                        var eventSourceId   = (EventSourceId)Guid.Parse(rawContentAndEnvelope.Content.EventSourceId.ToString());
                        var eventIdentifier = _applicationResourceIdentifierConverter.FromString(rawContentAndEnvelope.Envelope.Event.ToString());
                        var version         = EventSourceVersion.FromCombined((double)rawContentAndEnvelope.Envelope.Version);
                        var correlationId   = (TransactionCorrelationId)Guid.Parse(rawContentAndEnvelope.Envelope.CorrelationId.ToString());
                        CorrelationId = correlationId;

                        _logger.Trace($"Received event of with resource name '{eventIdentifier.Resource.Name}' from '{eventSourceId}' with version '{version}' in correlation '{correlationId}'");
                        var eventType = _eventTypes.SingleOrDefault(et => et.Name == eventIdentifier.Resource.Name);
                        if (eventType != null)
                        {
                            _logger.Trace("Matching Event Type : " + eventType.AssemblyQualifiedName);
                            var @event = Activator.CreateInstance(eventType, eventSourceId) as IEvent;
                            _serializer.FromJson(@event, rawContentAndEnvelope.Content.ToString());

                            var eventSource            = new ExternalSource(eventSourceId);
                            var uncommittedEventStream = new UncommittedEventStream(eventSource);
                            uncommittedEventStream.Append(@event, version);


                            _logger.Information($"Committing uncommitted event stream with correlationId '{correlationId}'");
                            var envelopes        = _eventEnvelopes.CreateFrom(eventSource, uncommittedEventStream.EventsAndVersion);
                            var envelopesAsArray = envelopes.ToArray();
                            var eventsAsArray    = uncommittedEventStream.ToArray();

                            _logger.Trace("Create an array of events and envelopes");
                            var eventsAndEnvelopes = new List <EventAndEnvelope>();
                            for (var eventIndex = 0; eventIndex < eventsAsArray.Length; eventIndex++)
                            {
                                var envelope     = envelopesAsArray[eventIndex];
                                var currentEvent = eventsAsArray[eventIndex];
                                eventsAndEnvelopes.Add(new EventAndEnvelope(
                                                           envelope
                                                           .WithTransactionCorrelationId(correlationId)
                                                           .WithSequenceNumber(_eventSequenceNumbers.Next())
                                                           .WithSequenceNumberForEventType(_eventSequenceNumbers.NextForType(envelope.Event)),
                                                           currentEvent
                                                           ));
                            }

                            _logger.Trace("Committing events to event store");
                            _eventStore.Commit(eventsAndEnvelopes);

                            _logger.Trace($"Set event source versions for the event source '{envelopesAsArray[0].EventSource}' with id '{envelopesAsArray[0].EventSourceId}'");
                            _eventSourceVersions.SetFor(envelopesAsArray[0].EventSource, envelopesAsArray[0].EventSourceId, envelopesAsArray[envelopesAsArray.Length - 1].Version);

                            _logger.Trace("Create a committed event stream");
                            var committedEventStream = new CommittedEventStream(uncommittedEventStream.EventSourceId, eventsAndEnvelopes);
                            _committedEventStreamBridge.Send(committedEventStream);

                            CorrelationId = Guid.Empty;
                        }
                    }
                }
                catch (Exception ex)
                {
                    _logger.Error(ex, "Error during receiving");
                }
            };
        }