Search in sources :

Example 6 with CreateTopicRequest

use of com.amazonaws.services.sns.model.CreateTopicRequest in project Synapse-Stack-Builder by Sage-Bionetworks.

the class EnvironmentInstancesNotificationSetupTest method testSetupResources.

@Test
public void testSetupResources() throws InterruptedException {
    CreateTopicRequest expectedReqPortal = expectedReq(StackEnvironmentType.PORTAL, config.getEnvironmentInstanceNotificationTopicName(StackEnvironmentType.PORTAL));
    CreateTopicResult expectedResPortal = setupExpectedRes(StackEnvironmentType.PORTAL, expectedReqPortal);
    CreateTopicRequest expectedReqRepo = expectedReq(StackEnvironmentType.REPO, config.getEnvironmentInstanceNotificationTopicName(StackEnvironmentType.REPO));
    CreateTopicResult expectedResRepo = setupExpectedRes(StackEnvironmentType.REPO, expectedReqRepo);
    CreateTopicRequest expectedReqWorkers = expectedReq(StackEnvironmentType.WORKERS, config.getEnvironmentInstanceNotificationTopicName(StackEnvironmentType.WORKERS));
    CreateTopicResult expectedResWorkers = setupExpectedRes(StackEnvironmentType.WORKERS, expectedReqWorkers);
    // Make the call
    setup.setupResources();
    verify(mockClient).createTopic(expectedReqPortal);
    verify(mockClient).createTopic(expectedReqRepo);
    verify(mockClient).createTopic(expectedReqWorkers);
    // Make sure it was set the resources
    assertEquals("The expected topic was not set in the resoruces", expectedResPortal.getTopicArn(), resources.getEnvironmentInstanceNotificationTopicArn(StackEnvironmentType.PORTAL));
    assertEquals("The expected topic was not set in the resoruces", expectedResRepo.getTopicArn(), resources.getEnvironmentInstanceNotificationTopicArn(StackEnvironmentType.REPO));
    assertEquals("The expected topic was not set in the resoruces", expectedResWorkers.getTopicArn(), resources.getEnvironmentInstanceNotificationTopicArn(StackEnvironmentType.WORKERS));
}
Also used : CreateTopicResult(com.amazonaws.services.sns.model.CreateTopicResult) CreateTopicRequest(com.amazonaws.services.sns.model.CreateTopicRequest) Test(org.junit.Test)

Example 7 with CreateTopicRequest

use of com.amazonaws.services.sns.model.CreateTopicRequest in project Synapse-Stack-Builder by Sage-Bionetworks.

the class NotificationUtils method setupNotificationTopicAndSubscription.

public static CreateTopicResult setupNotificationTopicAndSubscription(AmazonSNSClient client, String topicName, String endpoint) {
    // Create the topic
    CreateTopicRequest request = new CreateTopicRequest();
    request.setName(topicName);
    CreateTopicResult result = client.createTopic(request);
    // Create the subscription
    Subscription sub = NotificationUtils.createSubScription(client, result.getTopicArn(), Constants.TOPIC_SUBSCRIBE_PROTOCOL_EMAIL, endpoint);
    return result;
}
Also used : CreateTopicResult(com.amazonaws.services.sns.model.CreateTopicResult) CreateTopicRequest(com.amazonaws.services.sns.model.CreateTopicRequest) Subscription(com.amazonaws.services.sns.model.Subscription)

Example 8 with CreateTopicRequest

use of com.amazonaws.services.sns.model.CreateTopicRequest in project aws-doc-sdk-examples by awsdocs.

the class Example method main.

public static void main(String[] args) {
    final String BUCKET_NAME = "extended-client-bucket";
    final String TOPIC_NAME = "extended-client-topic";
    final String QUEUE_NAME = "extended-client-queue";
    final Regions region = Regions.DEFAULT_REGION;
    // Message threshold controls the maximum message size that will be allowed to be published
    // through SNS using the extended client. Payload of messages exceeding this value will be stored in
    // S3. The default value of this parameter is 256 KB which is the maximum message size in SNS (and SQS).
    final int EXTENDED_STORAGE_MESSAGE_SIZE_THRESHOLD = 32;
    // Initialize SNS, SQS and S3 clients
    final AmazonSNS snsClient = AmazonSNSClientBuilder.standard().withRegion(region).build();
    final AmazonSQS sqsClient = AmazonSQSClientBuilder.standard().withRegion(region).build();
    final AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withRegion(region).build();
    // Create bucket, topic, queue and subscription
    s3Client.createBucket(BUCKET_NAME);
    final String topicArn = snsClient.createTopic(new CreateTopicRequest().withName(TOPIC_NAME)).getTopicArn();
    final String queueUrl = sqsClient.createQueue(new CreateQueueRequest().withQueueName(QUEUE_NAME)).getQueueUrl();
    final String subscriptionArn = Topics.subscribeQueue(snsClient, sqsClient, topicArn, queueUrl);
    // To read message content stored in S3 transparently through SQS extended client,
    // set the RawMessageDelivery subscription attribute to TRUE
    final SetSubscriptionAttributesRequest subscriptionAttributesRequest = new SetSubscriptionAttributesRequest();
    subscriptionAttributesRequest.setSubscriptionArn(subscriptionArn);
    subscriptionAttributesRequest.setAttributeName("RawMessageDelivery");
    subscriptionAttributesRequest.setAttributeValue("TRUE");
    snsClient.setSubscriptionAttributes(subscriptionAttributesRequest);
    // Initialize SNS extended client
    // PayloadSizeThreshold triggers message content storage in S3 when the threshold is exceeded
    // To store all messages content in S3, use AlwaysThroughS3 flag
    final SNSExtendedClientConfiguration snsExtendedClientConfiguration = new SNSExtendedClientConfiguration().withPayloadSupportEnabled(s3Client, BUCKET_NAME).withPayloadSizeThreshold(EXTENDED_STORAGE_MESSAGE_SIZE_THRESHOLD);
    final AmazonSNSExtendedClient snsExtendedClient = new AmazonSNSExtendedClient(snsClient, snsExtendedClientConfiguration);
    // Publish message via SNS with storage in S3
    final String message = "This message is stored in S3 as it exceeds the threshold of 32 bytes set above.";
    snsExtendedClient.publish(topicArn, message);
    // Initialize SQS extended client
    final ExtendedClientConfiguration sqsExtendedClientConfiguration = new ExtendedClientConfiguration().withPayloadSupportEnabled(s3Client, BUCKET_NAME);
    final AmazonSQSExtendedClient sqsExtendedClient = new AmazonSQSExtendedClient(sqsClient, sqsExtendedClientConfiguration);
    // Read the message from the queue
    final ReceiveMessageResult result = sqsExtendedClient.receiveMessage(queueUrl);
    System.out.println("Received message is " + result.getMessages().get(0).getBody());
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) Regions(com.amazonaws.regions.Regions) AmazonSQS(com.amazonaws.services.sqs.AmazonSQS) CreateTopicRequest(com.amazonaws.services.sns.model.CreateTopicRequest) AmazonSQSExtendedClient(com.amazon.sqs.javamessaging.AmazonSQSExtendedClient) AmazonSNS(com.amazonaws.services.sns.AmazonSNS) AmazonSNSExtendedClient(software.amazon.sns.AmazonSNSExtendedClient) CreateQueueRequest(com.amazonaws.services.sqs.model.CreateQueueRequest) SetSubscriptionAttributesRequest(com.amazonaws.services.sns.model.SetSubscriptionAttributesRequest) SNSExtendedClientConfiguration(software.amazon.sns.SNSExtendedClientConfiguration) ExtendedClientConfiguration(com.amazon.sqs.javamessaging.ExtendedClientConfiguration) SNSExtendedClientConfiguration(software.amazon.sns.SNSExtendedClientConfiguration) ReceiveMessageResult(com.amazonaws.services.sqs.model.ReceiveMessageResult)

Aggregations

CreateTopicRequest (com.amazonaws.services.sns.model.CreateTopicRequest)8 CreateTopicResult (com.amazonaws.services.sns.model.CreateTopicResult)6 Subscription (com.amazonaws.services.sns.model.Subscription)3 ListSubscriptionsByTopicRequest (com.amazonaws.services.sns.model.ListSubscriptionsByTopicRequest)2 ListSubscriptionsByTopicResult (com.amazonaws.services.sns.model.ListSubscriptionsByTopicResult)2 Test (org.junit.Test)2 AmazonSQSExtendedClient (com.amazon.sqs.javamessaging.AmazonSQSExtendedClient)1 ExtendedClientConfiguration (com.amazon.sqs.javamessaging.ExtendedClientConfiguration)1 AmazonServiceException (com.amazonaws.AmazonServiceException)1 Regions (com.amazonaws.regions.Regions)1 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)1 DescribeSecurityGroupsRequest (com.amazonaws.services.ec2.model.DescribeSecurityGroupsRequest)1 DescribeSecurityGroupsResult (com.amazonaws.services.ec2.model.DescribeSecurityGroupsResult)1 SecurityGroup (com.amazonaws.services.ec2.model.SecurityGroup)1 AmazonRDSClient (com.amazonaws.services.rds.AmazonRDSClient)1 DBParameterGroup (com.amazonaws.services.rds.model.DBParameterGroup)1 DescribeDBParameterGroupsRequest (com.amazonaws.services.rds.model.DescribeDBParameterGroupsRequest)1 DescribeDBParameterGroupsResult (com.amazonaws.services.rds.model.DescribeDBParameterGroupsResult)1 DescribeDBParametersRequest (com.amazonaws.services.rds.model.DescribeDBParametersRequest)1 DescribeDBParametersResult (com.amazonaws.services.rds.model.DescribeDBParametersResult)1