Ejemplo n.º 1
0
 public EventStoreStatefulActorBuilder <TActor, TAggregate> WithReadOneStreamFromStartCache(
     string streamId,
     IEventTypeProvider <TAggregate> eventTypeProvider = null,
     Action <MultipleStreamsCatchupCacheConfiguration <TAggregate> > getMultipleStreamsCatchupCacheConfiguration = null)
 {
     return(WithReadManyStreamFromStartCache(new[] { streamId }, eventTypeProvider, getMultipleStreamsCatchupCacheConfiguration));
 }
Ejemplo n.º 2
0
        public EventStoreStatefulActorBuilder <TActor, TAggregate> WithReadManyStreamFromStartCache(
            string[] streamIds,
            IEventTypeProvider <TAggregate> eventTypeProvider = null,
            Action <MultipleStreamsCatchupCacheConfiguration <TAggregate> > getMultipleStreamsCatchupCacheConfiguration = null)
        {
            var getSubscribeFromEndMultipleStreamsEventStoreCache = new Func <IConnectionStatusMonitor <IEventStoreConnection>, ILoggerFactory, ISnapshotStore <TAggregate>, ISnapshotStrategy, IAggregateCache <TAggregate> >((connectionMonitor, loggerFactory, snapshotStore, snapshotStrategy) =>
            {
                var multipleStreamsCatchupCacheConfiguration = new MultipleStreamsCatchupCacheConfiguration <TAggregate>(streamIds)
                {
                    CrashAppIfSubscriptionFail = _actorConfiguration.CrashAppOnError
                };

                getMultipleStreamsCatchupCacheConfiguration?.Invoke(multipleStreamsCatchupCacheConfiguration);

                var multipleStreamsCatchupCache = new MultipleStreamsCatchupCache <TAggregate>(connectionMonitor, multipleStreamsCatchupCacheConfiguration, eventTypeProvider, loggerFactory, snapshotStore, snapshotStrategy);

                return(multipleStreamsCatchupCache);
            });

            if (null != _eventStoreActorConfiguration)
            {
                throw new InvalidOperationException("A cache as already been registered - only one cache allowed");
            }

            _eventStoreActorConfiguration = new EventStoreActorConfiguration <TAggregate>(_actorConfiguration, getSubscribeFromEndMultipleStreamsEventStoreCache);

            return(this);
        }
Ejemplo n.º 3
0
        public EventStoreStatefulActorBuilder <TActor, TAggregate> WithReadAllFromEndCache(
            IEventTypeProvider <TAggregate> eventTypeProvider = null,
            Action <AllStreamsCatchupCacheConfiguration <TAggregate> > volatileCacheConfigurationBuilder = null)
        {
            var getSubscribeFromEndEventStoreCache = new Func <IConnectionStatusMonitor <IEventStoreConnection>, ILoggerFactory, ISnapshotStore <TAggregate>, ISnapshotStrategy, IAggregateCache <TAggregate> >((connectionMonitor, loggerFactory, snapshotStore, snapshotStrategy) =>
            {
                var subscribeFromEndCacheConfiguration = new AllStreamsCatchupCacheConfiguration <TAggregate>(Position.End)
                {
                    CrashAppIfSubscriptionFail = _actorConfiguration.CrashAppOnError
                };

                volatileCacheConfigurationBuilder?.Invoke(subscribeFromEndCacheConfiguration);

                var eventProvider = eventTypeProvider ?? new ConsumerBasedEventProvider <TAggregate, TActor>();

                var subscribeFromEndEventStoreCache = new AllStreamsCatchupCache <TAggregate>(connectionMonitor,
                                                                                              subscribeFromEndCacheConfiguration,
                                                                                              eventProvider, loggerFactory);

                return(subscribeFromEndEventStoreCache);
            });

            if (null != _eventStoreActorConfiguration)
            {
                throw new InvalidOperationException("A cache as already been registered - only one cache allowed");
            }

            _eventStoreActorConfiguration = new EventStoreActorConfiguration <TAggregate>(_actorConfiguration, getSubscribeFromEndEventStoreCache);


            return(this);
        }
 public SingleStreamCatchupCache(IConnectionStatusMonitor <IEventStoreConnection> connectionMonitor,
                                 SingleStreamCatchupCacheConfiguration <TAggregate> cacheConfiguration,
                                 IEventTypeProvider <TAggregate> eventTypeProvider,
                                 ILoggerFactory loggerFactory,
                                 ISnapshotStore <TAggregate>?snapshotStore = null,
                                 ISnapshotStrategy?snapshotStrategy        = null) : base(connectionMonitor, cacheConfiguration, eventTypeProvider, loggerFactory, snapshotStore, snapshotStrategy)
 {
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 默认构造函数
 /// </summary>
 public AggregateRoot()
 {
     _sourcableEvents   = new Queue <SourcableEvent>();
     _notifyEvents      = new Queue <object>();
     _originalVersion   = DefaultVersion;
     _logger            = ObjectContainer.Resolve <ILoggerFactory>().Create("EventSourcing.AggregateRoot");
     _callbackProvider  = ObjectContainer.Resolve <IAggregateRootInternalHandlerProvider>();
     _eventTypeProvider = ObjectContainer.Resolve <IEventTypeProvider>();
 }
 public EventStoreStatefulActorBuilder <TActor, TAggregate, TRegistry> WithReadOneStreamFromStartCache(
     string streamId,
     IEventTypeProvider <TAggregate> eventTypeProvider,
     Action <MultipleStreamsCatchupCacheConfiguration <TAggregate> > getMultipleStreamsCatchupCacheConfiguration = null,
     ISnapshotStore <TAggregate> snapshotStore = null,
     ISnapshotStrategy snapshotStrategy        = null)
 {
     return(WithReadManyStreamsFromStartCache(new[] { streamId }, eventTypeProvider, getMultipleStreamsCatchupCacheConfiguration, snapshotStore, snapshotStrategy));
 }
Ejemplo n.º 7
0
 public SubscribeFromEndToAllEventStoreStream(
     IConnectionStatusMonitor <IEventStoreConnection> connectionMonitor,
     SubscribeFromEndEventStoreStreamConfiguration volatileEventStoreStreamConfiguration,
     IEventTypeProvider eventTypeProvider,
     ILoggerFactory?loggerFactory = null,
     IKillSwitch?killSwitch       = null)
     : base(connectionMonitor, volatileEventStoreStreamConfiguration, eventTypeProvider, loggerFactory?.CreateLogger <SubscribeFromEndToAllEventStoreStream>())
 {
     _volatileEventStoreStreamConfiguration = volatileEventStoreStreamConfiguration;
     _killSwitch = killSwitch ?? new KillSwitch();
 }
Ejemplo n.º 8
0
 public EventDispatcher(
     ILogger <EventDispatcher> logger,
     IHandlerImplementationProvider serviceProvider,
     IEventTypeProvider typeProvider,
     IInvokerProvider invokerProvider)
 {
     _logger          = logger;
     _serviceProvider = serviceProvider;
     _typeProvider    = typeProvider;
     _invokerProvider = invokerProvider;
 }
 public PersistentSubscriptionEventStoreStream(IConnectionStatusMonitor <IEventStoreConnection> connectionMonitor,
                                               PersistentSubscriptionEventStoreStreamConfiguration persistentEventStoreStreamConfiguration,
                                               IEventTypeProvider eventTypeProvider,
                                               ILoggerFactory?loggerFactory = null,
                                               IKillSwitch?killSwitch       = null) : base(connectionMonitor,
                                                                                           persistentEventStoreStreamConfiguration,
                                                                                           eventTypeProvider,
                                                                                           loggerFactory?.CreateLogger <PersistentSubscriptionEventStoreStream>())
 {
     _persistentEventStoreStreamConfiguration = persistentEventStoreStreamConfiguration;
     _killSwitch = killSwitch ?? new KillSwitch();
 }
 public BaseSubscribeToOneStreamEventStoreStream(
     int streamPosition,
     IConnectionStatusMonitor <IEventStoreConnection> connectionMonitor,
     SubscribeToOneStreamFromStartOrLaterEventStoreStreamConfiguration subscribeToOneStreamEventStoreStreamConfiguration,
     IEventTypeProvider eventTypeProvider,
     Microsoft.Extensions.Logging.ILogger?logger = null,
     IKillSwitch?killSwitch = null)
     : base(connectionMonitor, subscribeToOneStreamEventStoreStreamConfiguration, eventTypeProvider, logger)
 {
     _volatileSubscribeToOneStreamEventStoreStreamConfiguration = subscribeToOneStreamEventStoreStreamConfiguration;
     _streamPosition = streamPosition;
     _killSwitch     = killSwitch ?? new KillSwitch();
 }
Ejemplo n.º 11
0
        public QuikJsonSerializer(
            IResultTypeProvider resultTypeProvider,
            IEventTypeProvider eventTypeProvider)
        {
            _resultTypeProvider = resultTypeProvider;
            _eventTypeProvider  = eventTypeProvider;

            _serializer = new JsonSerializer
            {
                Culture           = CultureInfo.InvariantCulture,
                TypeNameHandling  = TypeNameHandling.None,
                NullValueHandling = NullValueHandling.Ignore
            };
        }
Ejemplo n.º 12
0
        public CosmosEventSerializer(IEventTypeProvider typeProvider)
        {
            jsonSerializerOptions = new JsonSerializerOptions
            {
                DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
                WriteIndented          = true,
                PropertyNamingPolicy   = JsonNamingPolicy.CamelCase,
            };

            jsonSerializerOptions.Converters.Add(new EventDocumentConverter(typeProvider));
            jsonSerializerOptions.Converters.Add(new TimeSpanConverter());
            jsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
            jsonSerializerOptions.Converters.Add(new StreamIdConverter());
            jsonSerializerOptions.Converters.Add(new StreamVersionConverter());
        }
Ejemplo n.º 13
0
        public BaseEventStoreStream(IConnectionStatusMonitor <IEventStoreConnection> connectionMonitor,
                                    IEventStoreStreamConfiguration cacheConfiguration,
                                    IEventTypeProvider eventTypeProvider,
                                    ILogger?logger = null)
        {
            Logger = logger;

            Id = $"{GetType()}-{Guid.NewGuid()}";

            _eventStoreStreamConfiguration = cacheConfiguration;
            _eventTypeProvider             = eventTypeProvider;
            _connectionMonitor             = connectionMonitor;

            _onMessageSubject = new Subject <IMessage>();
        }
        public async Task <TAggregate> GetById <TAggregate>(string streamId, IEventTypeProvider eventTypeProvider, bool loadEvents = false)
            where TAggregate : class, IAggregate, new()
        {
            if (!IsConnected)
            {
                throw new InvalidOperationException("Client is not connected to EventStore");
            }

            var aggregate = new TAggregate();

            aggregate.SetEntityId(streamId);

            var eventNumber = 0L;

            StreamEventsSlice currentSlice;

            do
            {
                currentSlice = await _eventStoreConnection.ReadStreamEventsForwardAsync(streamId, eventNumber, _eventStoreRepositoryConfiguration.ReadPageSize, false, _eventStoreRepositoryConfiguration.UserCredentials);

                if (currentSlice.Status == SliceReadStatus.StreamNotFound)
                {
                    throw new InvalidOperationException($"Unable to find stream {streamId}");
                }

                if (currentSlice.Status == SliceReadStatus.StreamDeleted)
                {
                    throw new InvalidOperationException($"Stream {streamId} was deleted");
                }

                eventNumber = currentSlice.NextEventNumber;

                foreach (var resolvedEvent in currentSlice.Events)
                {
                    var @event = DeserializeEvent <TAggregate>(resolvedEvent.Event, eventTypeProvider, false);

                    if (null == @event)
                    {
                        continue;
                    }

                    aggregate.ApplyEvent(@event, false, loadEvents);
                }
            } while (!currentSlice.IsEndOfStream);

            return(aggregate);
        }
        public EventStoreStatefulActorBuilder <TActor, TAggregate, TRegistry> WithReadAllFromEndCache(
            IEventTypeProvider <TAggregate> eventTypeProvider,
            Action <AllStreamsCatchupCacheConfiguration <TAggregate> > getSubscribeFromEndCacheConfiguration = null)
        {
            if (null != EventStoreCache)
            {
                throw new InvalidOperationException($"A cache has already been set => {EventStoreCache.GetType()}");
            }

            var subscribeFromEndCacheConfiguration = new AllStreamsCatchupCacheConfiguration <TAggregate>(Position.End);

            getSubscribeFromEndCacheConfiguration?.Invoke(subscribeFromEndCacheConfiguration);

            EventStoreCache = new AllStreamsCatchupCache <TAggregate>(ConnectionMonitor, subscribeFromEndCacheConfiguration, eventTypeProvider, LoggerFactory);

            return(this);
        }
        public EventStoreStatefulActorBuilder <TActor, TAggregate, TRegistry> WithReadAllFromStartCache(
            IEventTypeProvider <TAggregate> eventTypeProvider,
            Action <AllStreamsCatchupCacheConfiguration <TAggregate> > getCatchupEventStoreCacheConfigurationBuilder = null,
            ISnapshotStore <TAggregate> snapshotStore = null,
            ISnapshotStrategy snapshotStrategy        = null)
        {
            if (null != EventStoreCache)
            {
                throw new InvalidOperationException($"A cache has already been set => {EventStoreCache.GetType()}");
            }

            var catchupEventStoreCacheConfiguration = new AllStreamsCatchupCacheConfiguration <TAggregate>(Position.Start);

            getCatchupEventStoreCacheConfigurationBuilder?.Invoke(catchupEventStoreCacheConfiguration);

            EventStoreCache = new AllStreamsCatchupCache <TAggregate>(ConnectionMonitor, catchupEventStoreCacheConfiguration, eventTypeProvider, LoggerFactory, snapshotStore, snapshotStrategy);

            return(this);
        }
        public EventStoreStatefulActorBuilder <TActor, TAggregate, TRegistry> WithReadManyStreamsFromStartCache(
            string[] streamIds,
            IEventTypeProvider <TAggregate> eventTypeProvider,
            Action <MultipleStreamsCatchupCacheConfiguration <TAggregate> > getMultipleStreamsCatchupCacheConfiguration = null,
            ISnapshotStore <TAggregate> snapshotStore = null,
            ISnapshotStrategy snapshotStrategy        = null)
        {
            if (null != EventStoreCache)
            {
                throw new InvalidOperationException($"A cache has already been set => {EventStoreCache.GetType()}");
            }

            var multipleStreamsCatchupCacheConfiguration = new MultipleStreamsCatchupCacheConfiguration <TAggregate>(streamIds);

            getMultipleStreamsCatchupCacheConfiguration?.Invoke(multipleStreamsCatchupCacheConfiguration);

            EventStoreCache = new MultipleStreamsCatchupCache <TAggregate>(ConnectionMonitor, multipleStreamsCatchupCacheConfiguration, eventTypeProvider, LoggerFactory, snapshotStore, snapshotStrategy);

            return(this);
        }
        public void ApplyEventNamespaceBinding(IMessageTypeParser messageTypeParser, IEventTypeProvider eventTypeProvider)
        {
            var eventNamespaceMessageType = MessageType.FirstOrDefault(messageTypeParser.IsEventNamespaceType);

            if (string.IsNullOrWhiteSpace(eventNamespaceMessageType))
            {
                return;
            }

            var parsed      = messageTypeParser.Parse(eventNamespaceMessageType);
            var messageType = eventTypeProvider.GetType(parsed.Namespace, parsed.Type);

            if (messageType.HasNoValue)
            {
                return;
            }

            var messageTypes = MessageType.Where(mt => mt != eventNamespaceMessageType).ToList();

            messageTypes.Add(MessageUrn.ForType(messageType.Value).ToString());
            MessageType = messageTypes.ToArray();
        }
 public DefaultTypeNameMappingProvider(IEventTypeProvider eventTypeProvider, ISnapshotTypeProvider snapshotTypeProvider)
 {
     _eventTypeProvider = eventTypeProvider;
     _snapshotTypeProvider = snapshotTypeProvider;
     _mappings = new Dictionary<NameTypeMappingType, IDictionary<string, Type>>();
 }
        private IAggregateEvent <TAggregate>?DeserializeEvent <TAggregate>(RecordedEvent recordedEvent, IEventTypeProvider eventTypeProvider, bool throwIfNotHandled = true)
            where TAggregate : class, IAggregate
        {
            var targetType = eventTypeProvider.GetEventTypeByName(recordedEvent.EventType);

            if (null == targetType && throwIfNotHandled)
            {
                throw new InvalidOperationException($"{recordedEvent.EventType} cannot be handled");
            }
            if (null == targetType)
            {
                return(null);
            }

            return(_eventStoreRepositoryConfiguration.Serializer.DeserializeObject(recordedEvent.Data, targetType) as IAggregateEvent <TAggregate>);
        }
Ejemplo n.º 21
0
 public SubscribeFromEndToOneStreamEventStoreStream(IConnectionStatusMonitor <IEventStoreConnection> connectionMonitor, SubscribeToOneStreamFromStartOrLaterEventStoreStreamConfiguration subscribeToOneStreamEventStoreStreamConfiguration, IEventTypeProvider eventTypeProvider, ILoggerFactory?loggerFactory = null) : base(0, connectionMonitor, subscribeToOneStreamEventStoreStreamConfiguration, eventTypeProvider, loggerFactory?.CreateLogger <SubscribeFromEndToOneStreamEventStoreStream>())
 {
 }
Ejemplo n.º 22
0
 public EventDocumentConverter(IEventTypeProvider typeProvider)
 {
     this.typeProvider = typeProvider;
 }
 public EventDeserializer(IEventTypeProvider eventTypeProvider)
 {
     _eventTypeProvider = eventTypeProvider;
 }
Ejemplo n.º 24
0
 public void AddEventTypeProvider <TActor>(IEventTypeProvider eventTypeProvider)
 {
     _registry.Add(typeof(TActor), eventTypeProvider);
 }
Ejemplo n.º 25
0
        protected BaseOneOrManyStreamCatchupCache(IConnectionStatusMonitor <IEventStoreConnection> connectionMonitor, MultipleStreamsCatchupCacheConfiguration <TAggregate> catchupCacheConfiguration, IEventTypeProvider <TAggregate> eventTypeProvider, ILoggerFactory loggerFactory, ISnapshotStore <TAggregate>?snapshotStore = null, ISnapshotStrategy?snapshotStrategy = null) : base(connectionMonitor, catchupCacheConfiguration, eventTypeProvider, loggerFactory, snapshotStore, snapshotStrategy)
        {
            var catchupCacheSubscriptionHolders = catchupCacheConfiguration.StreamIds.Select(streamId => new CatchupCacheSubscriptionHolder <TAggregate>(streamId, catchupCacheConfiguration.CrashAppIfSubscriptionFail)).ToArray();

            Initialize(catchupCacheSubscriptionHolders);
        }
 public static IServiceCollection AddEventTypeProvider(this IServiceCollection services, IEventTypeProvider eventTypeProvider)
 {
     services.TryAddTransient <IEventTypeProvider>(_ => eventTypeProvider);
     return(services);
 }
 public DefaultTypeNameMappingProvider(IEventTypeProvider eventTypeProvider, ISnapshotTypeProvider snapshotTypeProvider)
 {
     _eventTypeProvider    = eventTypeProvider;
     _snapshotTypeProvider = snapshotTypeProvider;
     _mappings             = new Dictionary <NameTypeMappingType, IDictionary <string, Type> >();
 }
 public EventNamespaceMessageDeserializer(JsonSerializer deserializer, IEventTypeProvider eventTypeProvider, IMessageTypeParser messageTypeParser)
 {
     _deserializer      = deserializer;
     _eventTypeProvider = eventTypeProvider;
     _messageTypeParser = messageTypeParser;
 }