Example usage for com.amazonaws.services.sns.model SubscribeRequest withTopicArn

List of usage examples for com.amazonaws.services.sns.model SubscribeRequest withTopicArn

Introduction

In this page you can find the example usage for com.amazonaws.services.sns.model SubscribeRequest withTopicArn.

Prototype


public SubscribeRequest withTopicArn(String topicArn) 

Source Link

Document

The ARN of the topic you want to subscribe to.

Usage

From source file:com.connexience.server.model.archive.glacier.SetupUtils.java

License:Open Source License

public static String setupSNS(String accessKey, String secretKey, String domainName, String vaultName,
        String queueARN) {/*from w  w  w  . j  av a 2s.c  o m*/
    String topicARN = null;
    try {
        AWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey);

        AmazonSNSClient amazonSNSClient = new AmazonSNSClient(awsCredentials);
        amazonSNSClient.setEndpoint("https://sns." + domainName + ".amazonaws.com/");

        String topicName = vaultName + "-inkspot_glacier-topic";
        CreateTopicRequest createTopicRequest = new CreateTopicRequest();
        createTopicRequest.withName(topicName);

        CreateTopicResult createTopicResult = amazonSNSClient.createTopic(createTopicRequest);
        if (createTopicResult != null) {
            topicARN = createTopicResult.getTopicArn();

            SubscribeRequest subscribeRequest = new SubscribeRequest();
            subscribeRequest.withTopicArn(topicARN);
            subscribeRequest.withProtocol("sqs");
            subscribeRequest.withEndpoint(queueARN);

            SubscribeResult subscribeResult = amazonSNSClient.subscribe(subscribeRequest);
            if (subscribeResult == null)
                logger.warn("Unable to subscribe topic: \"" + topicName + "\" to queue: \"" + queueARN + "\"");
        } else
            logger.warn("Unable to create topic: \"" + topicName + "\"");

        amazonSNSClient.shutdown();
    } catch (AmazonServiceException amazonServiceException) {
        logger.warn("AmazonServiceException: " + amazonServiceException);
        logger.debug(amazonServiceException);
    } catch (IllegalArgumentException illegalArgumentException) {
        logger.warn("IllegalArgumentException: " + illegalArgumentException);
        logger.debug(illegalArgumentException);
    } catch (AmazonClientException amazonClientException) {
        logger.warn("AmazonClientException: " + amazonClientException);
        logger.debug(amazonClientException);
    } catch (Throwable throwable) {
        logger.warn("Throwable: " + throwable);
        logger.debug(throwable);
    }

    return topicARN;
}