本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用 Amazon SQS Java Message Service (JMS) 用戶端 搭配其他 Amazon SQS 用戶端
使用 Amazon SQS Java Message Service (JMS) 用戶端搭配 AWS SDK 會將 Amazon SQS 訊息大小限制為 256 KB。不過,您可以使用任何
Amazon SQS 用戶端建立 JMS 提供者。例如,您可以使用 JMS 用戶端 搭配Amazon SQS Java 延伸用戶端程式庫 傳送 Amazon SQS
訊息,其中包含對 Amazon S3 中的訊息承載 (最多 2 GB) 的參考。如需更多詳細資訊,請參閱「使用 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();