Esempio n. 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);
        }
Esempio n. 2
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);
        }