예제 #1
0
        async Task <TopicInfo> CreateMissingTopic(Topology.Entities.Topic topic, CancellationToken cancellationToken)
        {
            Dictionary <string, string> attributes = topic.TopicAttributes.ToDictionary(x => x.Key, x => x.Value.ToString());

            var request = new CreateTopicRequest(topic.EntityName)
            {
                Attributes = attributes,
                Tags       = topic.TopicTags.Select(x => new Tag
                {
                    Key   = x.Key,
                    Value = x.Value
                }).ToList()
            };

            var response = await _client.CreateTopicAsync(request, cancellationToken).ConfigureAwait(false);

            response.EnsureSuccessfulResponse();

            var topicArn = response.TopicArn;

            var attributesResponse = await _client.GetTopicAttributesAsync(topicArn, cancellationToken).ConfigureAwait(false);

            attributesResponse.EnsureSuccessfulResponse();

            var missingTopic = new TopicInfo(topic.EntityName, topicArn, attributesResponse.Attributes);

            if (topic.Durable && topic.AutoDelete == false)
            {
                lock (_durableTopics)
                    _durableTopics[missingTopic.EntityName] = missingTopic;
            }

            return(missingTopic);
        }
예제 #2
0
        public Task <TopicInfo> Get(Topology.Entities.Topic topic, CancellationToken cancellationToken)
        {
            lock (_durableTopics)
                if (_durableTopics.TryGetValue(topic.EntityName, out var queueInfo))
                {
                    return(Task.FromResult(queueInfo));
                }

            return(_nameIndex.Get(topic.EntityName, key => CreateMissingTopic(topic, cancellationToken)));
        }
예제 #3
0
        async Task <TopicInfo> CreateMissingTopic(Topology.Entities.Topic topic, CancellationToken cancellationToken)
        {
            Dictionary <string, string> attributes = topic.TopicAttributes.ToDictionary(x => x.Key, x => x.Value.ToString());

            var request = new CreateTopicRequest(topic.EntityName)
            {
                Attributes = attributes,
                Tags       = topic.TopicTags.Select(x => new Tag
                {
                    Key   = x.Key,
                    Value = x.Value
                }).ToList()
            };
            var topicArn = string.Empty;
            var doesTopicExistResponse = await _client.GetTopicAttributesAsync(topic.EntityName).ConfigureAwait(false);

            if (doesTopicExistResponse.DoesQueueExists())
            {
                topicArn = doesTopicExistResponse.Attributes
                           .First(t =>
                                  t.Key.Equals("TopicArn", System.StringComparison.InvariantCultureIgnoreCase))
                           .Value;
            }
            var response = await _client.CreateTopicAsync(request, cancellationToken).ConfigureAwait(false);

            response.EnsureSuccessfulResponse();

            topicArn = response.TopicArn;

            var attributesResponse = await _client.GetTopicAttributesAsync(topicArn, cancellationToken).ConfigureAwait(false);

            attributesResponse.EnsureSuccessfulResponse();

            var missingTopic = new TopicInfo(topic.EntityName, topicArn, attributesResponse.Attributes);

            if (topic.Durable && topic.AutoDelete == false)
            {
                lock (_durableTopics)
                    _durableTopics[missingTopic.EntityName] = missingTopic;
            }

            return(missingTopic);
        }
예제 #4
0
        public Task <TopicInfo> Get(Topology.Entities.Topic topic)
        {
            lock (_durableTopics)
            {
                if (_durableTopics.TryGetValue(topic.EntityName, out var queueInfo))
                {
                    return(Task.FromResult(queueInfo));
                }
            }

            return(_nameIndex.Get(topic.EntityName, async key =>
            {
                try
                {
                    return await CreateMissingTopic(topic).ConfigureAwait(false);
                }
                catch (InvalidParameterException e) when(e.Message.Contains("Topic already exists"))
                {
                    return await GetExistingTopic(topic.EntityName).ConfigureAwait(false);
                }
            }));
        }
예제 #5
0
        public Task <TopicInfo> Get(Topology.Entities.Topic topic)
        {
            lock (_durableTopics)
            {
                if (_durableTopics.TryGetValue(topic.EntityName, out var queueInfo))
                {
                    return(Task.FromResult(queueInfo));
                }
            }

            return(_nameIndex.Get(topic.EntityName, async key =>
            {
                try
                {
                    return await GetExistingTopic(topic.EntityName).ConfigureAwait(false);
                }
                catch (AmazonSqsTransportException e) when(e.Message.Equals($"Topic {topic.EntityName} not found."))
                {
                    return await CreateMissingTopic(topic).ConfigureAwait(false);
                }
            }));
        }
예제 #6
0
 public Task <TopicInfo> Get(Topology.Entities.Topic topic, CancellationToken cancellationToken)
 {
     return(_nameIndex.Get(topic.EntityName, key => CreateMissingTopic(topic, cancellationToken)));
 }
예제 #7
0
 Task ClientContext.DeleteTopic(Topic topic)
 {
     return(_context.DeleteTopic(topic));
 }
예제 #8
0
 Task ClientContext.CreateQueueSubscription(Topic topic, Queue queue)
 {
     return(_context.CreateQueueSubscription(topic, queue));
 }
예제 #9
0
 Task <string> ClientContext.CreateTopic(Topic topic)
 {
     return(_context.CreateTopic(topic));
 }