Usar o Serviço de Mensagens Java com outros clientes do Amazon SQS - Amazon Simple Queue Service

As traduções são geradas por tradução automática. Em caso de conflito entre o conteúdo da tradução e da versão original em inglês, a versão em inglês prevalecerá.

Usar o Serviço de Mensagens Java com outros clientes do Amazon SQS

O uso do cliente Amazon SQS Java Message Service (JMS) com o AWS SDK limita o tamanho da mensagem do Amazon SQS a 256 KB. No entanto, você pode criar um provedor JMS usando qualquer cliente do Amazon SQS. Por exemplo, você pode usar o cliente JMS com a biblioteca cliente Java estendida para o Amazon SQS para enviar uma mensagem do Amazon SQS que contenha uma referência à carga útil da mensagem (até 2 GB) no Amazon S3. Para obter mais informações, consulte Gerenciar mensagens grandes do Amazon SQS usando Java e Amazon S3.

O exemplo de código Java a seguir cria o provedor do JMS para a biblioteca do cliente em versão ampliada.

Veja os pré-requisitos em Pré-requisitos para trabalhar com o JMS e o Amazon SQS antes de testar este exemplo.

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

O exemplo de código Java a seguir cria a connection factory:

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