Example usage for com.amazonaws.services.sns AmazonSNS listTopics

List of usage examples for com.amazonaws.services.sns AmazonSNS listTopics

Introduction

In this page you can find the example usage for com.amazonaws.services.sns AmazonSNS listTopics.

Prototype

ListTopicsResult listTopics();

Source Link

Document

Simplified method form for invoking the ListTopics operation.

Usage

From source file:com.netflix.spinnaker.front50.model.TemporarySQSQueue.java

License:Apache License

private String getSnsTopicArn(AmazonSNS amazonSNS, String topicName) {
    ListTopicsResult listTopicsResult = amazonSNS.listTopics();
    String nextToken = listTopicsResult.getNextToken();
    List<Topic> topics = listTopicsResult.getTopics();

    while (nextToken != null) {
        listTopicsResult = amazonSNS.listTopics(nextToken);
        nextToken = listTopicsResult.getNextToken();
        topics.addAll(listTopicsResult.getTopics());
    }//from w w w.j av a2s  . c  o  m

    return topics.stream().filter(t -> t.getTopicArn().toLowerCase().endsWith(":" + topicName.toLowerCase()))
            .map(Topic::getTopicArn).findFirst().orElseThrow(
                    () -> new IllegalArgumentException("No SNS topic found (topicName: " + topicName + ")"));
}

From source file:net.smartcosmos.plugin.service.aws.notification.AwsNotificationService.java

License:Apache License

@Override
public boolean isHealthy() {
    try {// w ww .  j  a  va2  s .c o m
        AmazonSNS sns = new AmazonSNSClient(credentials);
        Region usEast1 = Region.getRegion(Regions.US_EAST_1);
        sns.setRegion(usEast1);
        sns.listTopics();
        return true;
    } catch (Exception e) {
        return false;
    }
}