Ejemplo n.º 1
0
        /// <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));
        }
Ejemplo n.º 2
0
        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;
        }
Ejemplo n.º 3
0
    /// <summary>
    /// Creates a Google PubSub subscription service
    /// </summary>
    /// <param name="options">Subscription options <see cref="PubSubSubscriptionOptions"/></param>
    /// <param name="consumePipe"></param>
    public GooglePubSubSubscription(PubSubSubscriptionOptions options, ConsumePipe consumePipe)
        : base(options, consumePipe)
    {
        _failureHandler = Ensure.NotNull(options).FailureHandler ?? DefaultEventProcessingErrorHandler;

        _subscriptionName = SubscriptionName.FromProjectSubscription(
            Ensure.NotEmptyString(options.ProjectId),
            Ensure.NotEmptyString(options.SubscriptionId)
            );

        _topicName = TopicName.FromProjectTopic(options.ProjectId, Ensure.NotEmptyString(options.TopicId));

        if (options.FailureHandler != null && !options.ThrowOnError)
        {
            Log.ThrowOnErrorIncompatible(SubscriptionId);
        }
    }
Ejemplo n.º 4
0
    protected PersistentSubscriptionBase(EventStoreClient eventStoreClient, T options, ConsumePipe consumePipe)
        : base(eventStoreClient, options, consumePipe)
    {
        var settings   = eventStoreClient.GetSettings().Copy();
        var opSettings = settings.OperationOptions.Clone();

        settings.OperationOptions = opSettings;

        SubscriptionClient = new EventStorePersistentSubscriptionsClient(settings);

        _handleEventProcessingFailure = options.FailureHandler ?? DefaultEventProcessingFailureHandler;

        if (options.FailureHandler != null && !options.ThrowOnError)
        {
            Log.ThrowOnErrorIncompatible(SubscriptionId);
        }
    }
Ejemplo n.º 5
0
        /// <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 !;
Ejemplo n.º 6
0
    /// <summary>
    /// Creates RabbitMQ subscription service instance
    /// </summary>
    /// <param name="connectionFactory"></param>
    /// <param name="options"></param>
    /// <param name="consumePipe"></param>
    public RabbitMqSubscription(
        ConnectionFactory connectionFactory,
        RabbitMqSubscriptionOptions options,
        ConsumePipe consumePipe
        )
        : base(
            Ensure.NotNull(options),
            consumePipe.AddFilterFirst(new ConcurrentFilter(options.ConcurrencyLimit, options.ConcurrencyLimit * 10))
            )
    {
        _failureHandler = options.FailureHandler ?? DefaultEventFailureHandler;
        _connection     = Ensure.NotNull(connectionFactory).CreateConnection();
        _channel        = _connection.CreateModel();

        var prefetch = Options.PrefetchCount > 0 ? Options.PrefetchCount : Options.ConcurrencyLimit * 2;

        _channel.BasicQos(0, (ushort)prefetch, false);

        if (options.FailureHandler != null && !options.ThrowOnError)
        {
            Log.ThrowOnErrorIncompatible(SubscriptionId);
        }
    }