List of usage examples for com.amazonaws.services.sns.model CreateTopicRequest CreateTopicRequest
public CreateTopicRequest()
From source file:awslabs.lab31.SolutionCode.java
License:Open Source License
@Override public String createTopic(AmazonSNSClient snsClient, String topicName) { // TODO: Construct a CreateTopicRequest object using the specified topic name. CreateTopicRequest createTopicRequest = new CreateTopicRequest().withName(topicName); // TODO: Submit the request using the createTopic method of the snsClient object. CreateTopicResult createTopicResult = snsClient.createTopic(createTopicRequest); // TODO: Return the topic ARN from the request result. return createTopicResult.getTopicArn(); }
From source file:awslabs.lab31.StudentCode.java
License:Open Source License
/** * Create an SNS topic and return the ARN for the newly created topic. Hint: Use the createTopic() method of the * client object. The ARN for the topic is contained in the response. * //from w w w .ja va 2 s . c om * @param snsClient The SNS client object. * @param topicName The name of the topic to create. * @return The ARN for the newly created topic. */ @Override public String createTopic(AmazonSNSClient snsClient, String topicName) { CreateTopicRequest request = new CreateTopicRequest().withName(topicName); CreateTopicResult result = snsClient.createTopic(request); return result.getTopicArn(); }
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 ww w .ja v a2 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.leverno.ysbos.archive.example.AmazonGlacierDownloadInventoryWithSQSPolling.java
License:Open Source License
private static void setupSNS() { CreateTopicRequest request = new CreateTopicRequest().withName(snsTopicName); CreateTopicResult result = snsClient.createTopic(request); snsTopicARN = result.getTopicArn();/* w w w .ja va2s. c o m*/ SubscribeRequest request2 = new SubscribeRequest().withTopicArn(snsTopicARN).withEndpoint(sqsQueueARN) .withProtocol("sqs"); SubscribeResult result2 = snsClient.subscribe(request2); snsSubscriptionARN = result2.getSubscriptionArn(); }
From source file:com.oneops.antenna.senders.aws.SNSService.java
License:Apache License
/** * Sends using the sns publisher/*from w w w.ja va2 s .c o m*/ */ @Override public boolean postMessage(NotificationMessage nMsg, BasicSubscriber subscriber) { SNSSubscriber sub; if (subscriber instanceof SNSSubscriber) { sub = (SNSSubscriber) subscriber; } else { throw new ClassCastException("invalid subscriber " + subscriber.getClass().getName()); } SNSMessage msg = buildSNSMessage(nMsg); AmazonSNS sns = new AmazonSNSClient(new BasicAWSCredentials(sub.getAwsAccessKey(), sub.getAwsSecretKey())); if (sub.getSnsEndpoint() != null) { sns.setEndpoint(sub.getSnsEndpoint()); } CreateTopicRequest tRequest = new CreateTopicRequest(); tRequest.setName(msg.getTopicName()); CreateTopicResult result = sns.createTopic(tRequest); PublishRequest pr = new PublishRequest(result.getTopicArn(), msg.getTxtMessage()) .withSubject(msg.getSubject()); try { PublishResult pubresult = sns.publish(pr); logger.info("Published msg with id - " + pubresult.getMessageId()); } catch (AmazonClientException ace) { logger.error(ace.getMessage()); return false; } return true; }
From source file:com.screensaver.util.AmazonSNSClientWrapper.java
License:Open Source License
private CreateTopicResult createTopic(Platform platform, String s, String platformToken, String platformApplicationArn) { CreateTopicRequest createTopicRequest = new CreateTopicRequest(); createTopicRequest.withName(Constants.SNS_TOPIC); return snsClient.createTopic(createTopicRequest); }
From source file:com.vrane.metaGlacier.gui.SNSTopic.java
/** * Creates a SNS topic.//from w w w .ja va2 s. c om * * @param topic string * @param email address to be notified when there is any event for this topic. * @return false if there is any error. * @throws Exception */ public boolean createTopic(final String topic, final String email) throws Exception { CreateTopicRequest request = new CreateTopicRequest().withName(topic); CreateTopicResult result = null; try { result = snsClient.createTopic(request); } catch (Exception e) { LGR.setUseParentHandlers(true); LGR.log(Level.SEVERE, null, e); LGR.setUseParentHandlers(false); return false; } topicARN = result.getTopicArn(); LGR.log(Level.INFO, "topic arn is {0}", topicARN); SubscribeRequest request2 = new SubscribeRequest().withTopicArn(topicARN).withEndpoint(email) .withProtocol("email"); SubscribeResult result2 = snsClient.subscribe(request2); LGR.log(Level.INFO, "subscription ARN {0}", result2.getSubscriptionArn()); return true; }
From source file:com.zotoh.cloudapi.aws.SNS.java
License:Open Source License
@Override public Topic createTopic(String topic) throws CloudException, InternalException { tstEStrArg("topic-name", topic); CreateTopicResult res = _svc.getCloud().getSNS().createTopic(new CreateTopicRequest().withName(topic)); Topic t = null;// www. j a v a 2 s. c o m if (res != null) { t = new Topic(); t.setActive(true); t.setName(res.getTopicArn()); t.setProviderOwnerId(_svc.getCloud().getContext().getAccountNumber()); t.setProviderRegionId(_svc.getCloud().getContext().getRegionId()); t.setProviderTopicId(t.getName()); } return t; }
From source file:org.transitime.maintenance.AwsGlacierInventoryRetriever.java
License:Open Source License
/** * For retrieving vault inventory. For initializing SNS for determining when * job completed. Does nothing if member snsTopicName is null. Sets members * snsTopicARN and snsSubscriptionARN.//from w w w . j a v a2s . c o m */ void setupSNS() { // If no snsTopicName setup then simply return if (snsTopicName == null) return; CreateTopicRequest request = new CreateTopicRequest().withName(snsTopicName); CreateTopicResult result = snsClient.createTopic(request); snsTopicARN = result.getTopicArn(); SubscribeRequest request2 = new SubscribeRequest().withTopicArn(snsTopicARN).withEndpoint(sqsQueueARN) .withProtocol("sqs"); SubscribeResult result2 = snsClient.subscribe(request2); snsSubscriptionARN = result2.getSubscriptionArn(); }