amazon SNS Create And Add - Java AWS

Java examples for AWS:Simple Notification Service

Description

amazon SNS Create And Add

Demo Code

import com.amazonaws.auth.PropertiesCredentials;
import com.amazonaws.services.sns.AmazonSNS;
import com.amazonaws.services.sns.AmazonSNSClient;
import com.amazonaws.services.sns.model.CreateTopicRequest;
import com.amazonaws.services.sns.model.SubscribeRequest;
import com.amazonaws.services.sns.model.SubscribeResult;

public class SNSCreateAndAdd {

    public static void main(String[] args) throws Exception {

        AmazonSNS sns = new AmazonSNSClient(new PropertiesCredentials(
                SNSCreateAndAdd.class
                        .getResourceAsStream("AwsCredentials.properties")));

        // Create a Topic 
        System.out.println("Creating SNS Topic.");
        CreateTopicRequest createTopicRequest = new CreateTopicRequest()
                .withName("LorenTestTopic");

        // Retrieve Amazon Resource Name 
        String SNSTopicArn = sns.createTopic(createTopicRequest)
                .getTopicArn();/*  w  ww  . j a  va 2  s .co  m*/

        // Subscribe to SNSTopic 
        SubscribeRequest subReq = new SubscribeRequest(SNSTopicArn,
                "email", "myName@myHost.com");
        SubscribeResult subRes = sns.subscribe(subReq);
        SubscribeRequest subReq2 = new SubscribeRequest(SNSTopicArn,
                "email", "etrange_desire@yahoo.com");
        SubscribeResult subRes2 = sns.subscribe(subReq2);

        System.out.println(SNSTopicArn);
    }
}

Related Tutorials