使用 Amazon 软件开发工具包为 Amazon SNS 推送通知创建平台终端节点
以下代码示例展示如何为 Amazon SNS 推送通知创建平台终端节点。
- Java
-
- SDK for Java 2.x
-
提示 要了解如何设置和运行此示例,请参阅 GitHub
。 public class RegistrationExample { public static void main(String[] args) { final String usage = "\n" + "Usage: " + " <token>\n\n" + "Where:\n" + " token - The name of the FIFO topic. \n\n" + " platformApplicationArn - The ARN value of platform application. You can get this value from the AWS Management Console. \n\n"; if (args.length != 2) { System.out.println(usage); System.exit(1); } String token = args[0]; String platformApplicationArn = args[1]; SnsClient snsClient = SnsClient.builder() .region(Region.US_EAST_1) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); createEndpoint(snsClient, token, platformApplicationArn); } public static void createEndpoint(SnsClient snsClient, String token, String platformApplicationArn){ System.out.println("Creating platform endpoint with token " + token); try { CreatePlatformEndpointRequest endpointRequest = CreatePlatformEndpointRequest.builder() .token(token) .platformApplicationArn(platformApplicationArn) .build(); CreatePlatformEndpointResponse response = snsClient.createPlatformEndpoint(endpointRequest); System.out.println("The ARN of the endpoint is " + response.endpointArn()); } catch ( SnsException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } } }
有关 Amazon 软件开发工具包开发人员指南和代码示例的完整列表,请参阅 将 Amazon SNS 与 Amazon 开发工具包结合使用。本主题还包括有关入门的信息以及有关先前的软件开发工具包版本的详细信息。
场景
创建并发布到 FIFO 主题