com.amazonaws.services.sns.model.CreateTopicRequest Java Examples
The following examples show how to use
com.amazonaws.services.sns.model.CreateTopicRequest.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AwsGlacierInventoryRetriever.java From core with GNU General Public License v3.0 | 6 votes |
/** * For retrieving vault inventory. For initializing SNS for determining when * job completed. Does nothing if member snsTopicName is null. Sets members * snsTopicARN and snsSubscriptionARN. */ 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(); }
Example #2
Source File: DynamicTopicDestinationResolver.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Override public String resolveDestination(String name) throws DestinationResolutionException { if (this.autoCreate) { return this.amazonSns.createTopic(new CreateTopicRequest(name)).getTopicArn(); } else { String physicalTopicName = name; if (this.resourceIdResolver != null) { physicalTopicName = this.resourceIdResolver .resolveToPhysicalResourceId(name); } if (physicalTopicName != null && AmazonResourceName.isValidAmazonResourceName(physicalTopicName)) { return physicalTopicName; } String topicArn = getTopicResourceName(null, physicalTopicName); if (topicArn == null) { throw new IllegalArgumentException("No Topic with name: '" + name + "' found. Please use " + "the right topic name or enable auto creation of topics for this DestinationResolver"); } return topicArn; } }
Example #3
Source File: DynamicTopicDestinationResolverTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void resolveDestination_withAutoCreateEnabled_shouldCreateTopicDirectly() throws Exception { // Arrange String topicArn = "arn:aws:sns:eu-west:123456789012:test"; AmazonSNS sns = mock(AmazonSNS.class); when(sns.createTopic(new CreateTopicRequest("test"))) .thenReturn(new CreateTopicResult().withTopicArn(topicArn)); DynamicTopicDestinationResolver resolver = new DynamicTopicDestinationResolver( sns); resolver.setAutoCreate(true); // Act String resolvedDestinationName = resolver.resolveDestination("test"); // Assert assertThat(resolvedDestinationName).isEqualTo(topicArn); }
Example #4
Source File: SnsWebhookManager.java From Singularity with Apache License 2.0 | 6 votes |
private String getOrCreateSnsTopic(WebhookType type) { return typeToArn.computeIfAbsent( type, t -> { String topic = webhookConf.getSnsTopics().get(type); try { LOG.info("Attempting to create sns topic {}", topic); CreateTopicRequest createTopicRequest = new CreateTopicRequest(topic); CreateTopicResult createTopicResult = snsClient.createTopic(createTopicRequest); return createTopicResult.getTopicArn(); } catch (Throwable th) { LOG.error("Could not create sns topic {}", topic, th); throw th; } } ); }
Example #5
Source File: SnsExecutor.java From spring-integration-aws with MIT License | 6 votes |
private void createTopicIfNotExists() { for (Topic topic : client.listTopics().getTopics()) { if (topic.getTopicArn().contains(topicName)) { topicArn = topic.getTopicArn(); break; } } if (topicArn == null) { CreateTopicRequest request = new CreateTopicRequest(topicName); CreateTopicResult result = client.createTopic(request); topicArn = result.getTopicArn(); log.debug("Topic created, arn: " + topicArn); } else { log.debug("Topic already created: " + topicArn); } }
Example #6
Source File: SNSService.java From oneops with Apache License 2.0 | 5 votes |
/** * Sends using the sns publisher */ @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; }
Example #7
Source File: SNSImpl.java From aws-sdk-java-resources with Apache License 2.0 | 5 votes |
@Override public Topic createTopic(CreateTopicRequest request, ResultCapture<CreateTopicResult> extractor) { ActionResult result = service.performAction("CreateTopic", request, extractor); if (result == null) return null; return new TopicImpl(result.getResource()); }
Example #8
Source File: SNSImpl.java From aws-sdk-java-resources with Apache License 2.0 | 5 votes |
@Override public Topic createTopic(String name, ResultCapture<CreateTopicResult> extractor) { CreateTopicRequest request = new CreateTopicRequest() .withName(name); return createTopic(request, extractor); }
Example #9
Source File: SNSImpl.java From aws-sdk-java-resources with Apache License 2.0 | 4 votes |
@Override public Topic createTopic(CreateTopicRequest request) { return createTopic(request, null); }
Example #10
Source File: SNS.java From aws-sdk-java-resources with Apache License 2.0 | 2 votes |
/** * Performs the <code>CreateTopic</code> action. * * <p> * * @return The <code>Topic</code> resource object associated with the result * of this action. * @see CreateTopicRequest */ com.amazonaws.resources.sns.Topic createTopic(CreateTopicRequest request);
Example #11
Source File: SNS.java From aws-sdk-java-resources with Apache License 2.0 | 2 votes |
/** * Performs the <code>CreateTopic</code> action and use a ResultCapture to * retrieve the low-level client response. * * <p> * * @return The <code>Topic</code> resource object associated with the result * of this action. * @see CreateTopicRequest */ com.amazonaws.resources.sns.Topic createTopic(CreateTopicRequest request, ResultCapture<CreateTopicResult> extractor);