/// <summary> /// Create a new EventStoreDB producer instance /// </summary> /// <param name="clientSettings">EventStoreDB gRPC client settings</param> /// <param name="serializer">Optional: event serializer instance</param> /// <param name="metaSerializer">Optional: metadata serializer instance</param> public EventStoreProducer( EventStoreClientSettings clientSettings, IEventSerializer?serializer = null, IMetadataSerializer?metaSerializer = null ) : this(new EventStoreClient(Ensure.NotNull(clientSettings)), serializer, metaSerializer) { }
/// <summary> /// Creates EventStoreDB catch-up subscription service for a given stream /// </summary> /// <param name="eventStoreClient">EventStoreDB gRPC client instance</param> /// <param name="streamName">Name of the stream to receive events from</param> /// <param name="subscriptionId">Subscription ID</param> /// <param name="checkpointStore">Checkpoint store instance</param> /// <param name="eventSerializer">Event serializer instance</param> /// <param name="eventHandlers">Collection of event handlers</param> /// <param name="loggerFactory">Optional: logger factory</param> /// <param name="measure">Optional: gap measurement for metrics</param> /// <param name="throwOnError"></param> public StreamSubscription( EventStoreClient eventStoreClient, string streamName, string subscriptionId, ICheckpointStore checkpointStore, IEnumerable <IEventHandler> eventHandlers, IEventSerializer?eventSerializer = null, ILoggerFactory?loggerFactory = null, ISubscriptionGapMeasure?measure = null, bool throwOnError = false ) : this( eventStoreClient, new StreamSubscriptionOptions { StreamName = streamName, SubscriptionId = subscriptionId, ThrowOnError = throwOnError }, checkpointStore, eventHandlers, eventSerializer, loggerFactory, measure ) { }
/// <summary> /// Creates RabbitMQ subscription service instance /// </summary> /// <param name="connectionFactory"></param> /// <param name="options"></param> /// <param name="eventHandlers">Collection of event handlers</param> /// <param name="eventSerializer">Event serializer instance</param> /// <param name="loggerFactory">Optional: logging factory</param> public RabbitMqSubscriptionService( ConnectionFactory connectionFactory, RabbitMqSubscriptionOptions options, IEnumerable <IEventHandler> eventHandlers, IEventSerializer?eventSerializer = null, ILoggerFactory?loggerFactory = null ) : base( Ensure.NotNull(options, nameof(options)), new NoOpCheckpointStore(), eventHandlers, eventSerializer, loggerFactory, new NoOpGapMeasure() ) { _options = options; _failureHandler = options.FailureHandler ?? DefaultEventFailureHandler; _log = loggerFactory?.CreateLogger <RabbitMqSubscriptionService>(); _concurrencyLimit = options.ConcurrencyLimit; _connection = Ensure.NotNull(connectionFactory, nameof(connectionFactory)).CreateConnection(); _channel = _connection.CreateModel(); var prefetch = _concurrencyLimit * 10; _channel.BasicQos(0, (ushort)prefetch, false); _subscriptionQueue = Ensure.NotEmptyString(options.SubscriptionQueue, nameof(options.SubscriptionQueue)); _exchange = Ensure.NotEmptyString(options.Exchange, nameof(options.Exchange)); }
public GooglePubSubProducer( IOptions <PubSubProducerOptions> options, IEventSerializer?serializer = null, ILoggerFactory?loggerFactory = null ) : this(options.Value, serializer, loggerFactory) { }
public StreamPersistentSubscription( EventStoreClient eventStoreClient, StreamPersistentSubscriptionOptions options, IEnumerable <IEventHandler> eventHandlers, IEventSerializer?eventSerializer = null, ILoggerFactory?loggerFactory = null, ISubscriptionGapMeasure?measure = null ) : base( eventStoreClient, options, new NoOpCheckpointStore(), eventHandlers, eventSerializer, loggerFactory, measure ) { Ensure.NotEmptyString(options.Stream, nameof(options.Stream)); var settings = eventStoreClient.GetSettings().Copy(); var opSettings = settings.OperationOptions.Clone(); options.ConfigureOperation?.Invoke(opSettings); settings.OperationOptions = opSettings; _subscriptionClient = new EventStorePersistentSubscriptionsClient(settings); _handleEventProcessingFailure = options.FailureHandler ?? DefaultEventProcessingFailureHandler; _options = options; }
public KafkaBasicProducer(KafkaProducerOptions options, IEventSerializer?serializer = null) : base(TracingOptions) { _producerWithKey = new ProducerBuilder <string, byte[]>(options.ProducerConfig).Build(); _producerWithoutKey = new DependentProducerBuilder <Null, byte[]>(_producerWithKey.Handle).Build(); _serializer = serializer ?? DefaultEventSerializer.Instance; }
/// <summary> /// Creates RabbitMQ subscription service instance /// </summary> /// <param name="connectionFactory"></param> /// <param name="options"></param> /// <param name="eventHandlers">Collection of event handlers</param> /// <param name="eventSerializer">Event serializer instance</param> /// <param name="loggerFactory">Optional: logging factory</param> public RabbitMqSubscriptionService( ConnectionFactory connectionFactory, IOptions <RabbitMqSubscriptionOptions> options, IEnumerable <IEventHandler> eventHandlers, IEventSerializer?eventSerializer = null, ILoggerFactory?loggerFactory = null ) : this(connectionFactory, options.Value, eventHandlers, eventSerializer, loggerFactory) { }
/// <summary> /// Creates a RabbitMQ producer instance /// </summary> /// <param name="connectionFactory">RabbitMQ connection factory</param> /// <param name="serializer">Event serializer instance</param> /// <param name="options">Additional configuration for the exchange</param> public RabbitMqProducer( ConnectionFactory connectionFactory, IEventSerializer?serializer = null, RabbitMqExchangeOptions?options = null ) { _options = options; _serializer = serializer ?? DefaultEventSerializer.Instance; _connectionFactory = Ensure.NotNull(connectionFactory, nameof(connectionFactory)); }
/// <summary> /// Create a new instance of a Google PubSub producer /// </summary> /// <param name="options">Producer options</param> /// <param name="serializer">Optional: event serializer. Will use the default instance if missing.</param> public GooglePubSubProducer( PubSubProducerOptions options, IEventSerializer?serializer = null ) : base(TracingOptions) { Ensure.NotNull(options); _serializer = serializer ?? DefaultEventSerializer.Instance; _clientCache = new ClientCache(options); _attributes = options.Attributes; }
protected EventStoreSubscriptionService( EventStoreClient eventStoreClient, EventStoreSubscriptionOptions options, ICheckpointStore checkpointStore, IEnumerable <IEventHandler> eventHandlers, IEventSerializer?eventSerializer = null, ILoggerFactory?loggerFactory = null, ISubscriptionGapMeasure?measure = null ) : base(options, checkpointStore, eventHandlers, eventSerializer, loggerFactory, measure) { EventStoreClient = Ensure.NotNull(eventStoreClient, nameof(eventStoreClient)); }
public EsdbEventStore( EventStoreClient client, IEventSerializer?serializer = null, IMetadataSerializer?metaSerializer = null, ILogger <EsdbEventStore>?logger = null ) { _logger = logger; _client = Ensure.NotNull(client); _serializer = serializer ?? DefaultEventSerializer.Instance; _metaSerializer = metaSerializer ?? DefaultMetadataSerializer.Instance; }
/// <summary> /// Create a new instance of a Google PubSub producer /// </summary> /// <param name="options">Producer options</param> /// <param name="serializer">Optional: event serializer. Will use the default instance if missing.</param> /// <param name="loggerFactory">Logger factory</param> public GooglePubSubProducer( PubSubProducerOptions options, IEventSerializer?serializer = null, ILoggerFactory?loggerFactory = null ) { Ensure.NotNull(options, nameof(options)); _serializer = serializer ?? DefaultEventSerializer.Instance; _log = loggerFactory?.CreateLogger($"Producer:{options.ProjectId}"); _clientCache = new ClientCache(options, _log); }
/// <summary> /// Create a new EventStoreDB producer instance /// </summary> /// <param name="eventStoreClient">EventStoreDB gRPC client</param> /// <param name="serializer">Optional: event serializer instance</param> /// <param name="metaSerializer">Optional: metadata serializer instance</param> public EventStoreProducer( EventStoreClient eventStoreClient, IEventSerializer?serializer = null, IMetadataSerializer?metaSerializer = null ) : base(TracingOptions) { _client = Ensure.NotNull(eventStoreClient); _serializer = serializer ?? DefaultEventSerializer.Instance; _metaSerializer = metaSerializer ?? DefaultMetadataSerializer.Instance; ReadyNow(); }
public TransactionalAllStreamSubscriptionService( EventStoreClient eventStoreClient, EventStoreSubscriptionOptions options, ICheckpointStore checkpointStore, IEnumerable <IEventHandler> eventHandlers, IEventSerializer?eventSerializer = null, ILoggerFactory?loggerFactory = null, ISubscriptionGapMeasure?measure = null) : base(eventStoreClient, options, checkpointStore, eventHandlers, eventSerializer, loggerFactory, measure) { _log = loggerFactory.CreateLogger(GetType()); }
public EsdbEventStore( EventStoreClientSettings clientSettings, IEventSerializer?serializer = null, IMetadataSerializer?metaSerializer = null, ILogger <EsdbEventStore>?logger = null ) : this( new EventStoreClient(Ensure.NotNull(clientSettings)), serializer, metaSerializer, logger ) { }
/// <summary> /// Creates EventStoreDB catch-up subscription service for a given stream /// </summary> /// <param name="client"></param> /// <param name="checkpointStore">Checkpoint store instance</param> /// <param name="eventSerializer">Event serializer instance</param> /// <param name="eventHandlers">Collection of event handlers</param> /// <param name="options">Subscription options</param> /// <param name="loggerFactory">Optional: logger factory</param> /// <param name="measure">Optional: gap measurement for metrics</param> public StreamSubscription( EventStoreClient client, StreamSubscriptionOptions options, ICheckpointStore checkpointStore, IEnumerable <IEventHandler> eventHandlers, IEventSerializer?eventSerializer = null, ILoggerFactory?loggerFactory = null, ISubscriptionGapMeasure?measure = null ) : base(client, options, checkpointStore, eventHandlers, eventSerializer, loggerFactory, measure) { Ensure.NotEmptyString(options.StreamName, nameof(options.StreamName)); _options = options; }
/// <summary> /// Create a new instance of a Google PubSub producer /// </summary> /// <param name="projectId">GCP project ID</param> /// <param name="serializer">Event serializer instance</param> /// <param name="settings"></param> /// <param name="clientCreationSettings"></param> public GooglePubSubProducer( string projectId, IEventSerializer?serializer = null, ClientCreationSettings?clientCreationSettings = null, Settings?settings = null ) : this( new PubSubProducerOptions { ProjectId = Ensure.NotEmptyString(projectId), Settings = settings, ClientCreationSettings = clientCreationSettings }, serializer ) { }
/// <summary> /// Creates RabbitMQ subscription service instance /// </summary> /// <param name="connectionFactory">RabbitMQ connection factory</param> /// <param name="exchange">Exchange to consume events from, the queue will get bound to this exchange</param> /// <param name="subscriptionId">Subscription ID</param> /// <param name="consumePipe"></param> /// <param name="eventSerializer">Event serializer instance</param> public RabbitMqSubscription( ConnectionFactory connectionFactory, string exchange, string subscriptionId, ConsumePipe consumePipe, IEventSerializer?eventSerializer = null ) : this( connectionFactory, new RabbitMqSubscriptionOptions { Exchange = exchange, SubscriptionId = subscriptionId, EventSerializer = eventSerializer }, consumePipe ) { }
/// <summary> /// Creates EventStoreDB persistent subscription service for a given stream /// </summary> /// <param name="eventStoreClient">EventStoreDB gRPC client instance</param> /// <param name="subscriptionId">Subscription ID</param> /// <param name="consumerPipe"></param> /// <param name="eventSerializer">Event serializer instance</param> /// <param name="metaSerializer"></param> public AllPersistentSubscription( EventStoreClient eventStoreClient, string subscriptionId, ConsumePipe consumerPipe, IEventSerializer?eventSerializer = null, IMetadataSerializer?metaSerializer = null ) : this( eventStoreClient, new AllPersistentSubscriptionOptions { SubscriptionId = subscriptionId, EventSerializer = eventSerializer, MetadataSerializer = metaSerializer }, consumerPipe ) { }
/// <summary> /// Creates a Google PubSub subscription service /// </summary> /// <param name="projectId">GCP project ID</param> /// <param name="topicId"></param> /// <param name="subscriptionId">Google PubSub subscription ID (within the project), which must already exist</param> /// <param name="consumePipe"></param> /// <param name="eventSerializer">Event serializer instance</param> public GooglePubSubSubscription( string projectId, string topicId, string subscriptionId, ConsumePipe consumePipe, IEventSerializer?eventSerializer = null ) : this( new PubSubSubscriptionOptions { SubscriptionId = subscriptionId, ProjectId = projectId, TopicId = topicId, EventSerializer = eventSerializer }, consumePipe ) { }
/// <summary> /// Creates a Google PubSub subscription service /// </summary> /// <param name="options">Subscription options <see cref="PubSubSubscriptionOptions"/></param> /// <param name="eventHandlers">Collection of event handlers</param> /// <param name="eventSerializer">Event serializer instance</param> /// <param name="loggerFactory">Optional: logger factory</param> /// <param name="measure">Callback for measuring the subscription gap</param> public GooglePubSubSubscription( PubSubSubscriptionOptions options, IEnumerable <IEventHandler> eventHandlers, IEventSerializer?eventSerializer = null, ILoggerFactory?loggerFactory = null, ISubscriptionGapMeasure?measure = null ) : base( options, new NoOpCheckpointStore(), eventHandlers, eventSerializer ?? DefaultEventSerializer.Instance, loggerFactory, measure ) { _failureHandler = Ensure.NotNull(options, nameof(options)).FailureHandler ?? DefaultEventProcessingErrorHandler; _subscriptionName = SubscriptionName.FromProjectSubscription( Ensure.NotEmptyString(options.ProjectId, nameof(options.ProjectId)), Ensure.NotEmptyString(options.SubscriptionId, nameof(options.SubscriptionId)) ); _topicName = TopicName.FromProjectTopic( options.ProjectId, Ensure.NotEmptyString(options.TopicId, nameof(options.TopicId)) ); _undeliveredCountRequest = GetFilteredRequest(PubSubMetricUndeliveredMessagesCount); _oldestAgeRequest = GetFilteredRequest(PubSubMetricOldestUnackedMessageAge); ListTimeSeriesRequest GetFilteredRequest(string metric) => new() { Name = $"projects/{options.ProjectId}", Filter = $"metric.type = \"pubsub.googleapis.com/subscription/{metric}\" " + $"AND resource.label.subscription_id = \"{options.SubscriptionId}\"" }; } Task _subscriberTask = null !;
/// <summary> /// Creates EventStoreDB catch-up subscription service for $all /// </summary> /// <param name="eventStoreClient">EventStoreDB gRPC client instance</param> /// <param name="subscriptionId">Subscription ID</param> /// <param name="checkpointStore">Checkpoint store instance</param> /// <param name="consumePipe"></param> /// <param name="eventSerializer">Event serializer instance</param> /// <param name="metaSerializer"></param> /// <param name="eventFilter">Optional: server-side event filter</param> public AllStreamSubscription( EventStoreClient eventStoreClient, string subscriptionId, ICheckpointStore checkpointStore, ConsumePipe consumePipe, IEventSerializer?eventSerializer = null, IMetadataSerializer?metaSerializer = null, IEventFilter?eventFilter = null ) : this( eventStoreClient, new AllStreamSubscriptionOptions { SubscriptionId = subscriptionId, EventSerializer = eventSerializer, MetadataSerializer = metaSerializer, EventFilter = eventFilter }, checkpointStore, consumePipe ) { }
/// <summary> /// Creates EventStoreDB persistent subscription service for a given stream /// </summary> /// <param name="eventStoreClient">EventStoreDB gRPC client instance</param> /// <param name="streamName">Name of the stream to receive events from</param> /// <param name="subscriptionId">Subscription ID</param> /// <param name="eventSerializer">Event serializer instance</param> /// <param name="eventHandlers">Collection of event handlers</param> /// <param name="loggerFactory">Optional: logger factory</param> /// <param name="measure">Optional: gap measurement for metrics</param> public StreamPersistentSubscription( EventStoreClient eventStoreClient, string streamName, string subscriptionId, IEnumerable <IEventHandler> eventHandlers, IEventSerializer?eventSerializer = null, ILoggerFactory?loggerFactory = null, ISubscriptionGapMeasure?measure = null ) : this( eventStoreClient, new StreamPersistentSubscriptionOptions { Stream = streamName, SubscriptionId = subscriptionId }, eventHandlers, eventSerializer, loggerFactory, measure ) { }
/// <summary> /// Creates RabbitMQ subscription service instance /// </summary> /// <param name="connectionFactory">RabbitMQ connection factory</param> /// <param name="subscriptionQueue">Subscription queue, will be created it doesn't exist</param> /// <param name="exchange">Exchange to consume events from, the queue will get bound to this exchange</param> /// <param name="subscriptionId">Subscription ID</param> /// <param name="eventSerializer">Event serializer instance</param> /// <param name="eventHandlers">Collection of event handlers</param> /// <param name="loggerFactory">Optional: logging factory</param> public RabbitMqSubscriptionService( ConnectionFactory connectionFactory, string subscriptionQueue, string exchange, string subscriptionId, IEnumerable <IEventHandler> eventHandlers, IEventSerializer?eventSerializer = null, ILoggerFactory?loggerFactory = null ) : this( connectionFactory, new RabbitMqSubscriptionOptions { SubscriptionQueue = subscriptionQueue, Exchange = exchange, SubscriptionId = subscriptionId }, eventHandlers, eventSerializer, loggerFactory ) { }
/// <summary> /// Creates a Google PubSub subscription service /// </summary> /// <param name="projectId">GCP project ID</param> /// <param name="topicId"></param> /// <param name="subscriptionId">Google PubSub subscription ID (within the project), which must already exist</param> /// <param name="eventHandlers">Collection of event handlers</param> /// <param name="eventSerializer">Event serializer instance</param> /// <param name="loggerFactory">Optional: logger factory</param> /// <param name="measure">Callback for measuring the subscription gap</param> public GooglePubSubSubscription( string projectId, string topicId, string subscriptionId, IEnumerable <IEventHandler> eventHandlers, IEventSerializer?eventSerializer = null, ILoggerFactory?loggerFactory = null, ISubscriptionGapMeasure?measure = null ) : this( new PubSubSubscriptionOptions { SubscriptionId = subscriptionId, ProjectId = projectId, TopicId = topicId }, eventHandlers, eventSerializer, loggerFactory, measure ) { }
/// <summary> /// Creates EventStoreDB catch-up subscription service for $all /// </summary> /// <param name="eventStoreClient"></param> /// <param name="options"></param> /// <param name="checkpointStore">Checkpoint store instance</param> /// <param name="eventSerializer">Event serializer instance</param> /// <param name="eventHandlers">Collection of event handlers</param> /// <param name="loggerFactory">Optional: logger factory</param> /// <param name="eventFilter">Optional: server-side event filter</param> /// <param name="measure">Optional: gap measurement for metrics</param> public AllStreamSubscription( EventStoreClient eventStoreClient, AllStreamSubscriptionOptions options, ICheckpointStore checkpointStore, IEnumerable <IEventHandler> eventHandlers, IEventSerializer?eventSerializer = null, ILoggerFactory?loggerFactory = null, IEventFilter?eventFilter = null, ISubscriptionGapMeasure?measure = null ) : base( eventStoreClient, options, checkpointStore, eventHandlers, eventSerializer, loggerFactory, measure ) { _eventFilter = eventFilter ?? EventTypeFilter.ExcludeSystemEvents(); _options = options; }
protected SubscriptionService( SubscriptionOptions options, ICheckpointStore checkpointStore, IEnumerable <IEventHandler> eventHandlers, IEventSerializer?eventSerializer = null, ILoggerFactory?loggerFactory = null, ISubscriptionGapMeasure?measure = null ) { _checkpointStore = Ensure.NotNull(checkpointStore, nameof(checkpointStore)); _eventSerializer = eventSerializer ?? DefaultEventSerializer.Instance; SubscriptionId = Ensure.NotEmptyString(options.SubscriptionId, options.SubscriptionId); _measure = measure; _throwOnError = options.ThrowOnError; _eventHandlers = Ensure.NotNull(eventHandlers, nameof(eventHandlers)) .Where(x => x.SubscriptionId == options.SubscriptionId) .ToArray(); Log = loggerFactory?.CreateLogger($"StreamSubscription-{options.SubscriptionId}"); DebugLog = Log?.IsEnabled(LogLevel.Debug) == true ? Log.LogDebug : null; }
/// <summary> /// Creates EventStoreDB catch-up subscription service for $all /// </summary> /// <param name="eventStoreClient">EventStoreDB gRPC client instance</param> /// <param name="subscriptionId">Subscription ID</param> /// <param name="checkpointStore">Checkpoint store instance</param> /// <param name="eventSerializer">Event serializer instance</param> /// <param name="eventHandlers">Collection of event handlers</param> /// <param name="loggerFactory">Optional: logger factory</param> /// <param name="eventFilter">Optional: server-side event filter</param> /// <param name="measure">Optional: gap measurement for metrics</param> public AllStreamSubscription( EventStoreClient eventStoreClient, string subscriptionId, ICheckpointStore checkpointStore, IEnumerable <IEventHandler> eventHandlers, IEventSerializer?eventSerializer = null, ILoggerFactory?loggerFactory = null, IEventFilter?eventFilter = null, ISubscriptionGapMeasure?measure = null ) : this( eventStoreClient, new AllStreamSubscriptionOptions { SubscriptionId = subscriptionId }, checkpointStore, eventHandlers, eventSerializer, loggerFactory, eventFilter, measure ) { }
/// <summary> /// Creates EventStoreDB catch-up subscription service for a given stream /// </summary> /// <param name="eventStoreClient">EventStoreDB gRPC client instance</param> /// <param name="streamName">Name of the stream to receive events from</param> /// <param name="subscriptionId">Subscription ID</param> /// <param name="checkpointStore">Checkpoint store instance</param> /// <param name="consumerPipe"></param> /// <param name="eventSerializer">Event serializer instance</param> /// <param name="metaSerializer"></param> /// <param name="throwOnError"></param> public StreamSubscription( EventStoreClient eventStoreClient, StreamName streamName, string subscriptionId, ICheckpointStore checkpointStore, ConsumePipe consumerPipe, IEventSerializer?eventSerializer = null, IMetadataSerializer?metaSerializer = null, bool throwOnError = false ) : this( eventStoreClient, new StreamSubscriptionOptions { StreamName = streamName, SubscriptionId = subscriptionId, ThrowOnError = throwOnError, EventSerializer = eventSerializer, MetadataSerializer = metaSerializer }, checkpointStore, consumerPipe ) { }
public void Setup() { if (Complexity == "Simple") { _ev = TestData.SimpleEventInstance(); } else { _ev = TestData.ComplexEventInstance(); } // BTDB Setup _eventSerializer = new EventSerializer(); _eventDeserializer = new EventDeserializer(); var meta = _eventSerializer.Serialize(out _, _ev).ToAsyncSafe(); _eventSerializer.ProcessMetadataLog(meta); _eventDeserializer.ProcessMetadataLog(meta); _btdbSerializedData = _eventSerializer.Serialize(out _, _ev).ToAsyncSafe(); BtdbByteSize = _btdbSerializedData.Length; _eventDeserializer.Deserialize(out object 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(); }