Пример #1
0
        /// <summary>
        /// Creates a consumer for the specified queue.
        /// </summary>
        /// <param name="subscription">The queue to connect to</param>
        /// <returns>IAmAMessageConsumer.</returns>
        public IAmAMessageConsumer Create(Subscription subscription)
        {
            SqsSubscription sqsSubscription = subscription as SqsSubscription;

            if (sqsSubscription == null)
            {
                throw new ConfigurationException("We expect an SqsSubscription or SqsSubscription<T> as a parameter");
            }

            return(new SqsMessageConsumer(
                       awsConnection: _awsConnection,
                       queueName: subscription.ChannelName.ToValidSQSQueueName(),
                       routingKey: subscription.RoutingKey,
                       batchSize: subscription.BufferSize,
                       hasDLQ: sqsSubscription.RedrivePolicy == null
                       ));
        }
Пример #2
0
        ///  <summary>
        ///  Creates the input channel.
        ///  With SQS we can ensure that queues exist ahead of creating the consumer, as there is no non-durable queue model
        ///  to create ephemeral queues, nor are there non-mirrored queues (on a single node in the cluster) where nodes
        ///  failing mean we want to create anew as we recreate. So the input factory creates the queue
        ///  </summary>
        /// <param name="subscription">An SqsSubscription, the subscription parameter so create the channel with</param>
        /// <returns>IAmAnInputChannel.</returns>
        public IAmAChannel CreateChannel(Subscription subscription)
        {
            var channel = _retryPolicy.Execute(() =>
            {
                SqsSubscription sqsSubscription = subscription as SqsSubscription;
                _subscription = sqsSubscription ?? throw new ConfigurationException("We expect an SqsSubscription or SqsSubscription<T> as a parameter");

                EnsureTopic(_subscription.RoutingKey, _subscription.SnsAttributes, _subscription.FindTopicBy, _subscription.MakeChannels);
                EnsureQueue();

                return(new Channel(
                           subscription.ChannelName.ToValidSQSQueueName(),
                           _messageConsumerFactory.Create(subscription),
                           subscription.BufferSize
                           ));
            });

            return(channel);
        }