ListSubscriptionsByTopic() public method

Returns a list of the subscriptions to a specific topic. Each call returns a limited list of subscriptions, up to 100. If there are more subscriptions, a NextToken is also returned. Use the NextToken parameter in a new ListSubscriptionsByTopic call to get further results.
/// Indicates that the user has been denied access to the requested resource. /// /// Indicates an internal service error. /// /// Indicates that a request parameter does not comply with the associated constraints. /// /// Indicates that the requested resource does not exist. ///
public ListSubscriptionsByTopic ( ListSubscriptionsByTopicRequest request ) : ListSubscriptionsByTopicResponse
request Amazon.SimpleNotificationService.Model.ListSubscriptionsByTopicRequest Container for the necessary parameters to execute the ListSubscriptionsByTopic service method.
return Amazon.SimpleNotificationService.Model.ListSubscriptionsByTopicResponse
Exemplo n.º 1
0
        public static IEnumerable<Subscription> ListSubscriptions(string topicArn)
        {
            using (var client = new AmazonSimpleNotificationServiceClient(Settings.AccessKey, Settings.Secret))
            {
                var request = new ListSubscriptionsByTopicRequest(topicArn);

                return client.ListSubscriptionsByTopic(request).Subscriptions;
            }
        }
Exemplo n.º 2
0
        public virtual void DeleteSubscriptions(AmazonSimpleNotificationServiceClient snsClient, string topicArn)
        {
            var listSubscriptionsByTopicRequest = new ListSubscriptionsByTopicRequest
            {
                TopicArn = topicArn
            };

            ListSubscriptionsByTopicResponse listSubscriptionsByTopicResponse =
                snsClient.ListSubscriptionsByTopic(listSubscriptionsByTopicRequest);

            foreach (
                Subscription subscription in
                    listSubscriptionsByTopicResponse.Subscriptions)
            {
                var unsubscribeRequest = new UnsubscribeRequest
                {
                    SubscriptionArn = subscription.SubscriptionArn
                };
                snsClient.Unsubscribe(unsubscribeRequest);
            }
        }
Exemplo n.º 3
0
    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
    }
Exemplo n.º 4
0
    public static void SNSListSubscriptionsByTopic()
    {
      #region SNSListSubscriptionsByTopic
      var snsClient = new AmazonSimpleNotificationServiceClient();
      var request = new ListSubscriptionsByTopicRequest();
      var response = new ListSubscriptionsByTopicResponse();

      request.TopicArn = "arn:aws:sns:us-east-1:80398EXAMPLE:CodingTestResults";

      do
      {
        response = snsClient.ListSubscriptionsByTopic(request);

        foreach (var sub in response.Subscriptions)
        {
          Console.WriteLine("Subscription: {0}", sub.SubscriptionArn);

          var subAttrs = snsClient.GetSubscriptionAttributes(
            new GetSubscriptionAttributesRequest
            {
              SubscriptionArn = sub.SubscriptionArn
            }).Attributes;

          if (subAttrs.Count > 0)
          {
            foreach (var subAttr in subAttrs)
            {
              Console.WriteLine(" -{0} : {1}", subAttr.Key, subAttr.Value);
            }
          }

          Console.WriteLine();
        }

        request.NextToken = response.NextToken;

      } while (!string.IsNullOrEmpty(response.NextToken));
      #endregion

      Console.ReadLine();
    }