

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 將 Java Message Service 與其他 Amazon SQS 用戶端搭配使用
<a name="sqs-jms-client-with-sqs-clients"></a>

搭配 AWS SDK 使用 Amazon SQS Java Message Service (JMS) 用戶端會將 Amazon SQS 訊息大小限制為 256 KB。不過，您可以使用任何 Amazon SQS 用戶端建立 JMS 提供者。例如，您可以使用 JMS Client 搭配適用於 Java 的 Amazon SQS 擴充用戶端程式庫來傳送 Amazon SQS 訊息，其中包含對 Amazon S3 中的訊息承載 (最多 2 GB) 的參考。如需詳細資訊，請參閱[使用 Java 和 Amazon S3 管理大型 Amazon SQS 訊息 Amazon S3](sqs-s3-messages.md)。

下列 Java 程式碼範例會為擴充用戶端程式庫建立 JMS 提供者。

在測試此範例[使用 JMS 和 Amazon SQS 的先決條件](prerequisites.md)之前，請參閱 中的先決條件。

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