Amazon Simple Queue Service
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 AWS 服务入门

将 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 提供程序:

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 代码示例将创建连接工厂:

// 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();