예제 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Subscription"/> class.
 /// </summary>
 /// <param name="dataType">Type of the data.</param>
 /// <param name="name">The name. Defaults to the data type's full name.</param>
 /// <param name="channelName">The channel name. Defaults to the data type's full name.</param>
 /// <param name="routingKey">The routing key. Defaults to the data type's full name.</param>
 /// <param name="noOfPerformers">The no of threads reading this channel.</param>
 /// <param name="bufferSize">The number of messages to buffer at any one time, also the number of messages to retrieve at once. Min of 1 Max of 10</param>
 /// <param name="timeoutInMilliseconds">The timeout in milliseconds.</param>
 /// <param name="requeueCount">The number of times you want to requeue a message before dropping it.</param>
 /// <param name="requeueDelayInMilliseconds">The number of milliseconds to delay the delivery of a requeue message for.</param>
 /// <param name="unacceptableMessageLimit">The number of unacceptable messages to handle, before stopping reading from the channel.</param>
 /// <param name="runAsync">Is this channel read asynchronously</param>
 /// <param name="channelFactory">The channel factory to create channels for Consumer.</param>
 /// <param name="lockTimeout">What is the visibility timeout for the queue</param>
 /// <param name="delaySeconds">The length of time, in seconds, for which the delivery of all messages in the queue is delayed.</param>
 /// <param name="messageRetentionPeriod">The length of time, in seconds, for which Amazon SQS retains a message</param>
 /// <param name="findTopicBy">Is the Topic an Arn, should be treated as an Arn by convention, or a name</param>
 /// <param name="iAmPolicy">The queue's policy. A valid AWS policy.</param>
 /// <param name="redrivePolicy">The policy that controls when and where requeued messages are sent to the DLQ</param>
 /// <param name="snsAttributes">The attributes of the Topic, either ARN if created, or attributes for creation</param>
 /// <param name="tags">Resource tags to be added to the queue</param>
 /// <param name="makeChannels">Should we make channels if they don't exist, defaults to creating</param>
 public SqsSubscription(Type dataType,
                        SubscriptionName name          = null,
                        ChannelName channelName        = null,
                        RoutingKey routingKey          = null,
                        int bufferSize                 = 1,
                        int noOfPerformers             = 1,
                        int timeoutInMilliseconds      = 300,
                        int requeueCount               = -1,
                        int requeueDelayInMilliseconds = 0,
                        int unacceptableMessageLimit   = 0,
                        bool runAsync = false,
                        IAmAChannelFactory channelFactory = null,
                        int lockTimeout                  = 10,
                        int delaySeconds                 = 0,
                        int messageRetentionPeriod       = 345600,
                        TopicFindBy findTopicBy          = TopicFindBy.Name,
                        string iAmPolicy                 = null,
                        RedrivePolicy redrivePolicy      = null,
                        SnsAttributes snsAttributes      = null,
                        Dictionary <string, string> tags = null,
                        OnMissingChannel makeChannels    = OnMissingChannel.Create
                        )
     : base(dataType, name, channelName, routingKey, bufferSize, noOfPerformers, timeoutInMilliseconds, requeueCount, requeueDelayInMilliseconds,
            unacceptableMessageLimit, runAsync, channelFactory, makeChannels)
 {
     LockTimeout            = lockTimeout;
     DelaySeconds           = delaySeconds;
     MessageRetentionPeriod = messageRetentionPeriod;
     FindTopicBy            = findTopicBy;
     IAMPolicy     = iAmPolicy;
     RedrivePolicy = redrivePolicy;
     SnsAttributes = snsAttributes;
     Tags          = tags;
 }
예제 #2
0
 protected string EnsureTopic(RoutingKey topic, SnsAttributes attributes, TopicFindBy topicFindBy, OnMissingChannel makeTopic)
 {
     //on validate or assume, turn a routing key into a topicARN
     if ((makeTopic == OnMissingChannel.Assume) || (makeTopic == OnMissingChannel.Validate))
     {
         ValidateTopic(topic, topicFindBy, makeTopic);
     }
     else if (makeTopic == OnMissingChannel.Create)
     {
         CreateTopic(topic, attributes);
     }
     return(ChannelTopicArn);
 }
예제 #3
0
        private void ValidateTopic(RoutingKey topic, SnsAttributes attributes, OnMissingChannel onMissingChannel)
        {
            if ((attributes != null) && (!string.IsNullOrEmpty(attributes.TopicARN)))
            {
                if (onMissingChannel == OnMissingChannel.Assume)
                {
                    _channelTopicArn = attributes.TopicARN;
                    return;
                }
                else
                {
                    ValidateTopicByArn(attributes.TopicARN);
                }
            }

            ValidateTopicByName(topic);
        }
예제 #4
0
        private void ValidateTopic(RoutingKey topic, SnsAttributes attributes)
        {
            if ((attributes != null) && (!string.IsNullOrEmpty(attributes.TopicARN)))
            {
                _channelTopicArn = attributes.TopicARN;
            }

            using (var snsClient = new AmazonSimpleNotificationServiceClient(_awsConnection.Credentials, _awsConnection.Region))
            {
                var(success, arn) = FindTopicByName(topic.ToValidSNSTopicName(), snsClient);
                if (success)
                {
                    _channelTopicArn = arn;
                }
                else
                {
                    throw new BrokerUnreachableException(
                              $"Topic validation error: could not find topic {topic.ToValidSNSTopicName()}. Did you want Brighter to create infrastructure?");
                }
            }
        }
예제 #5
0
        private void CreateTopic(RoutingKey topicName, SnsAttributes snsAttributes)
        {
            using (var snsClient = new AmazonSimpleNotificationServiceClient(_awsConnection.Credentials, _awsConnection.Region))
            {
                var attributes = new Dictionary <string, string>();
                if (snsAttributes != null)
                {
                    if (!string.IsNullOrEmpty(snsAttributes.DeliveryPolicy))
                    {
                        attributes.Add("DeliveryPolicy", snsAttributes.DeliveryPolicy);
                    }
                    if (!string.IsNullOrEmpty(snsAttributes.Policy))
                    {
                        attributes.Add("Policy", snsAttributes.Policy);
                    }
                }

                var createTopicRequest = new CreateTopicRequest(topicName)
                {
                    Attributes = attributes,
                    Tags       = new List <Tag> {
                        new Tag {
                            Key = "Source", Value = "Brighter"
                        }
                    }
                };

                //create topic is idempotent, so safe to call even if topic already exists
                var createTopic = snsClient.CreateTopicAsync(createTopicRequest).Result;

                if (!string.IsNullOrEmpty(createTopic.TopicArn))
                {
                    ChannelTopicArn = createTopic.TopicArn;
                }
                else
                {
                    throw new InvalidOperationException($"Could not create Topic topic: {topicName} on {_awsConnection.Region}");
                }
            }
        }