software.amazon.awssdk.services.sns.model.CreateTopicRequest Java Examples
The following examples show how to use
software.amazon.awssdk.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: SnsConnector.java From smallrye-reactive-messaging with Apache License 2.0 | 6 votes |
/** * Send message to the SNS Topic. * * @param message Message to be sent, must not be {@code null} * @return the CompletionStage of sending message. */ private CompletionStage<Message<?>> send(Message<?> message, String topic, String snsUrl, boolean mock) { SnsClientConfig clientConfig = new SnsClientConfig(snsUrl, mock); SnsAsyncClient client = SnsClientManager.get().getAsyncClient(clientConfig); CreateTopicRequest topicCreationRequest = CreateTopicRequest.builder().name(topic).build(); return client.createTopic(topicCreationRequest) .thenApply(CreateTopicResponse::topicArn) .thenCompose(arn -> client.publish(PublishRequest .builder() .topicArn(arn) .message((String) message.getPayload()) .build())) .thenApply(resp -> { log.successfullySend(resp.messageId()); return message; }); }
Example #2
Source File: SnsPolicyIntegrationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
/** * Tests that we can construct valid policies with Sns specific conditions/resources/etc. */ @Test public void testPolicies() throws Exception { String topicName = "java-sns-policy-integ-test-" + System.currentTimeMillis(); topicArn = sns.createTopic(CreateTopicRequest.builder().name(topicName).build()).topicArn(); Policy policy = new Policy() .withStatements(new Statement(Effect.Allow) .withActions(new Action("sns:Subscribe")) .withPrincipals(Principal.ALL_USERS) .withResources(new Resource(topicArn)) .withConditions(new StringCondition(StringComparisonType.StringLike, "sns:Endpoint", "*@amazon.com"), new StringCondition(StringComparisonType.StringEquals, "sns:Protocol", "email"))); sns.setTopicAttributes(SetTopicAttributesRequest.builder() .topicArn(topicArn) .attributeName("Policy") .attributeValue(policy.toJson()) .build()); }
Example #3
Source File: CreateTopic.java From aws-doc-sdk-examples with Apache License 2.0 | 6 votes |
public static String createSNSTopic(SnsClient snsClient, String topicName ) { CreateTopicResponse result = null; try { CreateTopicRequest request = CreateTopicRequest.builder() .name(topicName) .build(); result = snsClient.createTopic(request); return result.topicArn(); } catch (SnsException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return ""; //snippet-end:[sns.java2.CreateTopic.main] }
Example #4
Source File: ServiceIntegrationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
private void setupResources() throws IOException, Exception { s3.createBucket(CreateBucketRequest.builder().bucket(BUCKET_NAME).build()); topicArn = sns.createTopic(CreateTopicRequest.builder().name(TOPIC_NAME).build()).topicArn(); policyArn = createPolicy(); roleArn = createRole(); iam.attachRolePolicy(AttachRolePolicyRequest.builder().roleName(ROLE_NAME).policyArn(policyArn).build()); }
Example #5
Source File: SNSIntegrationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
/** * Tests that we can correctly handle exceptions from SNS. */ @Test public void testCloudcastExceptionHandling() { try { sns.createTopic(CreateTopicRequest.builder().name("").build()); } catch (AwsServiceException exception) { assertEquals("InvalidParameter", exception.awsErrorDetails().errorCode()); assertTrue(exception.getMessage().length() > 5); assertTrue(exception.requestId().length() > 5); assertThat(exception.awsErrorDetails().serviceName()).isEqualTo("Sns"); assertEquals(400, exception.statusCode()); } }
Example #6
Source File: AutoScalingIntegrationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
/** * Tests that we can invoke the notification related operations correctly. */ @Test public void testNotificationOperations() throws Exception { autoScalingGroupName = "java-integ-test-scaling-group-" + new Date().getTime(); launchConfigurationName = "java-integ-test-launch-configuration-" + new Date().getTime(); createLaunchConfiguration(launchConfigurationName); // Create an AutoScalingGroup CreateAutoScalingGroupRequest createRequest = CreateAutoScalingGroupRequest.builder() .autoScalingGroupName(autoScalingGroupName).launchConfigurationName(launchConfigurationName) .availabilityZones(AVAILABILITY_ZONE).maxSize(2).minSize(1) .build(); autoscaling.createAutoScalingGroup(createRequest); // Describe Notification Types List<String> notificationTypes = autoscaling.describeAutoScalingNotificationTypes(DescribeAutoScalingNotificationTypesRequest.builder().build()) .autoScalingNotificationTypes(); assertTrue(notificationTypes.size() > 1); String notificationType = notificationTypes.get(0); assertNotEmpty(notificationType); // PutNotificationConfiguration topicARN = sns.createTopic(CreateTopicRequest.builder().name("java-sdk-autoscaling-integ-test-" + System.currentTimeMillis()).build()).topicArn(); PutNotificationConfigurationRequest putRequest = PutNotificationConfigurationRequest.builder() .autoScalingGroupName(autoScalingGroupName).notificationTypes(notificationType) .topicARN(topicARN).build(); autoscaling.putNotificationConfiguration(putRequest); // DescribeNotificationConfiguration DescribeNotificationConfigurationsRequest describeRequest = DescribeNotificationConfigurationsRequest.builder() .autoScalingGroupNames(autoScalingGroupName).build(); List<NotificationConfiguration> notificationConfigurations = autoscaling.describeNotificationConfigurations( describeRequest).notificationConfigurations(); assertEquals(1, notificationConfigurations.size()); assertEquals(autoScalingGroupName, notificationConfigurations.get(0).autoScalingGroupName()); assertEquals(notificationType, notificationConfigurations.get(0).notificationType()); assertEquals(topicARN, notificationConfigurations.get(0).topicARN()); // DeleteNotificationConfiguration autoscaling.deleteNotificationConfiguration(DeleteNotificationConfigurationRequest.builder() .autoScalingGroupName(autoScalingGroupName) .topicARN(topicARN).build()); assertEquals(0, autoscaling.describeNotificationConfigurations(describeRequest).notificationConfigurations() .size()); }