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

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

Introduction

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

Prototype


public SubscribeRequest withProtocol(String protocol) 

Source Link

Document

The protocol you want to use.

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) {/* w  ww .  j  av  a  2 s.  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;
}