Beispiel #1
0
        private ICollection <IMessageReceiveBuffer> CreateBuffers(
            ReceiveMiddleware receiveMiddleware,
            SubscriptionGroupSettings subscriptionGroupSettings)
        {
            var buffers = new List <IMessageReceiveBuffer>();

            var logger = _loggerFactory.CreateLogger <MessageReceiveBuffer>();

            foreach (ISqsQueue queue in subscriptionGroupSettings.Queues)
            {
                var buffer = new MessageReceiveBuffer(
                    subscriptionGroupSettings.Prefetch,
                    subscriptionGroupSettings.BufferSize,
                    subscriptionGroupSettings.ReceiveBufferReadTimeout,
                    subscriptionGroupSettings.ReceiveMessagesWaitTime,
                    queue,
                    receiveMiddleware,
                    _monitor,
                    logger);

                buffers.Add(buffer);
            }

            return(buffers);
        }
        private ICollection <IMultiplexerSubscriber> CreateSubscribers(SubscriptionGroupSettings settings)
        {
            var logger = _loggerFactory.CreateLogger <MultiplexerSubscriber>();

            return(Enumerable.Range(0, settings.ConcurrencyLimit)
                   .Select(index => (IMultiplexerSubscriber) new MultiplexerSubscriber(
                               _messageDispatcher,
                               $"{settings.Name}-subscriber-{index}",
                               logger))
                   .ToList());
        }
Beispiel #3
0
 /// <summary>
 /// Coordinates reading messages from a collection of <see cref="IMessageReceiveBuffer"/>
 /// and dispatching using a collection of <see cref="IMultiplexerSubscriber"/>.
 /// </summary>
 /// <param name="settings">The <see cref="SubscriptionGroupSettings"/> to use.</param>
 /// <param name="receiveBuffers">The collection of <see cref="IMessageReceiveBuffer"/> to read from.</param>
 /// <param name="multiplexer">The <see cref="IMultiplexer"/> to aggregate all messages into one stream.</param>
 /// <param name="subscribers">The collection of <see cref="IMultiplexerSubscriber"/> that will dispatch the messages</param>
 /// <param name="logger">The <see cref="ILogger"/> to be used.</param>
 public SubscriptionGroup(
     SubscriptionGroupSettings settings,
     ICollection <IMessageReceiveBuffer> receiveBuffers,
     IMultiplexer multiplexer,
     ICollection <IMultiplexerSubscriber> subscribers,
     ILogger <SubscriptionGroup> logger)
 {
     _receiveBuffers = receiveBuffers;
     _settings       = settings;
     _multiplexer    = multiplexer;
     _subscribers    = subscribers;
     _logger         = logger;
 }
        /// <summary>
        /// Given a set of defaults and overrides from this builder, builds a concrete <see cref="SubscriptionGroupSettings"/>
        /// that can be passed to an <see cref="ISubscriptionGroupFactory"/> to build an <see cref="ISubscriptionGroup"/>.
        /// </summary>
        /// <param name="defaults">The default values to use if no override given.</param>
        /// <returns>A <see cref="SubscriptionGroupSettings"/>.</returns>
        public SubscriptionGroupSettings Build(SubscriptionGroupSettingsBuilder defaults)
        {
            if (defaults == null)
            {
                throw new InvalidOperationException("Defaults must be set before building settings.");
            }

            var settings = new SubscriptionGroupSettings(
                _groupName,
                _concurrencyLimit ?? defaults.ConcurrencyLimit,
                _bufferSize ?? defaults.BufferSize,
                _receiveBufferReadTimeout ?? defaults.ReceiveBufferReadTimeout,
                _recieveMessagesWaitTime ?? defaults.ReceiveMessagesWaitTime,
                _multiplexerCapacity ?? defaults.MultiplexerCapacity,
                _prefetch ?? defaults.Prefetch,
                _sqsQueues);

            settings.Validate();

            return(settings);
        }
        private ISubscriptionGroup Create(ReceiveMiddleware receiveMiddleware, SubscriptionGroupSettings settings)
        {
            IMultiplexer multiplexer = CreateMultiplexer(settings.MultiplexerCapacity);
            ICollection <IMessageReceiveBuffer>  receiveBuffers = CreateBuffers(receiveMiddleware, settings);
            ICollection <IMultiplexerSubscriber> subscribers    = CreateSubscribers(settings);

            foreach (IMessageReceiveBuffer receiveBuffer in receiveBuffers)
            {
                multiplexer.ReadFrom(receiveBuffer.Reader);
            }

            foreach (IMultiplexerSubscriber subscriber in subscribers)
            {
                subscriber.Subscribe(multiplexer.GetMessagesAsync());
            }

            return(new SubscriptionGroup(
                       settings,
                       receiveBuffers,
                       multiplexer,
                       subscribers,
                       _loggerFactory.CreateLogger <SubscriptionGroup>()));
        }