예제 #1
0
        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);
        }
        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);
        }
예제 #3
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));
        }
        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 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);
        }
예제 #6
0
        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);
        }