#pragma warning disable 8618
        public EventConsumer(
            IEventDeserializer eventDeserializer,
            EventConsumerConfig config,
            ILogger <EventConsumer <TAggregate, TAggregateId, TDeserializer> > logger)
        {
            _eventDeserializer = eventDeserializer;
            _logger            = logger;

            var aggregateType = typeof(TAggregate);

            var consumerConfig = new ConsumerConfig
            {
                GroupId            = config.ConsumerGroup,
                BootstrapServers   = config.KafkaConnectionString,
                AutoOffsetReset    = AutoOffsetReset.Earliest,
                EnablePartitionEof = true
            };

            var consumerBuilder        = new ConsumerBuilder <TAggregateId, string>(consumerConfig);
            var keyDeserializerFactory = new KeyDeserializerFactory();

            consumerBuilder.SetKeyDeserializer(keyDeserializerFactory.Create <TDeserializer, TAggregateId>());

            _eventConsumer = consumerBuilder.Build();

            var topicName = $"{config.TopicBaseName}-{aggregateType.Name}";

            _eventConsumer.Subscribe(topicName);
        }
Exemple #2
0
        public EventConsumer(IConfiguration configuration, IEventDeserializer eventDeserializer)
        {
            _eventDeserializer = eventDeserializer;

            string topicPrefix = configuration.GetSection("Kafka")
                                 .GetValue <string>("TopicPrefix");
            Type aggregateType = typeof(TA);

            string topicName = $"{topicPrefix}-{aggregateType.Name}";

            ConsumerConfig consumerConfig = new ConsumerConfig
            {
                GroupId = configuration.GetSection("Kafka")
                          .GetValue <string>("ConsumerGroupId"),
                BootstrapServers = configuration.GetSection("Kafka")
                                   .GetValue <string>("BootstrapServers"),
                AutoOffsetReset    = AutoOffsetReset.Earliest,
                EnablePartitionEof = true
            };

            _consumer = new ConsumerBuilder <TKey, string>(consumerConfig)
                        .SetKeyDeserializer(new KeyDeserializerFactory().Create <TKey>())
                        .Build();

            _consumer.Subscribe(topicName);
        }
Exemple #3
0
 public KnownSerializers(IEventSerializer eventSerializer, IEventDeserializer eventDeserializer,
                         ISnapshotSerializer snapshotSerializer, ISnapshotDeserializer snapshotDeserializer)
 {
     Events    = new SerializationPair <IEventSerializer, IEventDeserializer>(eventSerializer, eventDeserializer);
     Snapshots = new SerializationPair <ISnapshotSerializer, ISnapshotDeserializer>(snapshotSerializer,
                                                                                    snapshotDeserializer);
 }
        public RedisProjectionWriter(IRedisCache cache,
                                     ILogger <RedisProjectionWriter <TView> > logger,
                                     IEventSerializer eventSerializer,
                                     IEventDeserializer eventDeserializer)
        {
            if (cache == null)
            {
                throw new ArgumentNullException(nameof(cache));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (eventSerializer == null)
            {
                throw new ArgumentNullException(nameof(eventSerializer));
            }
            if (eventDeserializer == null)
            {
                throw new ArgumentNullException(nameof(eventDeserializer));
            }

            _cache           = cache;
            _logger          = logger;
            _eventSerializer = eventSerializer;
            _keyPrefix       = typeof(TView).Name;
        }
        public EventRepository(IEventStoreWrapper eventStore, IEventDeserializer eventDeserializer)
        {
            _eventStore        = eventStore;
            _eventDeserializer = eventDeserializer;
            var aggregateType = typeof(Item);

            _streamBaseName = aggregateType.Name;
        }
 public TestEventStore(IKnownSerializers serializers)
 {
     _eventSerializer   = serializers.Events.Serializer;
     _eventDeserializer = serializers.Events.Deserializer;
     _streams           = new Dictionary <string, IReadOnlyList <SerializedEvent> >();
     _streamPositions   = new Dictionary <string, int>();
     ExpectedVersion    = new ExpectedVersion(-1, -2, -3);
 }
 public EventStoreSubscriber(IEventStoreConnection openConnection, ITypeResolver typeResolver, IEventDeserializer deserializer)
 {
     _connection           = openConnection;
     _typeResolver         = typeResolver;
     _deserializer         = deserializer;
     _subscribedEventTypes = new ConcurrentBag <Type>();
     _eventProcessors      = new ConcurrentBag <IEventProcessor>();
 }
Exemple #8
0
 public SnapshotReaderCosmosDB(
     ICosmosDBClient cosmosDbClient,
     ICosmosDBConfigurations cosmosDBConfigurations,
     IEventDeserializer deserializer)
 {
     _cosmosDbClient         = cosmosDbClient ?? throw new ArgumentNullException(nameof(cosmosDbClient));
     _cosmosDBConfigurations = cosmosDBConfigurations ?? throw new ArgumentNullException(nameof(cosmosDBConfigurations));
     _deserializer           = deserializer ?? throw new ArgumentNullException(nameof(deserializer));
 }
Exemple #9
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="EventReaderConfiguration" /> class.
 /// </summary>
 /// <param name="sliceSize">Size of the slice to read.</param>
 /// <param name="deserializer">The event deserializer to use.</param>
 /// <param name="streamNameResolver">The stream name resolver to use.</param>
 /// <param name="streamUserCredentialsResolver">The stream user credentials resolver to use.</param>
 /// <exception cref="System.ArgumentNullException">
 ///     Thrown when the <paramref name="deserializer" /> or
 ///     <paramref name="streamNameResolver" /> is <c>null</c>.
 /// </exception>
 public EventReaderConfiguration(SliceSize sliceSize, IEventDeserializer deserializer,
                                 IStreamNameResolver streamNameResolver,
                                 IStreamUserCredentialsResolver streamUserCredentialsResolver)
 {
     SliceSize                     = sliceSize;
     Deserializer                  = deserializer ?? throw new ArgumentNullException(nameof(deserializer));
     StreamNameResolver            = streamNameResolver ?? throw new ArgumentNullException(nameof(streamNameResolver));
     StreamUserCredentialsResolver = streamUserCredentialsResolver ?? throw new ArgumentNullException(nameof(streamUserCredentialsResolver));
 }
Exemple #10
0
        public EventsRepository(IEventStoreConnectionWrapper connectionWrapper, IEventDeserializer eventDeserializer)
        {
            _connectionWrapper = connectionWrapper;
            _eventDeserializer = eventDeserializer;

            var aggregateType = typeof(TAggregate);

            _streamBaseName = aggregateType.Name;
        }
        public DefaultMessageFactory(IEventSerializer eventSerializer, IEventDeserializer eventDeserializer)
        {
            if (eventSerializer == null)
            {
                throw new ArgumentNullException(nameof(eventSerializer));
            }

            _eventSerializer   = eventSerializer;
            _eventDeserializer = eventDeserializer;
        }
Exemple #12
0
 public EventsPublisher(EventsPublisherSettings settings,
                        IBusControl busControl,
                        IEventDeserializer eventDeserializer,
                        IServiceProvider serviceProvider)
 {
     _settings          = settings;
     _busControl        = busControl;
     _eventDeserializer = eventDeserializer;
     _serviceProvider   = serviceProvider;
 }
 public RepositoryScenarioBuilder(IStreamStore connection)
 {
     _unitOfWork                   = new UnitOfWork();
     _connection                   = connection;
     _concurrentUnitOfWork         = new ConcurrentUnitOfWork();
     _eventStoreSchedule           = new List <Action <IStreamStore> >();
     _unitOfWorkSchedule           = new List <Action <UnitOfWork> >();
     _concurrentUnitOfWorkSchedule = new List <Action <ConcurrentUnitOfWork> >();
     _deserializer                 = new EventDeserializer();
 }
 public AsyncRepository(
     Func <TAggregateRoot> rootFactory,
     ConcurrentUnitOfWork unitOfWork,
     IStreamStore eventStore,
     IEventDeserializer deserializer)
 {
     RootFactory       = rootFactory ?? throw new ArgumentNullException(nameof(rootFactory));
     UnitOfWork        = unitOfWork ?? throw new ArgumentNullException(nameof(unitOfWork));
     EventStore        = eventStore ?? throw new ArgumentNullException(nameof(eventStore));
     EventDeserializer = deserializer ?? throw new ArgumentNullException(nameof(deserializer));
 }
Exemple #15
0
 EventReaderConfigurationBuilder(
     SliceSize sliceSize,
     IEventDeserializer deserializer,
     IStreamNameResolver streamNameResolver,
     IStreamUserCredentialsResolver streamUserCredentialsResolver)
 {
     _sliceSize                     = sliceSize;
     _deserializer                  = deserializer;
     _streamNameResolver            = streamNameResolver;
     _streamUserCredentialsResolver = streamUserCredentialsResolver;
 }
 EventReaderConfigurationBuilder(
     SliceSize sliceSize,
     IEventDeserializer deserializer,
     IStreamNameResolver streamNameResolver,
     IStreamUserCredentialsResolver streamUserCredentialsResolver)
 {
     _sliceSize = sliceSize;
     _deserializer = deserializer;
     _streamNameResolver = streamNameResolver;
     _streamUserCredentialsResolver = streamUserCredentialsResolver;
 }
        public EventsRepository(
            IEventStoreConnection eventStoreConnection,
            IEventDeserializer eventDeserializer
            )
        {
            _eventStoreConnection = eventStoreConnection;
            _eventDeserializer    = eventDeserializer;
            var aggregateType = typeof(TA);

            _streamBaseName = aggregateType.Name;
        }
Exemple #18
0
 public SubscriptionConfiguration(
     ConsumerSettings settings,
     BatchConfiguration batchConfiguration,
     IEventDeserializer serializer,
     HandlerConfiguration handlerConfig = default,
     bool skipUnknownEvents             = true,
     int consumerInstances = 1)
     : this(settings, serializer, handlerConfig, skipUnknownEvents, consumerInstances)
 {
     BatchConfiguration      = batchConfiguration;
     BatchProcessingRequired = true;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="EventReaderConfiguration"/> class.
 /// </summary>
 /// <param name="sliceSize">Size of the slice to read.</param>
 /// <param name="deserializer">The event deserializer to use.</param>
 /// <param name="streamNameResolver">The stream name resolver to use.</param>
 /// <param name="streamUserCredentialsResolver">The stream user credentials resolver to use.</param>
 /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="deserializer"/> or <paramref name="streamNameResolver"/> is <c>null</c>.</exception>
 public EventReaderConfiguration(SliceSize sliceSize, IEventDeserializer deserializer,
                                 IStreamNameResolver streamNameResolver,
                                 IStreamUserCredentialsResolver streamUserCredentialsResolver)
 {
     if (deserializer == null) throw new ArgumentNullException("deserializer");
     if (streamNameResolver == null) throw new ArgumentNullException("streamNameResolver");
     if (streamUserCredentialsResolver == null) throw new ArgumentNullException("streamUserCredentialsResolver");
     _sliceSize = sliceSize;
     _deserializer = deserializer;
     _streamNameResolver = streamNameResolver;
     _streamUserCredentialsResolver = streamUserCredentialsResolver;
 }
Exemple #20
0
 public AggregateStoreDependencies(IEventSerializer eventSerializer,
                                   IEventDeserializer eventDeserializer,
                                   ICosmosDBConnection cosmosDBConnection,
                                   ICosmosDBConfigurations cosmosDBConfigurations,
                                   IStreamNameProvider streamNameProvider)
 {
     EventSerializer        = eventSerializer;
     EventDeserializer      = eventDeserializer;
     CosmosDBConnection     = cosmosDBConnection;
     CosmosDBConfigurations = cosmosDBConfigurations;
     StreamNameProvider     = streamNameProvider;
 }
Exemple #21
0
        // EventStoreAllCatchUpSubscription _subscription;

        public SubscriptionIntegrator(IEventStoreConnection connection
                                      , ICheckpointStore checkpointStore
                                      , string subscriptionName
                                      , IOnewayAsyncMessenger <EventEnvelope> messenger
                                      , IEventDeserializer deserializer)
        {
            _connection       = connection;
            _checkpointStore  = checkpointStore;
            _subscriptionName = subscriptionName;
            _messenger        = messenger;
            _deserializer     = deserializer;
        }
 public AggregateStoreDependencies(IEventDeserializer eventDeserializer,
                                   IEventStoreConnection eventStoreConnection,
                                   IEventStoreConfigurations eventStoreConfigurations,
                                   IStreamNameProvider streamNameProvider,
                                   IEventSerializer eventSerializer)
 {
     EventDeserializer        = eventDeserializer;
     EventStoreConnection     = eventStoreConnection;
     EventStoreConfigurations = eventStoreConfigurations;
     StreamNameProvider       = streamNameProvider;
     EventSerializer          = eventSerializer;
 }
 internal SubscriptionManager(IEventStoreConnection connection,
                              ICheckpointStore checkpointStore,
                              ProjectionHandler[] projections,
                              ISnapshotter[] snapshotters,
                              IEventDeserializer eventDeserializer,
                              IEventStoreConfigurations configurations)
 {
     _connection        = connection ?? throw new ArgumentNullException(nameof(connection));
     _configurations    = configurations ?? throw new ArgumentNullException(nameof(configurations));
     _projections       = projections ?? throw new ArgumentNullException(nameof(projections));
     _snapshotters      = snapshotters ?? throw new ArgumentNullException(nameof(snapshotters));
     _checkpointStore   = checkpointStore ?? throw new ArgumentNullException(nameof(checkpointStore));
     _eventDeserializer = eventDeserializer ?? throw new ArgumentNullException(nameof(eventDeserializer));
 }
Exemple #24
0
        /// <inheritdoc cref="EventStore" />
        /// <param name="logger"></param>
        /// <param name="eventStoreLogger"></param>
        /// <param name="provider"></param>
        /// <param name="eventDeserializer"></param>
        /// <param name="eventStoreConfiguration"></param>
        public EventStore(ILogger <EventStore> logger,
                          ESLogger eventStoreLogger,
                          IServiceProvider provider,
                          IEventDeserializer eventDeserializer,
                          IOptionsMonitor <EventStoreConnectionConfiguration> eventStoreConfiguration)
        {
            _connectionLock          = new object();
            _logger                  = logger;
            _eventStoreLogger        = eventStoreLogger;
            _provider                = provider;
            _eventDeserializer       = eventDeserializer;
            _eventStoreConfiguration = eventStoreConfiguration;

            _eventStoreConfiguration.OnChange(_ => Connect(true));
        }
Exemple #25
0
        public DefaultEventContextFactory(IEventTypeCache eventTypeCache,
                                          IEventDeserializer eventDeserializer)
        {
            if (eventTypeCache == null)
            {
                throw new ArgumentNullException(nameof(eventTypeCache));
            }
            if (eventDeserializer == null)
            {
                throw new ArgumentNullException(nameof(eventDeserializer));
            }

            _eventTypeCache    = eventTypeCache;
            _eventDeserializer = eventDeserializer;
            _cache             = new ConcurrentDictionary <Type, Activator <IEventContext <IEvent> > >();
        }
Exemple #26
0
        public KafkaConsumer(
            IObserverFactory observerFactory,
            IEventDeserializer deserializer,
            ConsumerSettings settings,
            ILoggerFactory loggerFactory)
        {
            if (deserializer == null)
            {
                throw new ArgumentNullException(nameof(deserializer));
            }
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            _observerFactory = observerFactory ?? throw new ArgumentNullException(nameof(observerFactory));

            _logger = loggerFactory.CreateLogger <KafkaConsumer>();


            if (string.IsNullOrWhiteSpace(settings.Config.BootstrapServers))
            {
                throw new InvalidOperationException("Brokers not specified.");
            }

            if (string.IsNullOrEmpty(settings.Topic))
            {
                throw new InvalidOperationException("Topics not specified.");
            }

            if (string.IsNullOrEmpty(settings.Config.GroupId))
            {
                throw new InvalidOperationException("Group Id not specified.");
            }

            _consumer = new ConsumerBuilder <Guid, IStreamEvent>(settings.Config)
                        .SetKeyDeserializer(KeyDeserializer)
                        .SetValueDeserializer(new ValueObjectDeserializer(deserializer))
                        .SetErrorHandler((_, e) => _logger.LogError(
                                             $"KafkaConsumer internal error: Topic: {settings.Topic}, {e.Reason}, Fatal={e.IsFatal}," +
                                             $" IsLocal= {e.IsLocalError}, IsBroker={e.IsBrokerError}"))
                        .Build();

            _consumer.Subscribe(settings.Topic);
        }
Exemple #27
0
        public EndpointConfiguration AddSubscription(
            ConsumerSettings settings,
            IEventDeserializer serializer,
            HandlerConfiguration handlerConfig = default,
            bool skipUnknownEventTypes         = true,
            int instances = 1)
        {
            var subscription = new SubscriptionConfiguration(
                settings,
                serializer,
                handlerConfig,
                skipUnknownEventTypes,
                instances);

            _subscriptions.Add(subscription);

            return(this);
        }
 internal ProjectionManager(IEventStoreConnection connection,
                            IEventDeserializer serializer,
                            Func <TConnection> getConnection,
                            ICheckpointStore checkpointStore,
                            ProjectorDefiner[] projections,
                            ISnapshotter[] snapshotters,
                            int?maxLiveQueueSize,
                            int?readBatchSize)
 {
     _connection        = connection ?? throw new ArgumentNullException(nameof(connection));
     _serializer        = serializer ?? throw new ArgumentNullException(nameof(serializer));
     _getConnection     = getConnection;
     _projectorDefiners = projections;
     _snapshotters      = snapshotters;
     _checkpointStore   = checkpointStore;
     _maxLiveQueueSize  = maxLiveQueueSize ?? 10000;
     _readBatchSize     = readBatchSize ?? 500;
 }
Exemple #29
0
        public EndpointConfiguration AddBatchSubscription(
            ConsumerSettings settings,
            BatchConfiguration batchConfig,
            IEventDeserializer serializer,
            HandlerConfiguration handlerConfig = default,
            bool skipUnknownEventTypes         = true,
            int instances      = 1,
            bool isLongRunning = true)
        {
            var subscription = new SubscriptionConfiguration(
                isLongRunning ? settings.ToLongRunning() : settings,
                batchConfig,
                serializer,
                handlerConfig,
                skipUnknownEventTypes,
                instances);

            _subscriptions.Add(subscription);

            return(this);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="EventReaderConfiguration"/> class.
 /// </summary>
 /// <param name="sliceSize">Size of the slice to read.</param>
 /// <param name="deserializer">The event deserializer to use.</param>
 /// <param name="streamNameResolver">The stream name resolver to use.</param>
 /// <param name="streamUserCredentialsResolver">The stream user credentials resolver to use.</param>
 /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="deserializer"/> or <paramref name="streamNameResolver"/> is <c>null</c>.</exception>
 public EventReaderConfiguration(SliceSize sliceSize, IEventDeserializer deserializer,
                                 IStreamNameResolver streamNameResolver,
                                 IStreamUserCredentialsResolver streamUserCredentialsResolver)
 {
     if (deserializer == null)
     {
         throw new ArgumentNullException("deserializer");
     }
     if (streamNameResolver == null)
     {
         throw new ArgumentNullException("streamNameResolver");
     }
     if (streamUserCredentialsResolver == null)
     {
         throw new ArgumentNullException("streamUserCredentialsResolver");
     }
     _sliceSize                     = sliceSize;
     _deserializer                  = deserializer;
     _streamNameResolver            = streamNameResolver;
     _streamUserCredentialsResolver = streamUserCredentialsResolver;
 }
Exemple #31
0
        public SubscriptionConfiguration(
            ConsumerSettings settings,
            IEventDeserializer serializer,
            HandlerConfiguration handlerConfig = default,
            bool skipUnknownEvents             = true,
            int consumerInstances = 1)
        {
            if (consumerInstances < 1)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(consumerInstances),
                          consumerInstances,
                          "Instances should be >= 1.");
            }

            Settings          = settings ?? throw new ArgumentNullException(nameof(settings));
            Serializer        = serializer ?? throw new ArgumentNullException(nameof(serializer));
            SkipUnknownEvents = skipUnknownEvents;
            ConsumerInstances = consumerInstances;
            HandlerConfig     = handlerConfig ?? new HandlerConfiguration();
        }
Exemple #32
0
        public void Setup()
        {
            if (Complexity == "Simple")
            {
                _ev = TestData.SimpleEventInstance();
            }
            else
            {
                _ev = TestData.ComplexEventInstance();
            }

            // BTDB Setup
            _eventSerializer   = new EventSerializer();
            _eventDeserializer = new EventDeserializer();
            bool hasMedataData;
            var  meta = _eventSerializer.Serialize(out hasMedataData, _ev).ToAsyncSafe();

            _eventSerializer.ProcessMetadataLog(meta);
            _eventDeserializer.ProcessMetadataLog(meta);
            _btdbSerializedData = _eventSerializer.Serialize(out hasMedataData, _ev).ToAsyncSafe();
            BtdbByteSize        = _btdbSerializedData.Length;
            object obj;

            _eventDeserializer.Deserialize(out obj, _btdbSerializedData);
            obj.Should().BeEquivalentTo(_ev);

            // ProtoBuf Setup
            Serializer = ModelFactory.CreateModel();
            _eventType = typeof(Event);
            _memStream = new MemoryStream();
            Serializer.Serialize(_memStream, _ev);
            ProtoBufByteSize    = (int)_memStream.Length;
            _memStream.Position = 0;
            Serializer.Deserialize(_memStream, null, _eventType).Should().BeEquivalentTo(_ev);

            BtdbSerialization();
            BtdbDeserialization();
            ProtoBufSerialization();
            ProtoBufDeserialization();
        }
 public EventReaderConfigurationBuilder UsingDeserializer(IEventDeserializer value)
 {
     return new EventReaderConfigurationBuilder(_sliceSize, value, _streamNameResolver,
                                                _streamUserCredentialsResolver);
 }