public Subscribe ( SubscribeRequest request ) : SubscribeResponse | ||
request | SubscribeRequest | Container for the necessary parameters to execute the Subscribe service method. |
리턴 | SubscribeResponse |
public static void CreateEmailSubscription(string topicArn, string emailAddress) { using (var client = new AmazonSimpleNotificationServiceClient(Settings.AccessKey, Settings.Secret)) { var request = new SubscribeRequest(topicArn, "email", emailAddress); client.Subscribe(request); } }
public virtual void CreateSubscription(AmazonSimpleNotificationServiceClient snsClient, string queueArn, string topicArn) { // Create the request var subscriptionRequest = new SubscribeRequest { Endpoint = queueArn, Protocol = "sqs", TopicArn = topicArn }; // Create the subscription snsClient.Subscribe(subscriptionRequest); }
/// <summary> /// Creates a user account for SNS /// </summary> /// <param name="userName">The user to create a SNS account for</param> /// <param name="number">The user's phone number</param> private void CreateSNSAccount(String userName, String number) { AmazonSimpleNotificationServiceClient client = new AmazonSimpleNotificationServiceClient(); //Create topic first. CreateTopicRequest request = new CreateTopicRequest { Name = userName }; try { CreateTopicResponse response = client.CreateTopic(request); CreateTopicResult result = response.CreateTopicResult; String[] strings = new String[1]; strings[0] = "Success! Assigned ARN is: " + result.TopicArn + "\n"; TempData["result"] = strings; } catch (Exception e) { TempData["error"] = e.Message; } String arn = "arn:aws:sns:us-east-1:727060774285:" + userName; SetTopicAttributesRequest request2 = new SetTopicAttributesRequest { AttributeName = "DisplayName", AttributeValue = "Cookbook", TopicArn = arn }; try { SetTopicAttributesResponse response = client.SetTopicAttributes(request2); ResponseMetadata result = response.ResponseMetadata; Console.WriteLine(result.RequestId); } catch (Exception e) { Console.WriteLine(e.Message); } //Add SMS number to topic. SubscribeRequest request3 = new SubscribeRequest { TopicArn = arn, Endpoint = number, Protocol = "sms" }; try { SubscribeResponse response = client.Subscribe(request3); SubscribeResult result = response.SubscribeResult; string resultSubscribe = "Success! Subscription Arn is: " + result.SubscriptionArn + "\n"; Console.WriteLine(resultSubscribe); } catch (Exception e) { Console.WriteLine(e.Message); } }
public static void SNSCreateSubscribePublish() { #region SNSCreateSubscribePublish var snsClient = new AmazonSimpleNotificationServiceClient(); var topicRequest = new CreateTopicRequest { Name = "CodingTestResults" }; var topicResponse = snsClient.CreateTopic(topicRequest); var topicAttrRequest = new SetTopicAttributesRequest { TopicArn = topicResponse.TopicArn, AttributeName = "DisplayName", AttributeValue = "Coding Test Results" }; snsClient.SetTopicAttributes(topicAttrRequest); snsClient.Subscribe(new SubscribeRequest { Endpoint = "*****@*****.**", Protocol = "email", TopicArn = topicResponse.TopicArn }); // Wait for up to 2 minutes for the user to confirm the subscription. DateTime latest = DateTime.Now + TimeSpan.FromMinutes(2); while (DateTime.Now < latest) { var subsRequest = new ListSubscriptionsByTopicRequest { TopicArn = topicResponse.TopicArn }; var subs = snsClient.ListSubscriptionsByTopic(subsRequest).Subscriptions; var sub = subs[0]; if (!string.Equals(sub.SubscriptionArn, "PendingConfirmation", StringComparison.Ordinal)) { break; } // Wait 15 seconds before trying again. System.Threading.Thread.Sleep(TimeSpan.FromSeconds(15)); } snsClient.Publish(new PublishRequest { Subject = "Coding Test Results for " + DateTime.Today.ToShortDateString(), Message = "All of today's coding tests passed.", TopicArn = topicResponse.TopicArn }); #endregion }
/// <summary> /// Utility method for creating at topic and subscribe the email address to it. /// </summary> /// <param name="emailAddress"></param> /// <returns></returns> static string CreateTopic(string emailAddress) { var snsClient = new AmazonSimpleNotificationServiceClient(); var topicArn = snsClient.CreateTopic(new CreateTopicRequest { Name = "TranscodeEvents" + UNIQUE_POSTFIX }).TopicArn; snsClient.Subscribe(new SubscribeRequest { TopicArn = topicArn, Protocol = "email", Endpoint = emailAddress }); return topicArn; }