Example usage for com.amazonaws.services.sns AmazonSNSClient listSubscriptionsByTopic

List of usage examples for com.amazonaws.services.sns AmazonSNSClient listSubscriptionsByTopic

Introduction

In this page you can find the example usage for com.amazonaws.services.sns AmazonSNSClient listSubscriptionsByTopic.

Prototype

@Override
    public ListSubscriptionsByTopicResult listSubscriptionsByTopic(String topicArn) 

Source Link

Usage

From source file:awslabs.lab31.SolutionCode.java

License:Open Source License

@Override
public void deleteSubscriptions(AmazonSNSClient snsClient, String topicArn) {
    // TODO: Construct a ListSubscriptionsByTopicRequest object using the provided topic ARN.
    ListSubscriptionsByTopicRequest listSubscriptionsByTopicRequest = new ListSubscriptionsByTopicRequest()
            .withTopicArn(topicArn);/*w  w w .  j  a va2  s  . c o  m*/

    // TODO: Submit the request using the listSubscriptionsByTopic method of the snsClient object.
    ListSubscriptionsByTopicResult listSubscriptionsByTopicResult = snsClient
            .listSubscriptionsByTopic(listSubscriptionsByTopicRequest);

    // TODO: Iterate over the subscriptions in the request result.
    // TODO: For each subscription, construct an UnsubscribeRequest object using the subscription ARN.
    // TODO: For each unsubscribe request, submit it using the unsubscribe method of the snsClient object.
    for (Subscription subscription : listSubscriptionsByTopicResult.getSubscriptions()) {
        UnsubscribeRequest unsubscribeRequest = new UnsubscribeRequest()
                .withSubscriptionArn(subscription.getSubscriptionArn());
        snsClient.unsubscribe(unsubscribeRequest);
    }
}

From source file:awslabs.lab31.StudentCode.java

License:Open Source License

/**
 * Delete all subscriptions to the specified SNS topic. Hint: Call getSubscriptions() on the client object to get
 * all of the subscriptions and loop through them calling the client object's unsubscribe() method with details of
 * each subscription.//from w  ww.j  a  v  a2  s. c o m
 * 
 * @param snsClient The SNS client object.
 * @param topicArn The SNS topic to remove the subscriptions from.
 */
@Override
public void deleteSubscriptions(AmazonSNSClient snsClient, String topicArn) {
    ListSubscriptionsByTopicRequest request = new ListSubscriptionsByTopicRequest(topicArn);
    ListSubscriptionsByTopicResult result = snsClient.listSubscriptionsByTopic(request);

    for (Subscription s : result.getSubscriptions()) {
        UnsubscribeRequest unsubscribeRequest = new UnsubscribeRequest(s.getSubscriptionArn());
        snsClient.unsubscribe(unsubscribeRequest);
    }
}