Search in sources :

Example 1 with ListSubscriptionsByTopicRequest

use of software.amazon.awssdk.services.sns.model.ListSubscriptionsByTopicRequest in project aws-doc-sdk-examples by awsdocs.

the class SnsService method getTopicArnValue.

// Returns the Sub ARN based on the given endpoint
private String getTopicArnValue(String endpoint) {
    SnsClient snsClient = getSnsClient();
    try {
        String subArn = "";
        ListSubscriptionsByTopicRequest request = ListSubscriptionsByTopicRequest.builder().topicArn(topicArn).build();
        ListSubscriptionsByTopicResponse result = snsClient.listSubscriptionsByTopic(request);
        List<Subscription> allSubs = result.subscriptions();
        for (Subscription sub : allSubs) {
            if (sub.endpoint().compareTo(endpoint) == 0) {
                subArn = sub.subscriptionArn();
                return subArn;
            }
        }
    } catch (SnsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    return "";
}
Also used : SnsClient(software.amazon.awssdk.services.sns.SnsClient) ListSubscriptionsByTopicRequest(software.amazon.awssdk.services.sns.model.ListSubscriptionsByTopicRequest)

Example 2 with ListSubscriptionsByTopicRequest

use of software.amazon.awssdk.services.sns.model.ListSubscriptionsByTopicRequest in project aws-doc-sdk-examples by awsdocs.

the class SnsService method getAllSubscriptions.

public String getAllSubscriptions() {
    List subList = new ArrayList<String>();
    try {
        SnsClient snsClient = getSnsClient();
        ListSubscriptionsByTopicRequest request = ListSubscriptionsByTopicRequest.builder().topicArn(topicArn).build();
        ListSubscriptionsByTopicResponse result = snsClient.listSubscriptionsByTopic(request);
        List<Subscription> allSubs = result.subscriptions();
        for (Subscription sub : allSubs) {
            subList.add(sub.endpoint());
        }
    } catch (SnsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    return convertToString(toXml(subList));
}
Also used : SnsClient(software.amazon.awssdk.services.sns.SnsClient) ListSubscriptionsByTopicRequest(software.amazon.awssdk.services.sns.model.ListSubscriptionsByTopicRequest) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

SnsClient (software.amazon.awssdk.services.sns.SnsClient)2 ListSubscriptionsByTopicRequest (software.amazon.awssdk.services.sns.model.ListSubscriptionsByTopicRequest)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1