/** * Construct a synchronous implementation of AmazonSNS using the current builder configuration. * * @param params * Current builder configuration represented as a parameter object. * @return Fully configured implementation of AmazonSNS. */ @Override protected AmazonSNS build(AwsSyncClientParams params) { return new AmazonSNSClient(params); }
@Override public PublishResult publish(String topicArn, String message) { return publish(new PublishRequest().withTopicArn(topicArn).withMessage(message)); }
@Override public SubscribeResult subscribe(String topicArn, String protocol, String endpoint) { return subscribe(new SubscribeRequest().withTopicArn(topicArn).withProtocol(protocol).withEndpoint(endpoint)); }
/** * The Synchronous SNS client is used for creating topics and subscribing queues. */ private AmazonSNSClient createSNSClient( final Region region ) { final UsergridAwsCredentialsProvider ugProvider = new UsergridAwsCredentialsProvider(); final AmazonSNSClient sns = new AmazonSNSClient( ugProvider.getCredentials(), clientConfiguration ); sns.setRegion( region ); return sns; }
ListTopicsResult listTopicsResult = sns.listTopics(); String topicArn = null; CreateTopicResult createTopicResult = sns.createTopic( queueName ); topicArn = createTopicResult.getTopicArn();
private void init() { exceptionUnmarshallers.add(new SubscriptionLimitExceededExceptionUnmarshaller()); exceptionUnmarshallers.add(new InvalidParameterExceptionUnmarshaller()); exceptionUnmarshallers.add(new InvalidParameterValueExceptionUnmarshaller()); exceptionUnmarshallers.add(new EndpointDisabledExceptionUnmarshaller()); exceptionUnmarshallers.add(new FilterPolicyLimitExceededExceptionUnmarshaller()); exceptionUnmarshallers.add(new KMSOptInRequiredExceptionUnmarshaller()); exceptionUnmarshallers.add(new KMSAccessDeniedExceptionUnmarshaller()); exceptionUnmarshallers.add(new KMSInvalidStateExceptionUnmarshaller()); exceptionUnmarshallers.add(new NotFoundExceptionUnmarshaller()); exceptionUnmarshallers.add(new KMSDisabledExceptionUnmarshaller()); exceptionUnmarshallers.add(new KMSNotFoundExceptionUnmarshaller()); exceptionUnmarshallers.add(new TopicLimitExceededExceptionUnmarshaller()); exceptionUnmarshallers.add(new ThrottledExceptionUnmarshaller()); exceptionUnmarshallers.add(new PlatformApplicationDisabledExceptionUnmarshaller()); exceptionUnmarshallers.add(new InternalErrorExceptionUnmarshaller()); exceptionUnmarshallers.add(new KMSThrottlingExceptionUnmarshaller()); exceptionUnmarshallers.add(new AuthorizationErrorExceptionUnmarshaller()); exceptionUnmarshallers.add(new InvalidSecurityExceptionUnmarshaller()); exceptionUnmarshallers.add(new StandardErrorUnmarshaller(com.amazonaws.services.sns.model.AmazonSNSException.class)); setServiceNameIntern(DEFAULT_SIGNING_NAME); setEndpointPrefix(ENDPOINT_PREFIX); // calling this.setEndPoint(...) will also modify the signer accordingly this.setEndpoint("https://sns.us-east-1.amazonaws.com"); HandlerChainFactory chainFactory = new HandlerChainFactory(); requestHandler2s.addAll(chainFactory.newRequestHandlerChain("/com/amazonaws/services/sns/request.handlers")); requestHandler2s.addAll(chainFactory.newRequestHandler2Chain("/com/amazonaws/services/sns/request.handler2s")); requestHandler2s.addAll(chainFactory.getGlobalHandlers()); }
public void download(String vaultName, String archiveId, String downloadFilePath) { String msg = "Downloading " + archiveId + " from Glacier vault " + vaultName; System.out.println(msg); sqsClient = new AmazonSQSClient(credentials); sqsClient.setEndpoint("https://sqs." + region + ".amazonaws.com"); snsClient = new AmazonSNSClient(credentials); snsClient.setEndpoint("https://sns." + region + ".amazonaws.com"); try { ArchiveTransferManager atm = new ArchiveTransferManager(client, sqsClient, snsClient); atm.download(vaultName, archiveId, new File(downloadFilePath)); } catch (Exception e) { throw new RuntimeException("Error " + msg, e); } }
CreateTopicResult createTopicResult = sns.createTopic(createTopicRequest); sns.setTopicAttributes(setTopicAttributesRequest); sns.deleteTopic(deleteTopicRequest); logger.debug("event=delete_topic topic_arn="+arn+" user_id= " + userId); } catch (Exception ex) { ListTopicsResult listTopicResult = sns.listTopics(listTopicRequest); topics = listTopicResult.getTopics(); sns.deleteTopic(deleteTopicRequest); logger.debug("event=delete_topic topic_arn=" + (t != null ? t.getTopicArn() : "null") + " user_id= " + userId); } catch (Exception ex) { listTopicResult = sns.listTopics(listTopicRequest); topics = listTopicResult.getTopics(); GetTopicAttributesResult getTopicAttributesResult = sns.getTopicAttributes(getTopicAttributesRequest); Map<String, String> attributes = getTopicAttributesResult.getAttributes();
ListTopicsResult listResult = snsClient.listTopics(); List<Topic> topics = listResult.getTopics(); listResult = snsClient.listTopics(nextToken); topics = listResult.getTopics(); CreateTopicResult createTopicResult = snsClient.createTopic(this.snsControlTopicName); snsTopicARN = createTopicResult.getTopicArn(); snsClient.addPermission(snsTopicARN, "Permit_SNSAdd", Arrays.asList(new String[]{userARN}), Arrays.asList(new String[]{"Publish","Subscribe","Receive"})); SubscribeResult subscribeResult = snsClient.subscribe(snsTopicARN,"sqs",sqsQueueARN); snsSubscriptionARN = subscribeResult.getSubscriptionArn(); logger.info("Subscribed for messages from SNS control channel:" + snsTopicARN + " ----> SQS: "+sqsQueueARN);
try { logger.debug("destroy() unsubscribe " + this.snsSubscriptionARN); snsClient.unsubscribe(snsSubscriptionARN); } catch(Exception e) { logger.debug("destroy() error: " + e.getMessage()); try { logger.debug("destroy() " + this.snsTopicARN); snsClient.deleteTopic(this.snsTopicARN); } catch(Exception e) { logger.debug("destroy() error: " + e.getMessage());
private QueueConfig setupSNS(QueueConfig config, String snsTopicName) { CreateTopicRequest request = new CreateTopicRequest().withName(snsTopicName); CreateTopicResult result = snsClient.createTopic(request); config.snsTopicARN = result.getTopicArn(); SubscribeRequest request2 = new SubscribeRequest().withTopicArn(config.snsTopicARN).withEndpoint(config.sqsQueueARN) .withProtocol("sqs"); SubscribeResult result2 = snsClient.subscribe(request2); config.snsSubscriptionARN = result2.getSubscriptionArn(); return config; }
@Override public ListTopicsResult listTopics() { return listTopics(new ListTopicsRequest()); }
sns.subscribe(subscribeRequest); sns.unsubscribe(unsubscribeRequest); } catch (Exception ex) { logger.error("event=unsubscribe arn=" + arn , ex); listSubscriptionsByTopicResult = sns.listSubscriptionsByTopic(new ListSubscriptionsByTopicRequest(topicArn, nextToken)); subscriptions = listSubscriptionsByTopicResult.getSubscriptions();
AmazonSNSClient snsClient = new AmazonSNSClient(new DefaultAWSCredentialsProviderChain()); snsClient.setRegion(Region.getRegion(Regions.US_WEST_2)); List<Topic> topicArns = new ArrayList<>(); ListTopicsResult result = snsClient.listTopics(); topicArns.addAll(result.getTopics()); while (result.getNextToken() != null) { result = snsClient.listTopics(result.getNextToken()); topicArns.addAll(result.getTopics()); } for (Topic topic : topicArns) { System.out.println(topic.getTopicArn()); } snsClient.shutdown();
private void updateSNSFunction(Arn bindingArn, LambdaFunctionDefinition d) throws Exception { AmazonSNSClient client = createServiceFor(AmazonSNSClient.class); client.setRegion(Region.getRegion(Regions.fromName(bindingArn.getRegion()))); SubscribeRequest req = new SubscribeRequest().withTopicArn(bindingArn.getSourceArn()).withProtocol("lambda").withEndpoint(d.getArn()); final SubscribeResult subscribe = client.subscribe(req); getLog().info("Subscribed topic arn " + bindingArn.getSourceArn() + " to function " + d.getArn() + ": " + subscribe); // TODO: Unsubscribe older versions }
@Override public CreateTopicResult createTopic(String name) { return createTopic(new CreateTopicRequest().withName(name)); }
@Override public DeleteTopicResult deleteTopic(String topicArn) { return deleteTopic(new DeleteTopicRequest().withTopicArn(topicArn)); }
@Override public UnsubscribeResult unsubscribe(String subscriptionArn) { return unsubscribe(new UnsubscribeRequest().withSubscriptionArn(subscriptionArn)); }
private void init() { exceptionUnmarshallers.add(new AuthorizationErrorExceptionUnmarshaller()); exceptionUnmarshallers.add(new EndpointDisabledExceptionUnmarshaller()); exceptionUnmarshallers.add(new InternalErrorExceptionUnmarshaller()); exceptionUnmarshallers.add(new InvalidParameterExceptionUnmarshaller()); exceptionUnmarshallers.add(new InvalidParameterValueExceptionUnmarshaller()); exceptionUnmarshallers.add(new NotFoundExceptionUnmarshaller()); exceptionUnmarshallers.add(new PlatformApplicationDisabledExceptionUnmarshaller()); exceptionUnmarshallers.add(new SubscriptionLimitExceededExceptionUnmarshaller()); exceptionUnmarshallers.add(new ThrottledExceptionUnmarshaller()); exceptionUnmarshallers.add(new TopicLimitExceededExceptionUnmarshaller()); exceptionUnmarshallers.add(new StandardErrorUnmarshaller()); // calling this.setEndPoint(...) will also modify the signer accordingly this.setEndpoint("sns.us-east-1.amazonaws.com"); this.endpointPrefix = "sns"; HandlerChainFactory chainFactory = new HandlerChainFactory(); requestHandler2s.addAll(chainFactory.newRequestHandlerChain( "/com/amazonaws/services/sns/request.handlers")); requestHandler2s.addAll(chainFactory.newRequestHandler2Chain( "/com/amazonaws/services/sns/request.handler2s")); }
public void inventory(String vaultName, String snsTopicName, String sqsQueueName, String fileName) { String msg = "Requesting inventory from Glacier vault " + vaultName + ". It might take around 4 hours."; System.out.println(msg); sqsClient = new AmazonSQSClient(credentials); sqsClient.setEndpoint("https://sqs." + region + ".amazonaws.com"); snsClient = new AmazonSNSClient(credentials); snsClient.setEndpoint("https://sns." + region + ".amazonaws.com"); try { QueueConfig config = setupSQS(sqsQueueName); config = setupSNS(config, snsTopicName); String jobId = initiateJobRequest(vaultName, config.snsTopicARN); System.out.println("Jobid = " + jobId); Boolean success = waitForJobToComplete(jobId, config.sqsQueueURL); if (!success) { throw new Exception("Job did not complete successfully."); } downloadJobOutput(vaultName, jobId, fileName); cleanUp(config); } catch (Exception e) { System.err.println("Archive retrieval failed."); System.err.println(e); } }