List of usage examples for com.amazonaws.services.sns.model SubscribeRequest withEndpoint
public SubscribeRequest withEndpoint(String endpoint)
The endpoint that you want to receive notifications.
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 w w . java 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; }
From source file:com.pocketdealhunter.HotDealsMessagesUtil.java
License:Open Source License
protected void subscribeQueue() { try {/*w w w. j a v a 2s. c o m*/ String queueArn = this.getQueueArn(this.queueUrl); SubscribeRequest request = new SubscribeRequest(); request.withEndpoint(queueArn).withProtocol("sqs").withTopicArn(this.topicARN); this.snsClient.subscribe(request); } catch (Exception exception) { System.out.println("Exception = " + exception); } }