Esempio n. 1
0
        public void EnsureQueueAndErrorQueueExistAndAllAttributesAreUpdated(SqsBasicConfiguration queueConfig)
        {
            if (!Exists())
                Create(queueConfig);
            else
            {
                UpdateQueueAttribute(queueConfig);
            }

            //Create an error queue for existing queues if they don't already have one
            if (ErrorQueue != null)
            {
                var errorQueueConfig = new SqsReadConfiguration(SubscriptionType.ToTopic)
                {
                    ErrorQueueRetentionPeriodSeconds = queueConfig.ErrorQueueRetentionPeriodSeconds,
                    ErrorQueueOptOut = true
                };
                if (!ErrorQueue.Exists())
                {

                    ErrorQueue.Create(errorQueueConfig);
                }
                else
                {
                    ErrorQueue.UpdateQueueAttribute(errorQueueConfig);
                }
            }
            UpdateRedrivePolicy(new RedrivePolicy(queueConfig.RetryCountBeforeSendingToErrorQueue, ErrorQueue.Arn));

        }
Esempio n. 2
0
 protected internal virtual void UpdateQueueAttribute(SqsBasicConfiguration queueConfig)
 {
     if (QueueNeedsUpdating(queueConfig))
     {
         var request = new SetQueueAttributesRequest
         {
             QueueUrl = Url,
             Attributes = new Dictionary<string, string>
             {
                 {JustSayingConstants.ATTRIBUTE_RETENTION_PERIOD, queueConfig.MessageRetentionSeconds.ToString()},
                 {
                     JustSayingConstants.ATTRIBUTE_VISIBILITY_TIMEOUT,
                     queueConfig.VisibilityTimeoutSeconds.ToString()
                 },
                 {JustSayingConstants.ATTRIBUTE_DELIVERY_DELAY, queueConfig.DeliveryDelaySeconds.ToString()}
             }
         };
         var response = Client.SetQueueAttributes(request);
         if (response.HttpStatusCode == HttpStatusCode.OK)
         {
             MessageRetentionPeriod = queueConfig.MessageRetentionSeconds;
             VisibilityTimeout = queueConfig.VisibilityTimeoutSeconds;
             DeliveryDelay = queueConfig.DeliveryDelaySeconds;
         }
     }
 }
Esempio n. 3
0
 public override bool Create(SqsBasicConfiguration queueConfig, int attempt = 0)
 {
     if (!ErrorQueue.Exists())
     {
         ErrorQueue.Create(new SqsBasicConfiguration { ErrorQueueRetentionPeriodSeconds = queueConfig.ErrorQueueRetentionPeriodSeconds, ErrorQueueOptOut = true });
     }
     return base.Create(queueConfig, attempt);
 }
Esempio n. 4
0
 protected override Dictionary<string, string> GetCreateQueueAttributes(SqsBasicConfiguration queueConfig)
 {
     return new Dictionary<string, string>
     {
         { SQSConstants.ATTRIBUTE_MESSAGE_RETENTION_PERIOD , queueConfig.ErrorQueueRetentionPeriodSeconds.ToString(CultureInfo.InvariantCulture)},
         { SQSConstants.ATTRIBUTE_VISIBILITY_TIMEOUT  , JustSayingConstants.DEFAULT_VISIBILITY_TIMEOUT.ToString(CultureInfo.InvariantCulture)},
     };
 }
        public virtual bool Create(SqsBasicConfiguration queueConfig, int attempt = 0)
        {
            try
            {
                var result = Client.CreateQueue(new CreateQueueRequest{
                    QueueName = QueueName,
                    Attributes = GetCreateQueueAttributes(queueConfig)});

                if (!string.IsNullOrWhiteSpace(result.QueueUrl))
                {
                    Url = result.QueueUrl;
                    SetQueueProperties();

                    Log.Info(string.Format("Created Queue: {0} on Arn: {1}", QueueName, Arn));
                    return true;
                }
            }
            catch (AmazonSQSException ex)
            {
                if (ex.ErrorCode == "AWS.SimpleQueueService.QueueDeletedRecently")
                {
                    // Ensure we wait for queue delete timeout to expire.
                    Log.Info(string.Format("Waiting to create Queue due to AWS time restriction - Queue: {0}, AttemptCount: {1}", QueueName, attempt + 1));
                    Thread.Sleep(60000);
                    Create(queueConfig, attempt: attempt++);
                }
                else
                {
                    // Throw all errors which are not delete timeout related.
                    Log.Error(ex, string.Format("Create Queue error: {0}", QueueName));
                    throw;
                }

                // If we're on a delete timeout, throw after 2 attempts.
                if (attempt >= 2)
                {
                    Log.Error(ex, string.Format("Create Queue error, max retries exceeded for delay - Queue: {0}", QueueName));
                    throw;
                }
            }

            Log.Info(string.Format("Failed to create Queue: {0}", QueueName));
            return false;
        }
Esempio n. 6
0
 protected internal override void UpdateQueueAttribute(SqsBasicConfiguration queueConfig)
 {
     if (QueueNeedsUpdating(queueConfig))
     {
         var response = Client.SetQueueAttributes(
             new SetQueueAttributesRequest
             {
                 QueueUrl = Url,
                 Attributes = new Dictionary<string, string>
                 {
                     {JustSayingConstants.ATTRIBUTE_RETENTION_PERIOD, queueConfig.ErrorQueueRetentionPeriodSeconds.ToString()},
                 }
             });
         if (response.HttpStatusCode == HttpStatusCode.OK)
         {
             MessageRetentionPeriod = queueConfig.ErrorQueueRetentionPeriodSeconds;
         }
     }
 }
Esempio n. 7
0
 protected override Dictionary<string, string> GetCreateQueueAttributes(SqsBasicConfiguration queueConfig)
 {
     return new Dictionary<string, string>
     {
         { SQSConstants.ATTRIBUTE_MESSAGE_RETENTION_PERIOD ,queueConfig.MessageRetentionSeconds.ToString(CultureInfo.InvariantCulture)},
         { SQSConstants.ATTRIBUTE_VISIBILITY_TIMEOUT  , queueConfig.VisibilityTimeoutSeconds.ToString(CultureInfo.InvariantCulture)},
         { SQSConstants.ATTRIBUTE_DELAY_SECONDS  , queueConfig.DeliveryDelaySeconds.ToString(CultureInfo.InvariantCulture)},
         { JustSayingConstants.ATTRIBUTE_REDRIVE_POLICY, new RedrivePolicy(_retryCountBeforeSendingToErrorQueue, ErrorQueue.Arn).ToString()}
     };
 }
Esempio n. 8
0
 protected virtual bool QueueNeedsUpdating(SqsBasicConfiguration queueConfig)
 {
     return MessageRetentionPeriod != queueConfig.MessageRetentionSeconds
            || VisibilityTimeout != queueConfig.VisibilityTimeoutSeconds
            || DeliveryDelay != queueConfig.DeliveryDelaySeconds;
 }
 protected abstract Dictionary<string, string> GetCreateQueueAttributes(SqsBasicConfiguration queueConfig);
Esempio n. 10
0
 private static bool NeedErrorQueue(SqsBasicConfiguration queueConfig)
 {
     return !queueConfig.ErrorQueueOptOut;
 }
Esempio n. 11
0
 protected override bool QueueNeedsUpdating(SqsBasicConfiguration queueConfig)
 {
     return MessageRetentionPeriod != queueConfig.ErrorQueueRetentionPeriodSeconds;
 }