Amazon Simple Queue Service
开发人员指南
AWS 服务或AWS文档中描述的功能,可能因地区/位置而异。点 击 Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

将 Amazon SQS Java Message Service (JMS) 客户端 用于其他 Amazon SQS 客户端

将 Amazon SQS Java Message Service (JMS) 客户端 用于 AWS 开发工具包会将 Amazon SQS 消息大小限制为 256 KB。不过,您可以使用任何 Amazon SQS 客户端创建 JMS 提供程序。例如,您可以使用 JMS 客户端 与 适用于 Java 的 Amazon SQS 扩展客户端库 来发送包含对 Amazon S3 中的消息负载 (最大为 2 GB) 的引用的 Amazon SQS 消息。有关更多信息,请参阅 使用 Amazon S3 管理大 Amazon SQS 消息;

以下 Java 代码示例将为扩展客户端库创建 JMS 提供程序:

Copy
AmazonS3 s3 = new AmazonS3Client(credentials); Region s3Region = Region.getRegion(Regions.US_WEST_2); s3.setRegion(s3Region); // Set the Amazon S3 bucket name, and set a lifecycle rule on the bucket to // permanently delete objects a certain number of days after each object's creation date. // Next, create the bucket, and enable message objects to be stored in the bucket. BucketLifecycleConfiguration.Rule expirationRule = new BucketLifecycleConfiguration.Rule(); expirationRule.withExpirationInDays(14).withStatus("Enabled"); BucketLifecycleConfiguration lifecycleConfig = new BucketLifecycleConfiguration().withRules(expirationRule); s3.createBucket(s3BucketName); s3.setBucketLifecycleConfiguration(s3BucketName, lifecycleConfig); System.out.println("Bucket created and configured."); // Set the SQS extended client configuration with large payload support enabled. ExtendedClientConfiguration extendedClientConfig = new ExtendedClientConfiguration() .withLargePayloadSupportEnabled(s3, s3BucketName); AmazonSQS sqsExtended = new AmazonSQSExtendedClient(new AmazonSQSClient(credentials), extendedClientConfig); Region sqsRegion = Region.getRegion(Regions.US_WEST_2); sqsExtended.setRegion(sqsRegion);

以下 Java 代码示例将创建连接工厂:

Copy
// Create the connection factory using the environment variable credential provider. // Pass the configured Amazon SQS Extended Client to the JMS connection factory. SQSConnectionFactory connectionFactory = new SQSConnectionFactory( new ProviderConfiguration(), sqsExtended ); // Create the connection. SQSConnection connection = connectionFactory.createConnection();