示例#1
0
        public SqsMqBuffer(SqsQueueDefinition queueDefinition,
                           SqsConnectionFactory sqsConnectionFactory)
        {
            Guard.AgainstNullArgument(queueDefinition, "queueDefinition");
            Guard.AgainstNullArgument(sqsConnectionFactory, "sqsConnectionFactory");

            this.queueDefinition = queueDefinition;
            this.sqsConnectionFactory = sqsConnectionFactory;
        }
示例#2
0
        private SqsQueueDefinition CreateQueue(SqsQueueName queueName, int?visibilityTimeoutSeconds = null,
                                               int?receiveWaitTimeSeconds     = null, bool?disasbleBuffering = null,
                                               SqsRedrivePolicy redrivePolicy = null)
        {
            SqsQueueDefinition queueDefinition = null;

            var request = new CreateQueueRequest
            {
                QueueName  = queueName.AwsQueueName,
                Attributes = new Dictionary <string, string>
                {
                    {
                        QueueAttributeName.ReceiveMessageWaitTimeSeconds,
                        TimeSpan.FromSeconds(receiveWaitTimeSeconds ?? DefaultReceiveWaitTime)
                        .TotalSeconds
                        .ToString(CultureInfo.InvariantCulture)
                    },
                    {
                        QueueAttributeName.VisibilityTimeout,
                        TimeSpan.FromSeconds(visibilityTimeoutSeconds ?? DefaultVisibilityTimeout)
                        .TotalSeconds
                        .ToString(CultureInfo.InvariantCulture)
                    },
                    {
                        QueueAttributeName.MessageRetentionPeriod,
                        (QueueNames.IsTempQueue(queueName.QueueName)
                            ? SqsQueueDefinition.DefaultTempQueueRetentionSeconds
                            : SqsQueueDefinition.DefaultPermanentQueueRetentionSeconds).ToString(CultureInfo.InvariantCulture)
                    }
                }
            };

            if (redrivePolicy != null)
            {
                var json = redrivePolicy.ToJson();
                request.Attributes.Add(QueueAttributeName.RedrivePolicy, json);
            }

            try
            {
                var createResponse = SqsClient.CreateQueue(request);

                // Note - must go fetch the attributes from the server after creation, as the request attributes do not include
                // anything assigned by the server (i.e. the ARN, etc.).
                queueDefinition = GetQueueDefinition(queueName, createResponse.QueueUrl);

                queueDefinition.DisableBuffering = disasbleBuffering ?? DisableBuffering;

                queueNameMap[queueDefinition.QueueName] = queueDefinition;
            }
            catch (QueueNameExistsException)
            {   // Queue exists with different attributes, instead of creating, alter those attributes to match what was requested
                queueDefinition = UpdateQueue(queueName, request.ToSetAttributesRequest(null), disasbleBuffering);
            }

            return(queueDefinition);
        }
示例#3
0
        public SqsMqBufferNonBuffered(SqsQueueDefinition queueDefinition,
                                      SqsConnectionFactory sqsConnectionFactory)
        {
            Guard.AgainstNullArgument(queueDefinition, "queueDefinition");
            Guard.AgainstNullArgument(sqsConnectionFactory, "sqsConnectionFactory");

            this.queueDefinition      = queueDefinition;
            this.sqsConnectionFactory = sqsConnectionFactory;
        }
示例#4
0
        private string GetQueueUrl(SqsQueueName queueName, bool forceRecheck = false)
        {
            SqsQueueDefinition qd = null;

            if (!forceRecheck && queueNameMap.TryGetValue(queueName.QueueName, out qd))
            {
                if (!string.IsNullOrEmpty(qd.QueueUrl))
                {
                    return(qd.QueueUrl);
                }
            }

            var response = SqsClient.GetQueueUrl(new GetQueueUrlRequest {
                QueueName = queueName.AwsQueueName
            });

            return(response.QueueUrl);
        }
示例#5
0
        public ISqsMqBuffer GetOrCreate(SqsQueueDefinition queueDefinition)
        {
            var queueName = queueDefinition.QueueName;

            if (queueNameBuffers.TryGetValue(queueName, out var buffer))
            {
                return(buffer);
            }

            buffer = queueDefinition.DisableBuffering
                ? (ISqsMqBuffer) new SqsMqBufferNonBuffered(queueDefinition, sqsConnectionFactory)
                : (ISqsMqBuffer) new SqsMqBuffer(queueDefinition, sqsConnectionFactory);

            buffer.ErrorHandler = ErrorHandler;

            queueNameBuffers.TryAdd(queueName, buffer);

            return(queueNameBuffers[queueName]);
        }
        public ISqsMqBuffer GetOrCreate(SqsQueueDefinition queueDefinition)
        {
            var queueName = queueDefinition.QueueName;

            ISqsMqBuffer buffer;

            if (queueNameBuffers.TryGetValue(queueName, out buffer))
                return buffer;

            buffer = queueDefinition.DisableBuffering
                ? (ISqsMqBuffer)new SqsMqBufferNonBuffered(queueDefinition, sqsConnectionFactory)
                : (ISqsMqBuffer)new SqsMqBuffer(queueDefinition, sqsConnectionFactory);

            buffer.ErrorHandler = ErrorHandler;

            queueNameBuffers.TryAdd(queueName, buffer);

            return queueNameBuffers[queueName];
        }
示例#7
0
        public static SendMessageRequest ToSqsSendMessageRequest(this IMessage message, SqsQueueDefinition queueDefinition)
        {
            var to = new SendMessageRequest
            {
                QueueUrl          = queueDefinition.QueueUrl,
                MessageBody       = message.Body.ToJson(),
                MessageAttributes = new Dictionary <string, MessageAttributeValue>
                {
                    { "CreatedDate", message.CreatedDate.AsMessageAttributeValue() },
                    { "Options", message.Options.AsMessageAttributeValue() },
                    { "Priority", message.Priority.AsMessageAttributeValue() },
                    { "RetryAttempts", message.RetryAttempts.AsMessageAttributeValue() },
                }
            };

            if (message.Tag != null)
            {
                to.MessageAttributes["Tag"] = message.Tag.AsMessageAttributeValue();
            }
            if (message.Error != null)
            {
                to.MessageAttributes["Error"] = message.Error.AsMessageAttributeValue();
            }
            if (message.ReplyId != null)
            {
                to.MessageAttributes["ReplyId"] = message.ReplyId.AsMessageAttributeValue();
            }
            if (message.ReplyTo != null)
            {
                to.MessageAttributes["ReplyTo"] = message.ReplyTo.AsMessageAttributeValue();
            }
            if (message.Meta != null)
            {
                to.MessageAttributes["Meta"] = message.Meta.AsMessageAttributeValue();
            }

            return(to);
        }