public async Task <SqsQueueByName> EnsureTopicExistsWithQueueSubscribedAsync(
            string region,
            IMessageSerializationRegister serializationRegister,
            SqsReadConfiguration queueConfig,
            IMessageSubjectProvider messageSubjectProvider)
        {
            var regionEndpoint = RegionEndpoint.GetBySystemName(region);
            var sqsClient      = _awsClientFactory.GetAwsClientFactory().GetSqsClient(regionEndpoint);
            var snsClient      = _awsClientFactory.GetAwsClientFactory().GetSnsClient(regionEndpoint);

            var queue = await EnsureQueueExistsAsync(region, queueConfig).ConfigureAwait(false);

            if (TopicExistsInAnotherAccount(queueConfig))
            {
                var arnProvider = new ForeignTopicArnProvider(regionEndpoint, queueConfig.TopicSourceAccount, queueConfig.PublishEndpoint);

                var topicArn = await arnProvider.GetArnAsync().ConfigureAwait(false);
                await SubscribeQueueAndApplyFilterPolicyAsync(snsClient, topicArn, sqsClient, queue.Uri, queueConfig.FilterPolicy).ConfigureAwait(false);
            }
            else
            {
                var eventTopic = new SnsTopicByName(queueConfig.PublishEndpoint, snsClient, serializationRegister, _loggerFactory, messageSubjectProvider);
                await eventTopic.CreateAsync().ConfigureAwait(false);

                await SubscribeQueueAndApplyFilterPolicyAsync(snsClient, eventTopic.Arn, sqsClient, queue.Uri, queueConfig.FilterPolicy).ConfigureAwait(false);

                await SqsPolicy.SaveAsync(eventTopic.Arn, queue.Arn, queue.Uri, sqsClient).ConfigureAwait(false);
            }

            return(queue);
        }
 public SqsQueueByName EnsureQueueExists(string region, SqsReadConfiguration queueConfig)
 {
     var sqsclient = AWSClientFactory.CreateAmazonSQSClient(RegionEndpoint.GetBySystemName(region));
     var queue = new SqsQueueByName(queueConfig.QueueName, sqsclient, queueConfig.RetryCountBeforeSendingToErrorQueue);
     queue.EnsureQueueAndErrorQueueExistAndAllAttributesAreUpdated(queueConfig);
     return queue;
 }
        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));

        }
        public SqsQueueByName EnsureTopicExistsWithQueueSubscribed(string region, IMessageSerialisationRegister serialisationRegister, SqsReadConfiguration queueConfig)
        {
            var queue = EnsureQueueExists(region, queueConfig);
            var eventTopic = EnsureTopicExists(region, serialisationRegister, queueConfig);
            EnsureQueueIsSubscribedToTopic(region, eventTopic, queue);

            return queue;
        }
        public SqsQueueByName EnsureQueueExists(string region, SqsReadConfiguration queueConfig)
        {
            var sqsclient = AWSClientFactory.CreateAmazonSQSClient(RegionEndpoint.GetBySystemName(region));
            var queue     = new SqsQueueByName(queueConfig.QueueName, sqsclient, queueConfig.RetryCountBeforeSendingToErrorQueue);

            queue.EnsureQueueAndErrorQueueExistAndAllAttributesAreUpdated(queueConfig);
            return(queue);
        }
Exemple #6
0
        public QueueWithAsyncStartup EnsureTopicExistsWithQueueSubscribed(
            string region,
            SqsReadConfiguration queueConfig)
        {
            var regionEndpoint = RegionEndpoint.GetBySystemName(region);
            var sqsClient      = _awsClientFactory.GetAwsClientFactory().GetSqsClient(regionEndpoint);
            var snsClient      = _awsClientFactory.GetAwsClientFactory().GetSnsClient(regionEndpoint);

            var queueWithStartup = EnsureQueueExists(region, queueConfig);

            async Task StartupTask(CancellationToken cancellationToken)
            {
                await queueWithStartup.StartupTask.Invoke(cancellationToken).ConfigureAwait(false);

                var queue = queueWithStartup.Queue;

                if (TopicExistsInAnotherAccount(queueConfig))
                {
                    var arnProvider = new ForeignTopicArnProvider(regionEndpoint,
                                                                  queueConfig.TopicSourceAccount,
                                                                  queueConfig.PublishEndpoint);

                    var topicArn = await arnProvider.GetArnAsync().ConfigureAwait(false);
                    await SubscribeQueueAndApplyFilterPolicyAsync(snsClient,
                                                                  topicArn,
                                                                  sqsClient,
                                                                  queue.Uri,
                                                                  queueConfig.FilterPolicy).ConfigureAwait(false);
                }
                else
                {
#pragma warning disable 618
                    var eventTopic = new SnsTopicByName(queueConfig.PublishEndpoint, snsClient, _loggerFactory);
#pragma warning restore 618
                    await eventTopic.CreateAsync(cancellationToken).ConfigureAwait(false);

                    await SubscribeQueueAndApplyFilterPolicyAsync(snsClient,
                                                                  eventTopic.Arn,
                                                                  sqsClient,
                                                                  queue.Uri,
                                                                  queueConfig.FilterPolicy).ConfigureAwait(false);

                    var sqsDetails = new SqsPolicyDetails
                    {
                        SourceArn = eventTopic.Arn,
                        QueueArn  = queue.Arn,
                        QueueUri  = queue.Uri
                    };
                    await SqsPolicy
                    .SaveAsync(sqsDetails, sqsClient)
                    .ConfigureAwait(false);
                }
            }

            return(new QueueWithAsyncStartup(StartupTask, queueWithStartup.Queue));
        }
        private static SnsTopicByName EnsureTopicExists(string region, IMessageSerialisationRegister serialisationRegister, SqsReadConfiguration queueConfig)
        {
            var snsclient = AWSClientFactory.CreateAmazonSimpleNotificationServiceClient(RegionEndpoint.GetBySystemName(region));
            var eventTopic = new SnsTopicByName(queueConfig.PublishEndpoint, snsclient, serialisationRegister);

            if (!eventTopic.Exists())
                eventTopic.Create();

            return eventTopic;
        }
        public QueueWithAsyncStartup <SqsQueueByName> EnsureTopicExistsWithQueueSubscribed(
            string region,
            IMessageSerializationRegister serializationRegister,
            SqsReadConfiguration queueConfig,
            IMessageSubjectProvider messageSubjectProvider)
        {
            var regionEndpoint = RegionEndpoint.GetBySystemName(region);
            var sqsClient      = _awsClientFactory.GetAwsClientFactory().GetSqsClient(regionEndpoint);
            var snsClient      = _awsClientFactory.GetAwsClientFactory().GetSnsClient(regionEndpoint);

            var queueWithStartup = EnsureQueueExists(region, queueConfig);

            async Task StartupTask()
            {
                await queueWithStartup.StartupTask.ConfigureAwait(false);

                var queue = queueWithStartup.Queue;

                if (TopicExistsInAnotherAccount(queueConfig))
                {
                    var arnProvider = new ForeignTopicArnProvider(regionEndpoint,
                                                                  queueConfig.TopicSourceAccount,
                                                                  queueConfig.PublishEndpoint);

                    var topicArn = await arnProvider.GetArnAsync().ConfigureAwait(false);
                    await SubscribeQueueAndApplyFilterPolicyAsync(snsClient,
                                                                  topicArn,
                                                                  sqsClient,
                                                                  queue.Uri,
                                                                  queueConfig.FilterPolicy).ConfigureAwait(false);
                }
                else
                {
                    var eventTopic = new SnsTopicByName(queueConfig.PublishEndpoint,
                                                        snsClient,
                                                        serializationRegister,
                                                        _loggerFactory,
                                                        messageSubjectProvider);
                    await eventTopic.CreateAsync().ConfigureAwait(false);

                    await SubscribeQueueAndApplyFilterPolicyAsync(snsClient,
                                                                  eventTopic.Arn,
                                                                  sqsClient,
                                                                  queue.Uri,
                                                                  queueConfig.FilterPolicy).ConfigureAwait(false);

                    await SqsPolicy
                    .SaveAsync(eventTopic.Arn, queue.Arn, queue.Uri, sqsClient)
                    .ConfigureAwait(false);
                }
            }

            // This StartupTask is intentionally not awaited, as it will be run when the bus is started.
            return(new QueueWithAsyncStartup <SqsQueueByName>(StartupTask(), queueWithStartup.Queue));
        }
        public SqsQueueByName EnsureQueueExists(string region, SqsReadConfiguration queueConfig)
        {
            var regionEndpoint = RegionEndpoint.GetBySystemName(region);
            var sqsclient = _awsClientFactory.GetAwsClientFactory().GetSqsClient(regionEndpoint);
            var queue = _queueCache.TryGetFromCache(region, queueConfig.QueueName);
            if (queue != null)
                return queue;
            queue = new SqsQueueByName(regionEndpoint, queueConfig.QueueName, sqsclient, queueConfig.RetryCountBeforeSendingToErrorQueue);
            queue.EnsureQueueAndErrorQueueExistAndAllAttributesAreUpdated(queueConfig);

            _queueCache.AddToCache(region, queue.QueueName, queue);
            return queue;
        }
        public SqsQueueByName EnsureQueueExists(string region, SqsReadConfiguration queueConfig)
        {
            var regionEndpoint = RegionEndpoint.GetBySystemName(region);
            var sqsclient      = _awsClientFactory.GetAwsClientFactory().GetSqsClient(regionEndpoint);
            var queue          = _queueCache.TryGetFromCache(region, queueConfig.QueueName);

            if (queue != null)
            {
                return(queue);
            }
            queue = new SqsQueueByName(regionEndpoint, queueConfig.QueueName, sqsclient, queueConfig.RetryCountBeforeSendingToErrorQueue);
            queue.EnsureQueueAndErrorQueueExistAndAllAttributesAreUpdated(queueConfig);

            _queueCache.AddToCache(region, queue.QueueName, queue);
            return(queue);
        }
        private SnsTopicByName EnsureTopicExists(RegionEndpoint region, IMessageSerialisationRegister serialisationRegister, SqsReadConfiguration queueConfig)
        {
            var snsclient = _awsClientFactory.GetAwsClientFactory().GetSnsClient(region);

            var eventTopic = _topicCache.TryGetFromCache(region.SystemName, queueConfig.PublishEndpoint);
            if (eventTopic != null)
                return eventTopic;

            eventTopic = new SnsTopicByName(queueConfig.PublishEndpoint, snsclient, serialisationRegister);
            _topicCache.AddToCache(region.SystemName, queueConfig.PublishEndpoint, eventTopic);

            if (!eventTopic.Exists())
                eventTopic.Create();

            return eventTopic;
        }
Exemple #12
0
        public QueueWithAsyncStartup <SqsQueueByName> EnsureQueueExists(
            string region,
            SqsReadConfiguration queueConfig)
        {
            var regionEndpoint = RegionEndpoint.GetBySystemName(region);
            var sqsclient      = _awsClientFactory.GetAwsClientFactory().GetSqsClient(regionEndpoint);

            var queue = new SqsQueueByName(regionEndpoint,
                                           queueConfig.QueueName,
                                           sqsclient,
                                           queueConfig.RetryCountBeforeSendingToErrorQueue,
                                           _loggerFactory);

            var startupTask = queue.EnsureQueueAndErrorQueueExistAndAllAttributesAreUpdatedAsync(queueConfig);

            // This startupTask is intentionally not awaited, as it will be run when the bus is started.
            return(new QueueWithAsyncStartup <SqsQueueByName>(startupTask, queue));
        }
        public QueueWithAsyncStartup EnsureQueueExists(
            string region,
            SqsReadConfiguration queueConfig)
        {
            var regionEndpoint = RegionEndpoint.GetBySystemName(region);
            var sqsClient      = _awsClientFactory.GetAwsClientFactory().GetSqsClient(regionEndpoint);

#pragma warning disable 618
            var queue = new SqsQueueByName(regionEndpoint,
                                           queueConfig.QueueName,
                                           sqsClient,
                                           queueConfig.RetryCountBeforeSendingToErrorQueue,
                                           _loggerFactory);
#pragma warning restore 618

            var startupTask = new Func <Task>(() => queue.EnsureQueueAndErrorQueueExistAndAllAttributesAreUpdatedAsync(queueConfig));

            return(new QueueWithAsyncStartup(startupTask, queue));
        }
        public SqsQueueByName EnsureTopicExistsWithQueueSubscribed(string region, IMessageSerialisationRegister serialisationRegister, SqsReadConfiguration queueConfig)
        {
            var regionEndpoint = RegionEndpoint.GetBySystemName(region);
            var queue = EnsureQueueExists(region, queueConfig);
            if (TopicExistsInAnotherAccount(queueConfig))
            {
                var sqsClient = _awsClientFactory.GetAwsClientFactory().GetSqsClient(regionEndpoint);
                var snsClient = _awsClientFactory.GetAwsClientFactory().GetSnsClient(regionEndpoint);
                var arnProvider = new ForeignTopicArnProvider(regionEndpoint, queueConfig.TopicSourceAccount, queueConfig.PublishEndpoint);
                snsClient.SubscribeQueue(arnProvider.GetArn(), sqsClient, queue.Url);
            }
            else
            {
                var eventTopic = EnsureTopicExists(regionEndpoint, serialisationRegister, queueConfig);
                EnsureQueueIsSubscribedToTopic(regionEndpoint, eventTopic, queue);

                var sqsclient = _awsClientFactory.GetAwsClientFactory().GetSqsClient(regionEndpoint);
                SqsPolicy.Save(eventTopic.Arn, queue.Arn, queue.Url, sqsclient);
            }

            return queue;
        }
        private static SnsTopicByName EnsureTopicExists(string region, IMessageSerialisationRegister serialisationRegister, SqsReadConfiguration queueConfig)
        {
            var snsclient  = AWSClientFactory.CreateAmazonSimpleNotificationServiceClient(RegionEndpoint.GetBySystemName(region));
            var eventTopic = new SnsTopicByName(queueConfig.PublishEndpoint, snsclient, serialisationRegister);

            if (!eventTopic.Exists())
            {
                eventTopic.Create();
            }

            return(eventTopic);
        }
        public SqsQueueByName EnsureTopicExistsWithQueueSubscribed(string region, IMessageSerialisationRegister serialisationRegister, SqsReadConfiguration queueConfig)
        {
            var regionEndpoint = RegionEndpoint.GetBySystemName(region);
            var queue          = EnsureQueueExists(region, queueConfig);

            if (TopicExistsInAnotherAccount(queueConfig))
            {
                var sqsClient   = _awsClientFactory.GetAwsClientFactory().GetSqsClient(regionEndpoint);
                var snsClient   = _awsClientFactory.GetAwsClientFactory().GetSnsClient(regionEndpoint);
                var arnProvider = new ForeignTopicArnProvider(regionEndpoint, queueConfig.TopicSourceAccount, queueConfig.PublishEndpoint);
                snsClient.SubscribeQueue(arnProvider.GetArn(), sqsClient, queue.Url);
            }
            else
            {
                var eventTopic = EnsureTopicExists(regionEndpoint, serialisationRegister, queueConfig);
                EnsureQueueIsSubscribedToTopic(regionEndpoint, eventTopic, queue);

                var sqsclient = _awsClientFactory.GetAwsClientFactory().GetSqsClient(regionEndpoint);
                SqsPolicy.Save(eventTopic.Arn, queue.Arn, queue.Url, sqsclient);
            }

            return(queue);
        }
        public async Task <SqsQueueByName> EnsureTopicExistsWithQueueSubscribedAsync(string region, IMessageSerialisationRegister serialisationRegister, SqsReadConfiguration queueConfig)
        {
            var regionEndpoint = RegionEndpoint.GetBySystemName(region);
            var sqsClient      = _awsClientFactory.GetAwsClientFactory().GetSqsClient(regionEndpoint);
            var snsClient      = _awsClientFactory.GetAwsClientFactory().GetSnsClient(regionEndpoint);

            var queue = await EnsureQueueExistsAsync(region, queueConfig).ConfigureAwait(false);

            if (TopicExistsInAnotherAccount(queueConfig))
            {
                var arnProvider = new ForeignTopicArnProvider(regionEndpoint, queueConfig.TopicSourceAccount, queueConfig.PublishEndpoint);

                await snsClient.SubscribeQueueAsync(arnProvider.GetArn(), sqsClient, queue.Url).ConfigureAwait(false);
            }
            else
            {
                var eventTopic = new SnsTopicByName(queueConfig.PublishEndpoint, snsClient, serialisationRegister, _loggerFactory);
                eventTopic.Create();

                await EnsureQueueIsSubscribedToTopic(eventTopic, queue).ConfigureAwait(false);

                await SqsPolicy.SaveAsync(eventTopic.Arn, queue.Arn, queue.Url, sqsClient).ConfigureAwait(false);
            }

            return(queue);
        }
        private SnsTopicByName EnsureTopicExists(RegionEndpoint region, IMessageSerialisationRegister serialisationRegister, SqsReadConfiguration queueConfig)
        {
            var snsclient = _awsClientFactory.GetAwsClientFactory().GetSnsClient(region);

            var eventTopic = _topicCache.TryGetFromCache(region.SystemName, queueConfig.PublishEndpoint);

            if (eventTopic != null)
            {
                return(eventTopic);
            }

            eventTopic = new SnsTopicByName(queueConfig.PublishEndpoint, snsclient, serialisationRegister);
            _topicCache.AddToCache(region.SystemName, queueConfig.PublishEndpoint, eventTopic);

            if (!eventTopic.Exists())
            {
                eventTopic.Create();
            }

            return(eventTopic);
        }
 public SqsQueueByName EnsureQueueExists(string region, SqsReadConfiguration queueConfig)
 {
     return(EnsureQueueExistsAsync(region, queueConfig)
            .GetAwaiter().GetResult());
 }
        public SqsQueueByName EnsureTopicExistsWithQueueSubscribed(string region, IMessageSerialisationRegister serialisationRegister, SqsReadConfiguration queueConfig)
        {
            var regionEndpoint = RegionEndpoint.GetBySystemName(region);
            var queue          = EnsureQueueExists(region, queueConfig);
            var eventTopic     = EnsureTopicExists(regionEndpoint, serialisationRegister, queueConfig);

            EnsureQueueIsSubscribedToTopic(regionEndpoint, eventTopic, queue);

            var sqsclient = _awsClientFactory.GetAwsClientFactory().GetSqsClient(regionEndpoint);

            SqsPolicy.Save(eventTopic.Arn, queue.Arn, queue.Url, sqsclient);
            return(queue);
        }
 private static bool TopicExistsInAnotherAccount(SqsReadConfiguration queueConfig)
 {
     return !string.IsNullOrWhiteSpace(queueConfig.TopicSourceAccount);
 }
 public SqsQueueByName EnsureTopicExistsWithQueueSubscribed(string region,
                                                            IMessageSerialisationRegister serialisationRegister, SqsReadConfiguration queueConfig)
 {
     return(EnsureTopicExistsWithQueueSubscribedAsync(region, serialisationRegister, queueConfig)
            .GetAwaiter().GetResult());
 }
        public SqsQueueByName EnsureTopicExistsWithQueueSubscribed(string region, IMessageSerialisationRegister serialisationRegister, SqsReadConfiguration queueConfig)
        {
            var regionEndpoint = RegionEndpoint.GetBySystemName(region);
            var queue          = EnsureQueueExists(region, queueConfig);
            var eventTopic     = EnsureTopicExists(regionEndpoint, serialisationRegister, queueConfig);

            EnsureQueueIsSubscribedToTopic(regionEndpoint, eventTopic, queue);

            return(queue);
        }
 private static bool TopicExistsInAnotherAccount(SqsReadConfiguration queueConfig)
 {
     return(!string.IsNullOrWhiteSpace(queueConfig.TopicSourceAccount));
 }
 public string GetQueueName(SqsReadConfiguration sqsConfig, string messageType)
 {
     return string.IsNullOrWhiteSpace(sqsConfig.BaseQueueName) ? messageType.ToLower() : sqsConfig.BaseQueueName.ToLower();
 }
 public string GetQueueName(SqsReadConfiguration sqsConfig, string messageType)
 {
     return "test-" + messageType;
 }