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); }
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))); }
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); }
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); } })); }
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); } })); }
public Task <TopicInfo> Get(Topology.Entities.Topic topic, CancellationToken cancellationToken) { return(_nameIndex.Get(topic.EntityName, key => CreateMissingTopic(topic, cancellationToken))); }
Task ClientContext.DeleteTopic(Topic topic) { return(_context.DeleteTopic(topic)); }
Task ClientContext.CreateQueueSubscription(Topic topic, Queue queue) { return(_context.CreateQueueSubscription(topic, queue)); }
Task <string> ClientContext.CreateTopic(Topic topic) { return(_context.CreateTopic(topic)); }