private string FindTopicArn(AWSCredentials credentials, RegionEndpoint region, string topicName) { var snsClient = new AmazonSimpleNotificationServiceClient(credentials, region); var topicResponse = snsClient.FindTopicAsync(topicName).GetAwaiter().GetResult(); return(topicResponse.TopicArn); }
/// <summary> /// Send message /// </summary> /// <param name="topicName"></param> /// <param name="message"></param> /// <param name="token"></param> /// <returns></returns> public async Task SendAsync(string topicName, string message, CancellationToken token) { using (var client = new AmazonSimpleNotificationServiceClient(accessKey, secretKey, region)) { var topic = await client.FindTopicAsync(topicName); var req = new PublishRequest(topic.TopicArn, message); await client.PublishAsync(req, token); } }
private string FindTopicArnByName(RoutingKey topicName) { using (var snsClient = new AmazonSimpleNotificationServiceClient(_awsConnection.Credentials, _awsConnection.Region)) { var topic = snsClient.FindTopicAsync(topicName.Value).GetAwaiter().GetResult(); if (topic == null) { throw new BrokerUnreachableException($"Unable to find a Topic ARN for {topicName.Value}"); } return(topic.TopicArn); } }
private async Task <String> GetTopicArn(String topic) { var amazonTopic = await amazonSnsClient.FindTopicAsync(topic); if (amazonTopic != null) { return(amazonTopic.TopicArn); } var createTopicResponse = await amazonSnsClient.CreateTopicAsync(new CreateTopicRequest() { Name = topic }); return(createTopicResponse.TopicArn); }
//Note that we assume here that topic names are globally unique, if not provide the topic ARN directly in the SNSAttributes of the subscription private static (bool success, string topicArn) FindTopicByName(RoutingKey topicName, AmazonSimpleNotificationServiceClient snsClient) { var topic = snsClient.FindTopicAsync(topicName.Value).GetAwaiter().GetResult(); return(topic != null, topic?.TopicArn); }
//Note that we assume here that topic names are globally unique, if not provide the topic ARN directly in the SNSAttributes of the subscription //This approach can have be rate throttled at scale. AWS limits to 30 ListTopics calls per second, so it you have a lot of clients starting //you may run into issues public (bool, string TopicArn) Validate(string topicName) { var topic = _snsClient.FindTopicAsync(topicName).GetAwaiter().GetResult(); return(topic != null, topic?.TopicArn); }