diff --git a/.gitignore b/.gitignore index 2f7896d..07827cc 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ target/ +.idea/ \ No newline at end of file diff --git a/VERSIONING.md b/VERSIONING.md new file mode 100644 index 0000000..d8ee950 --- /dev/null +++ b/VERSIONING.md @@ -0,0 +1,20 @@ +## Versioning Policy + +We use a three-part X.Y.Z (Major.Minor.Patch) versioning definition, as follows: +* X (Major) version changes are significant and expected to break backwards compatibility. +* Y (Minor) version changes are moderate changes. These include: + * Significant non-breaking feature additions. + * Any change to the version of a dependency. + * Possible backwards-incompatible changes. These changes will be noted and explained in detail in the release notes. +* Z (Patch) version changes are small changes. These changes will not break backwards compatibility. + * Z releases will also include warning of upcoming breaking changes, whenever possible. + +## What this means for you + +We recommend running the most recent version. Here are our suggestions for managing updates: + +* X changes will require some effort to incorporate. +* Y changes will not require significant effort to incorporate. + * If you have good unit and integration tests, these changes are generally safe to pick up automatically. +* Z changes will not require any changes to your code. Z changes are intended to be picked up automatically. + * Good unit and integration tests are always recommended. \ No newline at end of file diff --git a/pom.xml b/pom.xml index 2ec00ac..7767eef 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.amazonaws amazon-sqs-java-extended-client-lib - 1.0.2 + 1.1.0 jar Amazon SQS Extended Client Library for Java An extension to the Amazon SQS client that enables sending and receiving messages up to 2GB via Amazon S3. @@ -52,6 +52,12 @@ ${aws-java-sdk.version} + + software.amazon.payloadoffloading + payloadoffloading-common + 1.0.0 + + junit junit @@ -73,12 +79,100 @@ maven-compiler-plugin 3.2 - 1.7 - 1.7 + 1.8 + 1.8 UTF-8 + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + + attach-javadocs + + jar + + + + -Xdoclint:none + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.7 + true + + ossrh + https://aws.oss.sonatype.org + true + + + + + + + publishing + + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + sign-artifacts + verify + + sign + + + + --pinentry-mode + loopback + + + + + + + + + diff --git a/src/main/java/com/amazon/sqs/javamessaging/AmazonSQSExtendedClient.java b/src/main/java/com/amazon/sqs/javamessaging/AmazonSQSExtendedClient.java index 8200d7b..8755f23 100644 --- a/src/main/java/com/amazon/sqs/javamessaging/AmazonSQSExtendedClient.java +++ b/src/main/java/com/amazon/sqs/javamessaging/AmazonSQSExtendedClient.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2010-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -15,25 +15,12 @@ package com.amazon.sqs.javamessaging; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStreamWriter; -import java.io.Writer; import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.Map; -import java.util.UUID; +import java.util.*; import java.util.Map.Entry; import com.amazonaws.AmazonClientException; import com.amazonaws.AmazonServiceException; -import com.amazonaws.services.s3.model.GetObjectRequest; -import com.amazonaws.services.s3.model.ObjectMetadata; -import com.amazonaws.services.s3.model.PutObjectRequest; -import com.amazonaws.services.s3.model.S3Object; -import com.amazonaws.services.s3.model.S3ObjectInputStream; import com.amazonaws.services.sqs.AmazonSQS; import com.amazonaws.services.sqs.model.BatchEntryIdsNotDistinctException; import com.amazonaws.services.sqs.model.BatchRequestTooLongException; @@ -66,10 +53,11 @@ import com.amazonaws.services.sqs.model.SendMessageRequest; import com.amazonaws.services.sqs.model.SendMessageResult; import com.amazonaws.services.sqs.model.TooManyEntriesInBatchRequestException; -import com.amazonaws.util.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import software.amazon.payloadoffloading.*; + /** * Amazon SQS Extended Client extends the functionality of Amazon SQS client. @@ -91,961 +79,977 @@ * */ public class AmazonSQSExtendedClient extends AmazonSQSExtendedClientBase implements AmazonSQS { - private static final Log LOG = LogFactory.getLog(AmazonSQSExtendedClient.class); - - private ExtendedClientConfiguration clientConfiguration; - - /** - * Constructs a new Amazon SQS extended client to invoke service methods on - * Amazon SQS with extended functionality using the specified Amazon SQS - * client object. - * - *

- * All service calls made using this new client object are blocking, and - * will not return until the service call completes. - * - * @param sqsClient - * The Amazon SQS client to use to connect to Amazon SQS. - */ - public AmazonSQSExtendedClient(AmazonSQS sqsClient) { - this(sqsClient, new ExtendedClientConfiguration()); - } - - /** - * Constructs a new Amazon SQS extended client to invoke service methods on - * Amazon SQS with extended functionality using the specified Amazon SQS - * client object. - * - *

- * All service calls made using this new client object are blocking, and - * will not return until the service call completes. - * - * @param sqsClient - * The Amazon SQS client to use to connect to Amazon SQS. - * @param extendedClientConfig - * The extended client configuration options controlling the - * functionality of this client. - */ - public AmazonSQSExtendedClient(AmazonSQS sqsClient, ExtendedClientConfiguration extendedClientConfig) { - super(sqsClient); - this.clientConfiguration = new ExtendedClientConfiguration(extendedClientConfig); - } - - /** - *

- * Delivers a message to the specified queue and uploads the message payload - * to Amazon S3 if necessary. - *

- *

- * IMPORTANT: The following list shows the characters (in Unicode) - * allowed in your message, according to the W3C XML specification. For more - * information, go to http://www.w3.org/TR/REC-xml/#charsets If you send any - * characters not included in the list, your request will be rejected. #x9 | - * #xA | #xD | [#x20 to #xD7FF] | [#xE000 to #xFFFD] | [#x10000 to #x10FFFF] - *

- * - * IMPORTANT: The input object may be modified by the method.

- * - * @param sendMessageRequest - * Container for the necessary parameters to execute the - * SendMessage service method on AmazonSQS. - * - * @return The response from the SendMessage service method, as returned by - * AmazonSQS. - * - * @throws InvalidMessageContentsException - * @throws UnsupportedOperationException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public SendMessageResult sendMessage(SendMessageRequest sendMessageRequest) { - - if (sendMessageRequest == null) { - String errorMessage = "sendMessageRequest cannot be null."; - LOG.error(errorMessage); - throw new AmazonClientException(errorMessage); - } - - sendMessageRequest.getRequestClientOptions().appendUserAgent(SQSExtendedClientConstants.USER_AGENT_HEADER); - - if (!clientConfiguration.isLargePayloadSupportEnabled()) { - return super.sendMessage(sendMessageRequest); - } - - if (sendMessageRequest.getMessageBody() == null || "".equals(sendMessageRequest.getMessageBody())) { - String errorMessage = "messageBody cannot be null or empty."; - LOG.error(errorMessage); - throw new AmazonClientException(errorMessage); - } - - if (clientConfiguration.isAlwaysThroughS3() || isLarge(sendMessageRequest)) { - sendMessageRequest = storeMessageInS3(sendMessageRequest); - } - return super.sendMessage(sendMessageRequest); - } - - /** - *

- * Delivers a message to the specified queue and uploads the message payload - * to Amazon S3 if necessary. - *

- *

- * IMPORTANT: The following list shows the characters (in Unicode) - * allowed in your message, according to the W3C XML specification. For more - * information, go to http://www.w3.org/TR/REC-xml/#charsets If you send any - * characters not included in the list, your request will be rejected. #x9 | - * #xA | #xD | [#x20 to #xD7FF] | [#xE000 to #xFFFD] | [#x10000 to #x10FFFF] - *

- * - * @param queueUrl - * The URL of the Amazon SQS queue to take action on. - * @param messageBody - * The message to send. For a list of allowed characters, see the - * preceding important note. - * - * @return The response from the SendMessage service method, as returned by - * AmazonSQS. - * - * @throws InvalidMessageContentsException - * @throws UnsupportedOperationException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public SendMessageResult sendMessage(String queueUrl, String messageBody) { - SendMessageRequest sendMessageRequest = new SendMessageRequest(queueUrl, messageBody); - return sendMessage(sendMessageRequest); - } - - /** - *

- * Retrieves one or more messages, with a maximum limit of 10 messages, from - * the specified queue. Downloads the message payloads from Amazon S3 when - * necessary. Long poll support is enabled by using the - * WaitTimeSeconds parameter. For more information, see Amazon SQS Long Poll in the Amazon SQS Developer Guide . - *

- *

- * Short poll is the default behavior where a weighted random set of - * machines is sampled on a ReceiveMessage call. This means - * only the messages on the sampled machines are returned. If the number of - * messages in the queue is small (less than 1000), it is likely you will - * get fewer messages than you requested per ReceiveMessage - * call. If the number of messages in the queue is extremely small, you - * might not receive any messages in a particular - * ReceiveMessage response; in which case you should repeat the - * request. - *

- *

- * For each message returned, the response includes the following: - *

- * - * - *

- * The receipt handle is the identifier you must provide when deleting the - * message. For more information, see Queue and Message Identifiers in the Amazon SQS Developer - * Guide . - *

- *

- * You can provide the VisibilityTimeout parameter in your - * request, which will be applied to the messages that Amazon SQS returns in - * the response. If you do not include the parameter, the overall visibility - * timeout for the queue is used for the returned messages. For more - * information, see Visibility Timeout in the Amazon SQS Developer Guide . - *

- *

- * NOTE: Going forward, new attributes might be added. If you are - * writing code that calls this action, we recommend that you structure your - * code so that it can handle new attributes gracefully. - *

- * - * @param receiveMessageRequest - * Container for the necessary parameters to execute the - * ReceiveMessage service method on AmazonSQS. - * - * @return The response from the ReceiveMessage service method, as returned - * by AmazonSQS. - * - * @throws OverLimitException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public ReceiveMessageResult receiveMessage(ReceiveMessageRequest receiveMessageRequest) { - - if (receiveMessageRequest == null) { - String errorMessage = "receiveMessageRequest cannot be null."; - LOG.error(errorMessage); - throw new AmazonClientException(errorMessage); - } - - receiveMessageRequest.getRequestClientOptions().appendUserAgent(SQSExtendedClientConstants.USER_AGENT_HEADER); - - if (!clientConfiguration.isLargePayloadSupportEnabled()) { - return super.receiveMessage(receiveMessageRequest); - } - - if (!receiveMessageRequest.getMessageAttributeNames().contains(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME)) { - receiveMessageRequest.getMessageAttributeNames().add(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME); + private static final Log LOG = LogFactory.getLog(AmazonSQSExtendedClient.class); + private static final String USER_AGENT_HEADER = Util.getUserAgentHeader(AmazonSQSExtendedClient.class.getSimpleName()); + static final String LEGACY_RESERVED_ATTRIBUTE_NAME = "SQSLargePayloadSize"; + static final List RESERVED_ATTRIBUTE_NAMES = Arrays.asList(LEGACY_RESERVED_ATTRIBUTE_NAME, + SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME); + private ExtendedClientConfiguration clientConfiguration; + private PayloadStore payloadStore; + + /** + * Constructs a new Amazon SQS extended client to invoke service methods on + * Amazon SQS with extended functionality using the specified Amazon SQS + * client object. + * + *

+ * All service calls made using this new client object are blocking, and + * will not return until the service call completes. + * + * @param sqsClient + * The Amazon SQS client to use to connect to Amazon SQS. + */ + public AmazonSQSExtendedClient(AmazonSQS sqsClient) { + this(sqsClient, new ExtendedClientConfiguration()); + } + + /** + * Constructs a new Amazon SQS extended client to invoke service methods on + * Amazon SQS with extended functionality using the specified Amazon SQS + * client object. + * + *

+ * All service calls made using this new client object are blocking, and + * will not return until the service call completes. + * + * @param sqsClient + * The Amazon SQS client to use to connect to Amazon SQS. + * @param extendedClientConfig + * The extended client configuration options controlling the + * functionality of this client. + */ + public AmazonSQSExtendedClient(AmazonSQS sqsClient, ExtendedClientConfiguration extendedClientConfig) { + super(sqsClient); + this.clientConfiguration = new ExtendedClientConfiguration(extendedClientConfig); + S3Dao s3Dao = new S3Dao(clientConfiguration.getAmazonS3Client()); + this.payloadStore = new S3BackedPayloadStore(s3Dao, clientConfiguration.getS3BucketName(), + clientConfiguration.getSSEAwsKeyManagementParams()); + } + + /** + *

+ * Delivers a message to the specified queue and uploads the message payload + * to Amazon S3 if necessary. + *

+ *

+ * IMPORTANT: The following list shows the characters (in Unicode) + * allowed in your message, according to the W3C XML specification. For more + * information, go to http://www.w3.org/TR/REC-xml/#charsets If you send any + * characters not included in the list, your request will be rejected. #x9 | + * #xA | #xD | [#x20 to #xD7FF] | [#xE000 to #xFFFD] | [#x10000 to #x10FFFF] + *

+ * + * IMPORTANT: The input object may be modified by the method.

+ * + * @param sendMessageRequest + * Container for the necessary parameters to execute the + * SendMessage service method on AmazonSQS. + * + * @return The response from the SendMessage service method, as returned by + * AmazonSQS. + * + * @throws InvalidMessageContentsException + * @throws UnsupportedOperationException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public SendMessageResult sendMessage(SendMessageRequest sendMessageRequest) { + //TODO: Clone request since it's modified in this method and will cause issues if the client reuses request object. + if (sendMessageRequest == null) { + String errorMessage = "sendMessageRequest cannot be null."; + LOG.error(errorMessage); + throw new AmazonClientException(errorMessage); + } + + sendMessageRequest.getRequestClientOptions().appendUserAgent(USER_AGENT_HEADER); + + if (!clientConfiguration.isPayloadSupportEnabled()) { + return super.sendMessage(sendMessageRequest); + } + + if (sendMessageRequest.getMessageBody() == null || "".equals(sendMessageRequest.getMessageBody())) { + String errorMessage = "messageBody cannot be null or empty."; + LOG.error(errorMessage); + throw new AmazonClientException(errorMessage); + } + + //Check message attributes for ExtendedClient related constraints + checkMessageAttributes(sendMessageRequest.getMessageAttributes()); + + if (clientConfiguration.isAlwaysThroughS3() || isLarge(sendMessageRequest)) { + sendMessageRequest = storeMessageInS3(sendMessageRequest); + } + return super.sendMessage(sendMessageRequest); + } + + /** + *

+ * Delivers a message to the specified queue and uploads the message payload + * to Amazon S3 if necessary. + *

+ *

+ * IMPORTANT: The following list shows the characters (in Unicode) + * allowed in your message, according to the W3C XML specification. For more + * information, go to http://www.w3.org/TR/REC-xml/#charsets If you send any + * characters not included in the list, your request will be rejected. #x9 | + * #xA | #xD | [#x20 to #xD7FF] | [#xE000 to #xFFFD] | [#x10000 to #x10FFFF] + *

+ * + * @param queueUrl + * The URL of the Amazon SQS queue to take action on. + * @param messageBody + * The message to send. For a list of allowed characters, see the + * preceding important note. + * + * @return The response from the SendMessage service method, as returned by + * AmazonSQS. + * + * @throws InvalidMessageContentsException + * @throws UnsupportedOperationException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public SendMessageResult sendMessage(String queueUrl, String messageBody) { + SendMessageRequest sendMessageRequest = new SendMessageRequest(queueUrl, messageBody); + return sendMessage(sendMessageRequest); + } + + /** + *

+ * Retrieves one or more messages, with a maximum limit of 10 messages, from + * the specified queue. Downloads the message payloads from Amazon S3 when + * necessary. Long poll support is enabled by using the + * WaitTimeSeconds parameter. For more information, see Amazon SQS Long Poll in the Amazon SQS Developer Guide . + *

+ *

+ * Short poll is the default behavior where a weighted random set of + * machines is sampled on a ReceiveMessage call. This means + * only the messages on the sampled machines are returned. If the number of + * messages in the queue is small (less than 1000), it is likely you will + * get fewer messages than you requested per ReceiveMessage + * call. If the number of messages in the queue is extremely small, you + * might not receive any messages in a particular + * ReceiveMessage response; in which case you should repeat the + * request. + *

+ *

+ * For each message returned, the response includes the following: + *

+ * + *
    + *
  • + *

    + * Message body + *

    + *
  • + *
  • + *

    + * MD5 digest of the message body. For information about MD5, go to + * http://www.faqs.org/rfcs/rfc1321.html . + *

    + *
  • + *
  • + *

    + * Message ID you received when you sent the message to the queue. + *

    + *
  • + *
  • + *

    + * Receipt handle. + *

    + *
  • + *
  • + *

    + * Message attributes. + *

    + *
  • + *
  • + *

    + * MD5 digest of the message attributes. + *

    + *
  • + * + *
+ *

+ * The receipt handle is the identifier you must provide when deleting the + * message. For more information, see Queue and Message Identifiers in the Amazon SQS Developer + * Guide . + *

+ *

+ * You can provide the VisibilityTimeout parameter in your + * request, which will be applied to the messages that Amazon SQS returns in + * the response. If you do not include the parameter, the overall visibility + * timeout for the queue is used for the returned messages. For more + * information, see Visibility Timeout in the Amazon SQS Developer Guide . + *

+ *

+ * NOTE: Going forward, new attributes might be added. If you are + * writing code that calls this action, we recommend that you structure your + * code so that it can handle new attributes gracefully. + *

+ * + * @param receiveMessageRequest + * Container for the necessary parameters to execute the + * ReceiveMessage service method on AmazonSQS. + * + * @return The response from the ReceiveMessage service method, as returned + * by AmazonSQS. + * + * @throws OverLimitException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public ReceiveMessageResult receiveMessage(ReceiveMessageRequest receiveMessageRequest) { + //TODO: Clone request since it's modified in this method and will cause issues if the client reuses request object. + if (receiveMessageRequest == null) { + String errorMessage = "receiveMessageRequest cannot be null."; + LOG.error(errorMessage); + throw new AmazonClientException(errorMessage); + } + + receiveMessageRequest.getRequestClientOptions().appendUserAgent(USER_AGENT_HEADER); + + if (!clientConfiguration.isPayloadSupportEnabled()) { + return super.receiveMessage(receiveMessageRequest); + } + //Remove before adding to avoid any duplicates + receiveMessageRequest.getMessageAttributeNames().removeAll(RESERVED_ATTRIBUTE_NAMES); + receiveMessageRequest.getMessageAttributeNames().addAll(RESERVED_ATTRIBUTE_NAMES); + + ReceiveMessageResult receiveMessageResult = super.receiveMessage(receiveMessageRequest); + + List messages = receiveMessageResult.getMessages(); + for (Message message : messages) { + + // for each received message check if they are stored in S3. + Optional largePayloadAttributeName = getReservedAttributeNameIfPresent(message.getMessageAttributes()); + if (largePayloadAttributeName.isPresent()) { + String largeMessagePointer = message.getBody(); + + message.setBody(payloadStore.getOriginalPayload(largeMessagePointer)); + + // remove the additional attribute before returning the message + // to user. + message.getMessageAttributes().keySet().removeAll(RESERVED_ATTRIBUTE_NAMES); + + // Embed s3 object pointer in the receipt handle. + String modifiedReceiptHandle = embedS3PointerInReceiptHandle( + message.getReceiptHandle(), + largeMessagePointer); + + message.setReceiptHandle(modifiedReceiptHandle); + } + } + return receiveMessageResult; + } + + /** + *

+ * Retrieves one or more messages, with a maximum limit of 10 messages, from + * the specified queue. Downloads the message payloads from Amazon S3 when + * necessary. Long poll support is enabled by using the + * WaitTimeSeconds parameter. For more information, see Amazon SQS Long Poll in the Amazon SQS Developer Guide . + *

+ *

+ * Short poll is the default behavior where a weighted random set of + * machines is sampled on a ReceiveMessage call. This means + * only the messages on the sampled machines are returned. If the number of + * messages in the queue is small (less than 1000), it is likely you will + * get fewer messages than you requested per ReceiveMessage + * call. If the number of messages in the queue is extremely small, you + * might not receive any messages in a particular + * ReceiveMessage response; in which case you should repeat the + * request. + *

+ *

+ * For each message returned, the response includes the following: + *

+ * + *
    + *
  • + *

    + * Message body + *

    + *
  • + *
  • + *

    + * MD5 digest of the message body. For information about MD5, go to + * http://www.faqs.org/rfcs/rfc1321.html . + *

    + *
  • + *
  • + *

    + * Message ID you received when you sent the message to the queue. + *

    + *
  • + *
  • + *

    + * Receipt handle. + *

    + *
  • + *
  • + *

    + * Message attributes. + *

    + *
  • + *
  • + *

    + * MD5 digest of the message attributes. + *

    + *
  • + * + *
+ *

+ * The receipt handle is the identifier you must provide when deleting the + * message. For more information, see Queue and Message Identifiers in the Amazon SQS Developer + * Guide . + *

+ *

+ * You can provide the VisibilityTimeout parameter in your + * request, which will be applied to the messages that Amazon SQS returns in + * the response. If you do not include the parameter, the overall visibility + * timeout for the queue is used for the returned messages. For more + * information, see Visibility Timeout in the Amazon SQS Developer Guide . + *

+ *

+ * NOTE: Going forward, new attributes might be added. If you are + * writing code that calls this action, we recommend that you structure your + * code so that it can handle new attributes gracefully. + *

+ * + * @param queueUrl + * The URL of the Amazon SQS queue to take action on. + * + * @return The response from the ReceiveMessage service method, as returned + * by AmazonSQS. + * + * @throws OverLimitException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public ReceiveMessageResult receiveMessage(String queueUrl) { + ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(queueUrl); + return receiveMessage(receiveMessageRequest); + } + + /** + *

+ * Deletes the specified message from the specified queue and deletes the + * message payload from Amazon S3 when necessary. You specify the message by + * using the message's receipt handle and not the + * message ID you received when you sent the message. Even if + * the message is locked by another reader due to the visibility timeout + * setting, it is still deleted from the queue. If you leave a message in + * the queue for longer than the queue's configured retention period, Amazon + * SQS automatically deletes it. + *

+ *

+ * NOTE: The receipt handle is associated with a specific instance of + * receiving the message. If you receive a message more than once, the + * receipt handle you get each time you receive the message is different. + * When you request DeleteMessage, if you don't provide the most recently + * received receipt handle for the message, the request will still succeed, + * but the message might not be deleted. + *

+ *

+ * IMPORTANT: It is possible you will receive a message even after + * you have deleted it. This might happen on rare occasions if one of the + * servers storing a copy of the message is unavailable when you request to + * delete the message. The copy remains on the server and might be returned + * to you again on a subsequent receive request. You should create your + * system to be idempotent so that receiving a particular message more than + * once is not a problem. + *

+ * + * @param deleteMessageRequest + * Container for the necessary parameters to execute the + * DeleteMessage service method on AmazonSQS. + * + * @return The response from the DeleteMessage service method, as returned + * by AmazonSQS. + * + * @throws ReceiptHandleIsInvalidException + * @throws InvalidIdFormatException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public DeleteMessageResult deleteMessage(DeleteMessageRequest deleteMessageRequest) { + + if (deleteMessageRequest == null) { + String errorMessage = "deleteMessageRequest cannot be null."; + LOG.error(errorMessage); + throw new AmazonClientException(errorMessage); + } + + deleteMessageRequest.getRequestClientOptions().appendUserAgent(USER_AGENT_HEADER); + + if (!clientConfiguration.isPayloadSupportEnabled()) { + return super.deleteMessage(deleteMessageRequest); + } + + String receiptHandle = deleteMessageRequest.getReceiptHandle(); + String origReceiptHandle = receiptHandle; + + // Update original receipt handle if needed + if (isS3ReceiptHandle(receiptHandle)) { + origReceiptHandle = getOrigReceiptHandle(receiptHandle); + // Delete pay load from S3 if needed + if (clientConfiguration.doesCleanupS3Payload()) { + String messagePointer = getMessagePointerFromModifiedReceiptHandle(receiptHandle); + payloadStore.deleteOriginalPayload(messagePointer); + } + } + + deleteMessageRequest.setReceiptHandle(origReceiptHandle); + return super.deleteMessage(deleteMessageRequest); + } + + /** + *

+ * Deletes the specified message from the specified queue and deletes the + * message payload from Amazon S3 when necessary. You specify the message by + * using the message's receipt handle and not the + * message ID you received when you sent the message. Even if + * the message is locked by another reader due to the visibility timeout + * setting, it is still deleted from the queue. If you leave a message in + * the queue for longer than the queue's configured retention period, Amazon + * SQS automatically deletes it. + *

+ *

+ * NOTE: The receipt handle is associated with a specific instance of + * receiving the message. If you receive a message more than once, the + * receipt handle you get each time you receive the message is different. + * When you request DeleteMessage, if you don't provide the most recently + * received receipt handle for the message, the request will still succeed, + * but the message might not be deleted. + *

+ *

+ * IMPORTANT: It is possible you will receive a message even after + * you have deleted it. This might happen on rare occasions if one of the + * servers storing a copy of the message is unavailable when you request to + * delete the message. The copy remains on the server and might be returned + * to you again on a subsequent receive request. You should create your + * system to be idempotent so that receiving a particular message more than + * once is not a problem. + *

+ * + * @param queueUrl + * The URL of the Amazon SQS queue to take action on. + * @param receiptHandle + * The receipt handle associated with the message to delete. + * + * @return The response from the DeleteMessage service method, as returned + * by AmazonSQS. + * + * @throws ReceiptHandleIsInvalidException + * @throws InvalidIdFormatException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public DeleteMessageResult deleteMessage(String queueUrl, String receiptHandle) { + DeleteMessageRequest deleteMessageRequest = new DeleteMessageRequest(queueUrl, receiptHandle); + return deleteMessage(deleteMessageRequest); + } + + /** + * Simplified method form for invoking the ChangeMessageVisibility + * operation. + * + * @see #changeMessageVisibility(ChangeMessageVisibilityRequest) + */ + public ChangeMessageVisibilityResult changeMessageVisibility(String queueUrl, + String receiptHandle, + Integer visibilityTimeout) { + ChangeMessageVisibilityRequest changeMessageVisibilityRequest = + new ChangeMessageVisibilityRequest(queueUrl, receiptHandle, visibilityTimeout); + return changeMessageVisibility(changeMessageVisibilityRequest); + } + + /** + *

+ * Changes the visibility timeout of a specified message in a queue to a new + * value. The maximum allowed timeout value you can set the value to is 12 + * hours. This means you can't extend the timeout of a message in an + * existing queue to more than a total visibility timeout of 12 hours. (For + * more information visibility timeout, see Visibility Timeout in the Amazon SQS Developer Guide .) + *

+ *

+ * For example, let's say you have a message and its default message + * visibility timeout is 30 minutes. You could call + * ChangeMessageVisiblity with a value of two hours and the + * effective timeout would be two hours and 30 minutes. When that time comes + * near you could again extend the time out by calling + * ChangeMessageVisiblity, but this time the maximum allowed timeout would + * be 9 hours and 30 minutes. + *

+ *

+ * NOTE: There is a 120,000 limit for the number of inflight messages + * per queue. Messages are inflight after they have been received from the + * queue by a consuming component, but have not yet been deleted from the + * queue. If you reach the 120,000 limit, you will receive an OverLimit + * error message from Amazon SQS. To help avoid reaching the limit, you + * should delete the messages from the queue after they have been processed. + * You can also increase the number of queues you use to process the + * messages. + *

+ *

+ * IMPORTANT:If you attempt to set the VisibilityTimeout to an amount + * more than the maximum time left, Amazon SQS returns an error. It will not + * automatically recalculate and increase the timeout to the maximum time + * remaining. + *

+ *

+ * IMPORTANT:Unlike with a queue, when you change the visibility + * timeout for a specific message, that timeout value is applied immediately + * but is not saved in memory for that message. If you don't delete a + * message after it is received, the visibility timeout for the message the + * next time it is received reverts to the original timeout value, not the + * value you set with the ChangeMessageVisibility action. + *

+ * + * @param changeMessageVisibilityRequest + * Container for the necessary parameters to execute the + * ChangeMessageVisibility service method on AmazonSQS. + * + * + * @throws ReceiptHandleIsInvalidException + * @throws MessageNotInflightException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public ChangeMessageVisibilityResult changeMessageVisibility(ChangeMessageVisibilityRequest changeMessageVisibilityRequest) + throws AmazonServiceException, AmazonClientException { + + if (isS3ReceiptHandle(changeMessageVisibilityRequest.getReceiptHandle())) { + changeMessageVisibilityRequest.setReceiptHandle( + getOrigReceiptHandle(changeMessageVisibilityRequest.getReceiptHandle())); + } + return amazonSqsToBeExtended.changeMessageVisibility(changeMessageVisibilityRequest); + } + + /** + *

+ * Delivers up to ten messages to the specified queue. This is a batch + * version of SendMessage. The result of the send action on each message is + * reported individually in the response. Uploads message payloads to Amazon + * S3 when necessary. + *

+ *

+ * If the DelaySeconds parameter is not specified for an entry, + * the default for the queue is used. + *

+ *

+ * IMPORTANT:The following list shows the characters (in Unicode) + * that are allowed in your message, according to the W3C XML specification. + * For more information, go to http://www.faqs.org/rfcs/rfc1321.html. If you + * send any characters that are not included in the list, your request will + * be rejected. #x9 | #xA | #xD | [#x20 to #xD7FF] | [#xE000 to #xFFFD] | + * [#x10000 to #x10FFFF] + *

+ *

+ * IMPORTANT: Because the batch request can result in a combination + * of successful and unsuccessful actions, you should check for batch errors + * even when the call returns an HTTP status code of 200. + *

+ * IMPORTANT: The input object may be modified by the method.

+ *

+ * NOTE:Some API actions take lists of parameters. These lists are + * specified using the param.n notation. Values of n are integers starting + * from 1. For example, a parameter list with two elements looks like this: + *

+ *

+ * &Attribute.1=this + *

+ *

+ * &Attribute.2=that + *

+ * + * @param sendMessageBatchRequest + * Container for the necessary parameters to execute the + * SendMessageBatch service method on AmazonSQS. + * + * @return The response from the SendMessageBatch service method, as + * returned by AmazonSQS. + * + * @throws BatchEntryIdsNotDistinctException + * @throws TooManyEntriesInBatchRequestException + * @throws BatchRequestTooLongException + * @throws UnsupportedOperationException + * @throws InvalidBatchEntryIdException + * @throws EmptyBatchRequestException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public SendMessageBatchResult sendMessageBatch(SendMessageBatchRequest sendMessageBatchRequest) { + + if (sendMessageBatchRequest == null) { + String errorMessage = "sendMessageBatchRequest cannot be null."; + LOG.error(errorMessage); + throw new AmazonClientException(errorMessage); + } + + sendMessageBatchRequest.getRequestClientOptions().appendUserAgent(USER_AGENT_HEADER); + + if (!clientConfiguration.isPayloadSupportEnabled()) { + return super.sendMessageBatch(sendMessageBatchRequest); + } + + List batchEntries = sendMessageBatchRequest.getEntries(); + + int index = 0; + for (SendMessageBatchRequestEntry entry : batchEntries) { + //Check message attributes for ExtendedClient related constraints + checkMessageAttributes(entry.getMessageAttributes()); + + if (clientConfiguration.isAlwaysThroughS3() || isLarge(entry)) { + batchEntries.set(index, storeMessageInS3(entry)); + } + ++index; + } + + return super.sendMessageBatch(sendMessageBatchRequest); + } + + /** + *

+ * Delivers up to ten messages to the specified queue. This is a batch + * version of SendMessage. The result of the send action on each message is + * reported individually in the response. Uploads message payloads to Amazon + * S3 when necessary. + *

+ *

+ * If the DelaySeconds parameter is not specified for an entry, + * the default for the queue is used. + *

+ *

+ * IMPORTANT:The following list shows the characters (in Unicode) + * that are allowed in your message, according to the W3C XML specification. + * For more information, go to http://www.faqs.org/rfcs/rfc1321.html. If you + * send any characters that are not included in the list, your request will + * be rejected. #x9 | #xA | #xD | [#x20 to #xD7FF] | [#xE000 to #xFFFD] | + * [#x10000 to #x10FFFF] + *

+ *

+ * IMPORTANT: Because the batch request can result in a combination + * of successful and unsuccessful actions, you should check for batch errors + * even when the call returns an HTTP status code of 200. + *

+ *

+ * NOTE:Some API actions take lists of parameters. These lists are + * specified using the param.n notation. Values of n are integers starting + * from 1. For example, a parameter list with two elements looks like this: + *

+ *

+ * &Attribute.1=this + *

+ *

+ * &Attribute.2=that + *

+ * + * @param queueUrl + * The URL of the Amazon SQS queue to take action on. + * @param entries + * A list of SendMessageBatchRequestEntry items. + * + * @return The response from the SendMessageBatch service method, as + * returned by AmazonSQS. + * + * @throws BatchEntryIdsNotDistinctException + * @throws TooManyEntriesInBatchRequestException + * @throws BatchRequestTooLongException + * @throws UnsupportedOperationException + * @throws InvalidBatchEntryIdException + * @throws EmptyBatchRequestException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public SendMessageBatchResult sendMessageBatch(String queueUrl, List entries) { + SendMessageBatchRequest sendMessageBatchRequest = new SendMessageBatchRequest(queueUrl, entries); + return sendMessageBatch(sendMessageBatchRequest); + } + + /** + *

+ * Deletes up to ten messages from the specified queue. This is a batch + * version of DeleteMessage. The result of the delete action on each message + * is reported individually in the response. Also deletes the message + * payloads from Amazon S3 when necessary. + *

+ *

+ * IMPORTANT: Because the batch request can result in a combination + * of successful and unsuccessful actions, you should check for batch errors + * even when the call returns an HTTP status code of 200. + *

+ *

+ * NOTE:Some API actions take lists of parameters. These lists are + * specified using the param.n notation. Values of n are integers starting + * from 1. For example, a parameter list with two elements looks like this: + *

+ *

+ * &Attribute.1=this + *

+ *

+ * &Attribute.2=that + *

+ * + * @param deleteMessageBatchRequest + * Container for the necessary parameters to execute the + * DeleteMessageBatch service method on AmazonSQS. + * + * @return The response from the DeleteMessageBatch service method, as + * returned by AmazonSQS. + * + * @throws BatchEntryIdsNotDistinctException + * @throws TooManyEntriesInBatchRequestException + * @throws InvalidBatchEntryIdException + * @throws EmptyBatchRequestException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public DeleteMessageBatchResult deleteMessageBatch(DeleteMessageBatchRequest deleteMessageBatchRequest) { + + if (deleteMessageBatchRequest == null) { + String errorMessage = "deleteMessageBatchRequest cannot be null."; + LOG.error(errorMessage); + throw new AmazonClientException(errorMessage); + } + + deleteMessageBatchRequest.getRequestClientOptions().appendUserAgent(USER_AGENT_HEADER); + + if (!clientConfiguration.isPayloadSupportEnabled()) { + return super.deleteMessageBatch(deleteMessageBatchRequest); + } + + for (DeleteMessageBatchRequestEntry entry : deleteMessageBatchRequest.getEntries()) { + String receiptHandle = entry.getReceiptHandle(); + String origReceiptHandle = receiptHandle; + + // Update original receipt handle if needed + if (isS3ReceiptHandle(receiptHandle)) { + origReceiptHandle = getOrigReceiptHandle(receiptHandle); + // Delete s3 payload if needed + if (clientConfiguration.doesCleanupS3Payload()) { + String messagePointer = getMessagePointerFromModifiedReceiptHandle(receiptHandle); + payloadStore.deleteOriginalPayload(messagePointer); } + } - ReceiveMessageResult receiveMessageResult = super.receiveMessage(receiveMessageRequest); - - List messages = receiveMessageResult.getMessages(); - for (Message message : messages) { - - // for each received message check if they are stored in S3. - MessageAttributeValue largePayloadAttributeValue = message.getMessageAttributes().get( - SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME); - if (largePayloadAttributeValue != null) { - String messageBody = message.getBody(); - - // read the S3 pointer from the message body JSON string. - MessageS3Pointer s3Pointer = readMessageS3PointerFromJSON(messageBody); - - String s3MsgBucketName = s3Pointer.getS3BucketName(); - String s3MsgKey = s3Pointer.getS3Key(); - - String origMsgBody = getTextFromS3(s3MsgBucketName, s3MsgKey); - LOG.info("S3 object read, Bucket name: " + s3MsgBucketName + ", Object key: " + s3MsgKey + "."); - - message.setBody(origMsgBody); - - // remove the additional attribute before returning the message - // to user. - message.getMessageAttributes().remove(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME); - - // Embed s3 object pointer in the receipt handle. - String modifiedReceiptHandle = embedS3PointerInReceiptHandle(message.getReceiptHandle(), - s3MsgBucketName, s3MsgKey); - - message.setReceiptHandle(modifiedReceiptHandle); - } - } - return receiveMessageResult; - } - - /** - *

- * Retrieves one or more messages, with a maximum limit of 10 messages, from - * the specified queue. Downloads the message payloads from Amazon S3 when - * necessary. Long poll support is enabled by using the - * WaitTimeSeconds parameter. For more information, see Amazon SQS Long Poll in the Amazon SQS Developer Guide . - *

- *

- * Short poll is the default behavior where a weighted random set of - * machines is sampled on a ReceiveMessage call. This means - * only the messages on the sampled machines are returned. If the number of - * messages in the queue is small (less than 1000), it is likely you will - * get fewer messages than you requested per ReceiveMessage - * call. If the number of messages in the queue is extremely small, you - * might not receive any messages in a particular - * ReceiveMessage response; in which case you should repeat the - * request. - *

- *

- * For each message returned, the response includes the following: - *

- * - *
    - *
  • - *

    - * Message body - *

    - *
  • - *
  • - *

    - * MD5 digest of the message body. For information about MD5, go to - * http://www.faqs.org/rfcs/rfc1321.html . - *

    - *
  • - *
  • - *

    - * Message ID you received when you sent the message to the queue. - *

    - *
  • - *
  • - *

    - * Receipt handle. - *

    - *
  • - *
  • - *

    - * Message attributes. - *

    - *
  • - *
  • - *

    - * MD5 digest of the message attributes. - *

    - *
  • - * - *
- *

- * The receipt handle is the identifier you must provide when deleting the - * message. For more information, see Queue and Message Identifiers in the Amazon SQS Developer - * Guide . - *

- *

- * You can provide the VisibilityTimeout parameter in your - * request, which will be applied to the messages that Amazon SQS returns in - * the response. If you do not include the parameter, the overall visibility - * timeout for the queue is used for the returned messages. For more - * information, see Visibility Timeout in the Amazon SQS Developer Guide . - *

- *

- * NOTE: Going forward, new attributes might be added. If you are - * writing code that calls this action, we recommend that you structure your - * code so that it can handle new attributes gracefully. - *

- * - * @param queueUrl - * The URL of the Amazon SQS queue to take action on. - * - * @return The response from the ReceiveMessage service method, as returned - * by AmazonSQS. - * - * @throws OverLimitException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public ReceiveMessageResult receiveMessage(String queueUrl) { - ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(queueUrl); - return receiveMessage(receiveMessageRequest); - } - - /** - *

- * Deletes the specified message from the specified queue and deletes the - * message payload from Amazon S3 when necessary. You specify the message by - * using the message's receipt handle and not the - * message ID you received when you sent the message. Even if - * the message is locked by another reader due to the visibility timeout - * setting, it is still deleted from the queue. If you leave a message in - * the queue for longer than the queue's configured retention period, Amazon - * SQS automatically deletes it. - *

- *

- * NOTE: The receipt handle is associated with a specific instance of - * receiving the message. If you receive a message more than once, the - * receipt handle you get each time you receive the message is different. - * When you request DeleteMessage, if you don't provide the most recently - * received receipt handle for the message, the request will still succeed, - * but the message might not be deleted. - *

- *

- * IMPORTANT: It is possible you will receive a message even after - * you have deleted it. This might happen on rare occasions if one of the - * servers storing a copy of the message is unavailable when you request to - * delete the message. The copy remains on the server and might be returned - * to you again on a subsequent receive request. You should create your - * system to be idempotent so that receiving a particular message more than - * once is not a problem. - *

- * - * @param deleteMessageRequest - * Container for the necessary parameters to execute the - * DeleteMessage service method on AmazonSQS. - * - * @return The response from the DeleteMessage service method, as returned - * by AmazonSQS. - * - * @throws ReceiptHandleIsInvalidException - * @throws InvalidIdFormatException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public DeleteMessageResult deleteMessage(DeleteMessageRequest deleteMessageRequest) { - - if (deleteMessageRequest == null) { - String errorMessage = "deleteMessageRequest cannot be null."; - LOG.error(errorMessage); - throw new AmazonClientException(errorMessage); - } - - deleteMessageRequest.getRequestClientOptions().appendUserAgent(SQSExtendedClientConstants.USER_AGENT_HEADER); - - if (!clientConfiguration.isLargePayloadSupportEnabled()) { - return super.deleteMessage(deleteMessageRequest); - } - - String receiptHandle = deleteMessageRequest.getReceiptHandle(); - String origReceiptHandle = receiptHandle; - if (isS3ReceiptHandle(receiptHandle)) { - deleteMessagePayloadFromS3(receiptHandle); - origReceiptHandle = getOrigReceiptHandle(receiptHandle); - } - deleteMessageRequest.setReceiptHandle(origReceiptHandle); - return super.deleteMessage(deleteMessageRequest); - } - - /** - *

- * Deletes the specified message from the specified queue and deletes the - * message payload from Amazon S3 when necessary. You specify the message by - * using the message's receipt handle and not the - * message ID you received when you sent the message. Even if - * the message is locked by another reader due to the visibility timeout - * setting, it is still deleted from the queue. If you leave a message in - * the queue for longer than the queue's configured retention period, Amazon - * SQS automatically deletes it. - *

- *

- * NOTE: The receipt handle is associated with a specific instance of - * receiving the message. If you receive a message more than once, the - * receipt handle you get each time you receive the message is different. - * When you request DeleteMessage, if you don't provide the most recently - * received receipt handle for the message, the request will still succeed, - * but the message might not be deleted. - *

- *

- * IMPORTANT: It is possible you will receive a message even after - * you have deleted it. This might happen on rare occasions if one of the - * servers storing a copy of the message is unavailable when you request to - * delete the message. The copy remains on the server and might be returned - * to you again on a subsequent receive request. You should create your - * system to be idempotent so that receiving a particular message more than - * once is not a problem. - *

- * - * @param queueUrl - * The URL of the Amazon SQS queue to take action on. - * @param receiptHandle - * The receipt handle associated with the message to delete. - * - * @return The response from the DeleteMessage service method, as returned - * by AmazonSQS. - * - * @throws ReceiptHandleIsInvalidException - * @throws InvalidIdFormatException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public DeleteMessageResult deleteMessage(String queueUrl, String receiptHandle) { - DeleteMessageRequest deleteMessageRequest = new DeleteMessageRequest(queueUrl, receiptHandle); - return deleteMessage(deleteMessageRequest); - } - - /** - * Simplified method form for invoking the ChangeMessageVisibility - * operation. - * - * @see #changeMessageVisibility(ChangeMessageVisibilityRequest) - */ - public ChangeMessageVisibilityResult changeMessageVisibility(String queueUrl, - String receiptHandle, - Integer visibilityTimeout) { - ChangeMessageVisibilityRequest changeMessageVisibilityRequest = - new ChangeMessageVisibilityRequest(queueUrl, receiptHandle, visibilityTimeout); - return changeMessageVisibility(changeMessageVisibilityRequest); - } - - /** - *

- * Changes the visibility timeout of a specified message in a queue to a new - * value. The maximum allowed timeout value you can set the value to is 12 - * hours. This means you can't extend the timeout of a message in an - * existing queue to more than a total visibility timeout of 12 hours. (For - * more information visibility timeout, see Visibility Timeout in the Amazon SQS Developer Guide .) - *

- *

- * For example, let's say you have a message and its default message - * visibility timeout is 30 minutes. You could call - * ChangeMessageVisiblity with a value of two hours and the - * effective timeout would be two hours and 30 minutes. When that time comes - * near you could again extend the time out by calling - * ChangeMessageVisiblity, but this time the maximum allowed timeout would - * be 9 hours and 30 minutes. - *

- *

- * NOTE: There is a 120,000 limit for the number of inflight messages - * per queue. Messages are inflight after they have been received from the - * queue by a consuming component, but have not yet been deleted from the - * queue. If you reach the 120,000 limit, you will receive an OverLimit - * error message from Amazon SQS. To help avoid reaching the limit, you - * should delete the messages from the queue after they have been processed. - * You can also increase the number of queues you use to process the - * messages. - *

- *

- * IMPORTANT:If you attempt to set the VisibilityTimeout to an amount - * more than the maximum time left, Amazon SQS returns an error. It will not - * automatically recalculate and increase the timeout to the maximum time - * remaining. - *

- *

- * IMPORTANT:Unlike with a queue, when you change the visibility - * timeout for a specific message, that timeout value is applied immediately - * but is not saved in memory for that message. If you don't delete a - * message after it is received, the visibility timeout for the message the - * next time it is received reverts to the original timeout value, not the - * value you set with the ChangeMessageVisibility action. - *

- * - * @param changeMessageVisibilityRequest - * Container for the necessary parameters to execute the - * ChangeMessageVisibility service method on AmazonSQS. - * - * - * @throws ReceiptHandleIsInvalidException - * @throws MessageNotInflightException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public ChangeMessageVisibilityResult changeMessageVisibility(ChangeMessageVisibilityRequest changeMessageVisibilityRequest) - throws AmazonServiceException, AmazonClientException { - - if (isS3ReceiptHandle(changeMessageVisibilityRequest.getReceiptHandle())) { - changeMessageVisibilityRequest.setReceiptHandle( - getOrigReceiptHandle(changeMessageVisibilityRequest.getReceiptHandle())); - } - return amazonSqsToBeExtended.changeMessageVisibility(changeMessageVisibilityRequest); - } - - /** - *

- * Delivers up to ten messages to the specified queue. This is a batch - * version of SendMessage. The result of the send action on each message is - * reported individually in the response. Uploads message payloads to Amazon - * S3 when necessary. - *

- *

- * If the DelaySeconds parameter is not specified for an entry, - * the default for the queue is used. - *

- *

- * IMPORTANT:The following list shows the characters (in Unicode) - * that are allowed in your message, according to the W3C XML specification. - * For more information, go to http://www.faqs.org/rfcs/rfc1321.html. If you - * send any characters that are not included in the list, your request will - * be rejected. #x9 | #xA | #xD | [#x20 to #xD7FF] | [#xE000 to #xFFFD] | - * [#x10000 to #x10FFFF] - *

- *

- * IMPORTANT: Because the batch request can result in a combination - * of successful and unsuccessful actions, you should check for batch errors - * even when the call returns an HTTP status code of 200. - *

- * IMPORTANT: The input object may be modified by the method.

- *

- * NOTE:Some API actions take lists of parameters. These lists are - * specified using the param.n notation. Values of n are integers starting - * from 1. For example, a parameter list with two elements looks like this: - *

- *

- * &Attribute.1=this - *

- *

- * &Attribute.2=that - *

- * - * @param sendMessageBatchRequest - * Container for the necessary parameters to execute the - * SendMessageBatch service method on AmazonSQS. - * - * @return The response from the SendMessageBatch service method, as - * returned by AmazonSQS. - * - * @throws BatchEntryIdsNotDistinctException - * @throws TooManyEntriesInBatchRequestException - * @throws BatchRequestTooLongException - * @throws UnsupportedOperationException - * @throws InvalidBatchEntryIdException - * @throws EmptyBatchRequestException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public SendMessageBatchResult sendMessageBatch(SendMessageBatchRequest sendMessageBatchRequest) { - - if (sendMessageBatchRequest == null) { - String errorMessage = "sendMessageBatchRequest cannot be null."; - LOG.error(errorMessage); - throw new AmazonClientException(errorMessage); - } - - sendMessageBatchRequest.getRequestClientOptions().appendUserAgent(SQSExtendedClientConstants.USER_AGENT_HEADER); - - if (!clientConfiguration.isLargePayloadSupportEnabled()) { - return super.sendMessageBatch(sendMessageBatchRequest); - } - - List batchEntries = sendMessageBatchRequest.getEntries(); - - int index = 0; - for (SendMessageBatchRequestEntry entry : batchEntries) { - if (clientConfiguration.isAlwaysThroughS3() || isLarge(entry)) { - batchEntries.set(index, storeMessageInS3(entry)); - } - ++index; - } - - return super.sendMessageBatch(sendMessageBatchRequest); - } - - /** - *

- * Delivers up to ten messages to the specified queue. This is a batch - * version of SendMessage. The result of the send action on each message is - * reported individually in the response. Uploads message payloads to Amazon - * S3 when necessary. - *

- *

- * If the DelaySeconds parameter is not specified for an entry, - * the default for the queue is used. - *

- *

- * IMPORTANT:The following list shows the characters (in Unicode) - * that are allowed in your message, according to the W3C XML specification. - * For more information, go to http://www.faqs.org/rfcs/rfc1321.html. If you - * send any characters that are not included in the list, your request will - * be rejected. #x9 | #xA | #xD | [#x20 to #xD7FF] | [#xE000 to #xFFFD] | - * [#x10000 to #x10FFFF] - *

- *

- * IMPORTANT: Because the batch request can result in a combination - * of successful and unsuccessful actions, you should check for batch errors - * even when the call returns an HTTP status code of 200. - *

- *

- * NOTE:Some API actions take lists of parameters. These lists are - * specified using the param.n notation. Values of n are integers starting - * from 1. For example, a parameter list with two elements looks like this: - *

- *

- * &Attribute.1=this - *

- *

- * &Attribute.2=that - *

- * - * @param queueUrl - * The URL of the Amazon SQS queue to take action on. - * @param entries - * A list of SendMessageBatchRequestEntry items. - * - * @return The response from the SendMessageBatch service method, as - * returned by AmazonSQS. - * - * @throws BatchEntryIdsNotDistinctException - * @throws TooManyEntriesInBatchRequestException - * @throws BatchRequestTooLongException - * @throws UnsupportedOperationException - * @throws InvalidBatchEntryIdException - * @throws EmptyBatchRequestException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public SendMessageBatchResult sendMessageBatch(String queueUrl, List entries) { - SendMessageBatchRequest sendMessageBatchRequest = new SendMessageBatchRequest(queueUrl, entries); - return sendMessageBatch(sendMessageBatchRequest); - } - - /** - *

- * Deletes up to ten messages from the specified queue. This is a batch - * version of DeleteMessage. The result of the delete action on each message - * is reported individually in the response. Also deletes the message - * payloads from Amazon S3 when necessary. - *

- *

- * IMPORTANT: Because the batch request can result in a combination - * of successful and unsuccessful actions, you should check for batch errors - * even when the call returns an HTTP status code of 200. - *

- *

- * NOTE:Some API actions take lists of parameters. These lists are - * specified using the param.n notation. Values of n are integers starting - * from 1. For example, a parameter list with two elements looks like this: - *

- *

- * &Attribute.1=this - *

- *

- * &Attribute.2=that - *

- * - * @param deleteMessageBatchRequest - * Container for the necessary parameters to execute the - * DeleteMessageBatch service method on AmazonSQS. - * - * @return The response from the DeleteMessageBatch service method, as - * returned by AmazonSQS. - * - * @throws BatchEntryIdsNotDistinctException - * @throws TooManyEntriesInBatchRequestException - * @throws InvalidBatchEntryIdException - * @throws EmptyBatchRequestException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public DeleteMessageBatchResult deleteMessageBatch(DeleteMessageBatchRequest deleteMessageBatchRequest) { - - if (deleteMessageBatchRequest == null) { - String errorMessage = "deleteMessageBatchRequest cannot be null."; - LOG.error(errorMessage); - throw new AmazonClientException(errorMessage); - } - - deleteMessageBatchRequest.getRequestClientOptions().appendUserAgent( - SQSExtendedClientConstants.USER_AGENT_HEADER); - - if (!clientConfiguration.isLargePayloadSupportEnabled()) { - return super.deleteMessageBatch(deleteMessageBatchRequest); - } - - for (DeleteMessageBatchRequestEntry entry : deleteMessageBatchRequest.getEntries()) { - String receiptHandle = entry.getReceiptHandle(); - String origReceiptHandle = receiptHandle; - if (isS3ReceiptHandle(receiptHandle)) { - deleteMessagePayloadFromS3(receiptHandle); - origReceiptHandle = getOrigReceiptHandle(receiptHandle); - } - entry.setReceiptHandle(origReceiptHandle); - } - return super.deleteMessageBatch(deleteMessageBatchRequest); - } - - /** - *

- * Deletes up to ten messages from the specified queue. This is a batch - * version of DeleteMessage. The result of the delete action on each message - * is reported individually in the response. Also deletes the message - * payloads from Amazon S3 when necessary. - *

- *

- * IMPORTANT: Because the batch request can result in a combination - * of successful and unsuccessful actions, you should check for batch errors - * even when the call returns an HTTP status code of 200. - *

- *

- * NOTE:Some API actions take lists of parameters. These lists are - * specified using the param.n notation. Values of n are integers starting - * from 1. For example, a parameter list with two elements looks like this: - *

- *

- * &Attribute.1=this - *

- *

- * &Attribute.2=that - *

- * - * @param queueUrl - * The URL of the Amazon SQS queue to take action on. - * @param entries - * A list of receipt handles for the messages to be deleted. - * - * @return The response from the DeleteMessageBatch service method, as - * returned by AmazonSQS. - * - * @throws BatchEntryIdsNotDistinctException - * @throws TooManyEntriesInBatchRequestException - * @throws InvalidBatchEntryIdException - * @throws EmptyBatchRequestException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public DeleteMessageBatchResult deleteMessageBatch(String queueUrl, List entries) { - DeleteMessageBatchRequest deleteMessageBatchRequest = new DeleteMessageBatchRequest(queueUrl, entries); - return deleteMessageBatch(deleteMessageBatchRequest); - } - - /** - * Simplified method form for invoking the ChangeMessageVisibilityBatch - * operation. - * - * @see #changeMessageVisibilityBatch(ChangeMessageVisibilityBatchRequest) - */ - public ChangeMessageVisibilityBatchResult changeMessageVisibilityBatch( - String queueUrl, - java.util.List entries) { - ChangeMessageVisibilityBatchRequest changeMessageVisibilityBatchRequest = - new ChangeMessageVisibilityBatchRequest(queueUrl, entries); - return changeMessageVisibilityBatch(changeMessageVisibilityBatchRequest); - } - - /** - *

- * Changes the visibility timeout of multiple messages. This is a batch - * version of ChangeMessageVisibility. The result of the action on each - * message is reported individually in the response. You can send up to 10 - * ChangeMessageVisibility requests with each - * ChangeMessageVisibilityBatch action. - *

- *

- * IMPORTANT:Because the batch request can result in a combination of - * successful and unsuccessful actions, you should check for batch errors - * even when the call returns an HTTP status code of 200. - *

- *

- * NOTE:Some API actions take lists of parameters. These lists are - * specified using the param.n notation. Values of n are integers starting - * from 1. For example, a parameter list with two elements looks like this: - *

- *

- * &Attribute.1=this - *

- *

- * &Attribute.2=that - *

- * - * @param changeMessageVisibilityBatchRequest - * Container for the necessary parameters to execute the - * ChangeMessageVisibilityBatch service method on AmazonSQS. - * - * @return The response from the ChangeMessageVisibilityBatch service - * method, as returned by AmazonSQS. - * - * @throws BatchEntryIdsNotDistinctException - * @throws TooManyEntriesInBatchRequestException - * @throws InvalidBatchEntryIdException - * @throws EmptyBatchRequestException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public ChangeMessageVisibilityBatchResult changeMessageVisibilityBatch( - ChangeMessageVisibilityBatchRequest changeMessageVisibilityBatchRequest) throws AmazonServiceException, - AmazonClientException { - - for (ChangeMessageVisibilityBatchRequestEntry entry : changeMessageVisibilityBatchRequest.getEntries()) { - if (isS3ReceiptHandle(entry.getReceiptHandle())) { - entry.setReceiptHandle(getOrigReceiptHandle(entry.getReceiptHandle())); - } - } - - return amazonSqsToBeExtended.changeMessageVisibilityBatch(changeMessageVisibilityBatchRequest); - } + entry.setReceiptHandle(origReceiptHandle); + } + return super.deleteMessageBatch(deleteMessageBatchRequest); + } + + /** + *

+ * Deletes up to ten messages from the specified queue. This is a batch + * version of DeleteMessage. The result of the delete action on each message + * is reported individually in the response. Also deletes the message + * payloads from Amazon S3 when necessary. + *

+ *

+ * IMPORTANT: Because the batch request can result in a combination + * of successful and unsuccessful actions, you should check for batch errors + * even when the call returns an HTTP status code of 200. + *

+ *

+ * NOTE:Some API actions take lists of parameters. These lists are + * specified using the param.n notation. Values of n are integers starting + * from 1. For example, a parameter list with two elements looks like this: + *

+ *

+ * &Attribute.1=this + *

+ *

+ * &Attribute.2=that + *

+ * + * @param queueUrl + * The URL of the Amazon SQS queue to take action on. + * @param entries + * A list of receipt handles for the messages to be deleted. + * + * @return The response from the DeleteMessageBatch service method, as + * returned by AmazonSQS. + * + * @throws BatchEntryIdsNotDistinctException + * @throws TooManyEntriesInBatchRequestException + * @throws InvalidBatchEntryIdException + * @throws EmptyBatchRequestException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public DeleteMessageBatchResult deleteMessageBatch(String queueUrl, List entries) { + DeleteMessageBatchRequest deleteMessageBatchRequest = new DeleteMessageBatchRequest(queueUrl, entries); + return deleteMessageBatch(deleteMessageBatchRequest); + } + + /** + * Simplified method form for invoking the ChangeMessageVisibilityBatch + * operation. + * + * @see #changeMessageVisibilityBatch(ChangeMessageVisibilityBatchRequest) + */ + public ChangeMessageVisibilityBatchResult changeMessageVisibilityBatch( + String queueUrl, + java.util.List entries) { + ChangeMessageVisibilityBatchRequest changeMessageVisibilityBatchRequest = + new ChangeMessageVisibilityBatchRequest(queueUrl, entries); + return changeMessageVisibilityBatch(changeMessageVisibilityBatchRequest); + } + + /** + *

+ * Changes the visibility timeout of multiple messages. This is a batch + * version of ChangeMessageVisibility. The result of the action on each + * message is reported individually in the response. You can send up to 10 + * ChangeMessageVisibility requests with each + * ChangeMessageVisibilityBatch action. + *

+ *

+ * IMPORTANT:Because the batch request can result in a combination of + * successful and unsuccessful actions, you should check for batch errors + * even when the call returns an HTTP status code of 200. + *

+ *

+ * NOTE:Some API actions take lists of parameters. These lists are + * specified using the param.n notation. Values of n are integers starting + * from 1. For example, a parameter list with two elements looks like this: + *

+ *

+ * &Attribute.1=this + *

+ *

+ * &Attribute.2=that + *

+ * + * @param changeMessageVisibilityBatchRequest + * Container for the necessary parameters to execute the + * ChangeMessageVisibilityBatch service method on AmazonSQS. + * + * @return The response from the ChangeMessageVisibilityBatch service + * method, as returned by AmazonSQS. + * + * @throws BatchEntryIdsNotDistinctException + * @throws TooManyEntriesInBatchRequestException + * @throws InvalidBatchEntryIdException + * @throws EmptyBatchRequestException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public ChangeMessageVisibilityBatchResult changeMessageVisibilityBatch( + ChangeMessageVisibilityBatchRequest changeMessageVisibilityBatchRequest) throws AmazonServiceException, + AmazonClientException { + + for (ChangeMessageVisibilityBatchRequestEntry entry : changeMessageVisibilityBatchRequest.getEntries()) { + if (isS3ReceiptHandle(entry.getReceiptHandle())) { + entry.setReceiptHandle(getOrigReceiptHandle(entry.getReceiptHandle())); + } + } + + return amazonSqsToBeExtended.changeMessageVisibilityBatch(changeMessageVisibilityBatchRequest); + } /** *

@@ -1082,284 +1086,190 @@ public ChangeMessageVisibilityBatchResult changeMessageVisibilityBatch( * either a problem with the data in the request, or a server * side issue. */ - public PurgeQueueResult purgeQueue(PurgeQueueRequest purgeQueueRequest) - throws AmazonServiceException, AmazonClientException { - LOG.warn("Calling purgeQueue deletes SQS messages without deleting their payload from S3."); - - if (purgeQueueRequest == null) { - String errorMessage = "purgeQueueRequest cannot be null."; - LOG.error(errorMessage); - throw new AmazonClientException(errorMessage); - } - - purgeQueueRequest.getRequestClientOptions().appendUserAgent(SQSExtendedClientConstants.USER_AGENT_HEADER); - - return super.purgeQueue(purgeQueueRequest); - } - - private void deleteMessagePayloadFromS3(String receiptHandle) { - String s3MsgBucketName = getFromReceiptHandleByMarker(receiptHandle, - SQSExtendedClientConstants.S3_BUCKET_NAME_MARKER); - String s3MsgKey = getFromReceiptHandleByMarker(receiptHandle, SQSExtendedClientConstants.S3_KEY_MARKER); - try { - clientConfiguration.getAmazonS3Client().deleteObject(s3MsgBucketName, s3MsgKey); - } catch (AmazonServiceException e) { - String errorMessage = "Failed to delete the S3 object which contains the SQS message payload. SQS message was not deleted."; - LOG.error(errorMessage, e); - throw new AmazonServiceException(errorMessage, e); - } catch (AmazonClientException e) { - String errorMessage = "Failed to delete the S3 object which contains the SQS message payload. SQS message was not deleted."; - LOG.error(errorMessage, e); - throw new AmazonClientException(errorMessage, e); - } - LOG.info("S3 object deleted, Bucket name: " + s3MsgBucketName + ", Object key: " + s3MsgKey + "."); - } - - private void checkMessageAttributes(Map messageAttributes) { - int msgAttributesSize = getMsgAttributesSize(messageAttributes); - if (msgAttributesSize > clientConfiguration.getMessageSizeThreshold()) { - String errorMessage = "Total size of Message attributes is " + msgAttributesSize - + " bytes which is larger than the threshold of " + clientConfiguration.getMessageSizeThreshold() - + " Bytes. Consider including the payload in the message body instead of message attributes."; - LOG.error(errorMessage); - throw new AmazonClientException(errorMessage); - } - - int messageAttributesNum = messageAttributes.size(); - if (messageAttributesNum > SQSExtendedClientConstants.MAX_ALLOWED_ATTRIBUTES) { - String errorMessage = "Number of message attributes [" + messageAttributesNum - + "] exceeds the maximum allowed for large-payload messages [" - + SQSExtendedClientConstants.MAX_ALLOWED_ATTRIBUTES + "]."; - LOG.error(errorMessage); - throw new AmazonClientException(errorMessage); - } - - MessageAttributeValue largePayloadAttributeValue = messageAttributes - .get(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME); - if (largePayloadAttributeValue != null) { - String errorMessage = "Message attribute name " + SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME - + " is reserved for use by SQS extended client."; - LOG.error(errorMessage); - throw new AmazonClientException(errorMessage); - } - - } - - private String embedS3PointerInReceiptHandle(String receiptHandle, String s3MsgBucketName, String s3MsgKey) { - String modifiedReceiptHandle = SQSExtendedClientConstants.S3_BUCKET_NAME_MARKER + s3MsgBucketName - + SQSExtendedClientConstants.S3_BUCKET_NAME_MARKER + SQSExtendedClientConstants.S3_KEY_MARKER - + s3MsgKey + SQSExtendedClientConstants.S3_KEY_MARKER + receiptHandle; - return modifiedReceiptHandle; - } - - private MessageS3Pointer readMessageS3PointerFromJSON(String messageBody) { - - MessageS3Pointer s3Pointer = null; - try { - JsonDataConverter jsonDataConverter = new JsonDataConverter(); - s3Pointer = jsonDataConverter.deserializeFromJson(messageBody, MessageS3Pointer.class); - } catch (Exception e) { - String errorMessage = "Failed to read the S3 object pointer from an SQS message. Message was not received."; - LOG.error(errorMessage, e); - throw new AmazonClientException(errorMessage, e); - } - return s3Pointer; - } - - private String getOrigReceiptHandle(String receiptHandle) { - int secondOccurence = receiptHandle.indexOf(SQSExtendedClientConstants.S3_KEY_MARKER, - receiptHandle.indexOf(SQSExtendedClientConstants.S3_KEY_MARKER) + 1); - return receiptHandle.substring(secondOccurence + SQSExtendedClientConstants.S3_KEY_MARKER.length()); - } - - private String getFromReceiptHandleByMarker(String receiptHandle, String marker) { - int firstOccurence = receiptHandle.indexOf(marker); - int secondOccurence = receiptHandle.indexOf(marker, firstOccurence + 1); - return receiptHandle.substring(firstOccurence + marker.length(), secondOccurence); - } - - private boolean isS3ReceiptHandle(String receiptHandle) { - return receiptHandle.contains(SQSExtendedClientConstants.S3_BUCKET_NAME_MARKER) - && receiptHandle.contains(SQSExtendedClientConstants.S3_KEY_MARKER); - } - - private String getTextFromS3(String s3BucketName, String s3Key) { - GetObjectRequest getObjectRequest = new GetObjectRequest(s3BucketName, s3Key); - String embeddedText = null; - S3Object obj = null; - try { - obj = clientConfiguration.getAmazonS3Client().getObject(getObjectRequest); - } catch (AmazonServiceException e) { - String errorMessage = "Failed to get the S3 object which contains the message payload. Message was not received."; - LOG.error(errorMessage, e); - throw new AmazonServiceException(errorMessage, e); - } catch (AmazonClientException e) { - String errorMessage = "Failed to get the S3 object which contains the message payload. Message was not received."; - LOG.error(errorMessage, e); - throw new AmazonClientException(errorMessage, e); - } - S3ObjectInputStream is = obj.getObjectContent(); - try { - embeddedText = IOUtils.toString(is); - } catch (IOException e) { - String errorMessage = "Failure when handling the message which was read from S3 object. Message was not received."; - LOG.error(errorMessage, e); - throw new AmazonClientException(errorMessage, e); - } finally { - IOUtils.closeQuietly(is, LOG); - } - return embeddedText; - } - - private boolean isLarge(SendMessageRequest sendMessageRequest) { - int msgAttributesSize = getMsgAttributesSize(sendMessageRequest.getMessageAttributes()); - long msgBodySize = getStringSizeInBytes(sendMessageRequest.getMessageBody()); - long totalMsgSize = msgAttributesSize + msgBodySize; - return (totalMsgSize > clientConfiguration.getMessageSizeThreshold()); - } - - private boolean isLarge(SendMessageBatchRequestEntry batchEntry) { - int msgAttributesSize = getMsgAttributesSize(batchEntry.getMessageAttributes()); - long msgBodySize = getStringSizeInBytes(batchEntry.getMessageBody()); - long totalMsgSize = msgAttributesSize + msgBodySize; - return (totalMsgSize > clientConfiguration.getMessageSizeThreshold()); - } - - private int getMsgAttributesSize(Map msgAttributes) { - int totalMsgAttributesSize = 0; - for (Entry entry : msgAttributes.entrySet()) { - totalMsgAttributesSize += getStringSizeInBytes(entry.getKey()); - - MessageAttributeValue entryVal = entry.getValue(); - if (entryVal.getDataType() != null) { - totalMsgAttributesSize += getStringSizeInBytes(entryVal.getDataType()); - } - - String stringVal = entryVal.getStringValue(); - if (stringVal != null) { - totalMsgAttributesSize += getStringSizeInBytes(entryVal.getStringValue()); - } - - ByteBuffer binaryVal = entryVal.getBinaryValue(); - if (binaryVal != null) { - totalMsgAttributesSize += binaryVal.array().length; - } - } - return totalMsgAttributesSize; - } - - private SendMessageBatchRequestEntry storeMessageInS3(SendMessageBatchRequestEntry batchEntry) { - - checkMessageAttributes(batchEntry.getMessageAttributes()); - - String s3Key = UUID.randomUUID().toString(); - - // Read the content of the message from message body - String messageContentStr = batchEntry.getMessageBody(); - - Long messageContentSize = getStringSizeInBytes(messageContentStr); - - // Add a new message attribute as a flag - MessageAttributeValue messageAttributeValue = new MessageAttributeValue(); - messageAttributeValue.setDataType("Number"); - messageAttributeValue.setStringValue(messageContentSize.toString()); - batchEntry.addMessageAttributesEntry(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME, messageAttributeValue); - - // Store the message content in S3. - storeTextInS3(s3Key, messageContentStr, messageContentSize); - - LOG.info("S3 object created, Bucket name: " + clientConfiguration.getS3BucketName() + ", Object key: " + s3Key - + "."); - - // Convert S3 pointer (bucket name, key, etc) to JSON string - MessageS3Pointer s3Pointer = new MessageS3Pointer(clientConfiguration.getS3BucketName(), s3Key); - String s3PointerStr = getJSONFromS3Pointer(s3Pointer); - - // Storing S3 pointer in the message body. - batchEntry.setMessageBody(s3PointerStr); - - return batchEntry; - } - - private SendMessageRequest storeMessageInS3(SendMessageRequest sendMessageRequest) { - - checkMessageAttributes(sendMessageRequest.getMessageAttributes()); - - String s3Key = UUID.randomUUID().toString(); - - // Read the content of the message from message body - String messageContentStr = sendMessageRequest.getMessageBody(); - - Long messageContentSize = getStringSizeInBytes(messageContentStr); - - // Add a new message attribute as a flag - MessageAttributeValue messageAttributeValue = new MessageAttributeValue(); - messageAttributeValue.setDataType("Number"); - messageAttributeValue.setStringValue(messageContentSize.toString()); - sendMessageRequest.addMessageAttributesEntry(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME, - messageAttributeValue); - - // Store the message content in S3. - storeTextInS3(s3Key, messageContentStr, messageContentSize); - LOG.info("S3 object created, Bucket name: " + clientConfiguration.getS3BucketName() + ", Object key: " + s3Key - + "."); - - // Convert S3 pointer (bucket name, key, etc) to JSON string - MessageS3Pointer s3Pointer = new MessageS3Pointer(clientConfiguration.getS3BucketName(), s3Key); - - String s3PointerStr = getJSONFromS3Pointer(s3Pointer); - - // Storing S3 pointer in the message body. - sendMessageRequest.setMessageBody(s3PointerStr); - - return sendMessageRequest; - } - - private String getJSONFromS3Pointer(MessageS3Pointer s3Pointer) { - String s3PointerStr = null; - try { - JsonDataConverter jsonDataConverter = new JsonDataConverter(); - s3PointerStr = jsonDataConverter.serializeToJson(s3Pointer); - } catch (Exception e) { - String errorMessage = "Failed to convert S3 object pointer to text. Message was not sent."; - LOG.error(errorMessage, e); - throw new AmazonClientException(errorMessage, e); - } - return s3PointerStr; - } - - private void storeTextInS3(String s3Key, String messageContentStr, Long messageContentSize) { - InputStream messageContentStream = new ByteArrayInputStream(messageContentStr.getBytes(StandardCharsets.UTF_8)); - ObjectMetadata messageContentStreamMetadata = new ObjectMetadata(); - messageContentStreamMetadata.setContentLength(messageContentSize); - PutObjectRequest putObjectRequest = new PutObjectRequest(clientConfiguration.getS3BucketName(), s3Key, - messageContentStream, messageContentStreamMetadata); - try { - clientConfiguration.getAmazonS3Client().putObject(putObjectRequest); - } catch (AmazonServiceException e) { - String errorMessage = "Failed to store the message content in an S3 object. SQS message was not sent."; - LOG.error(errorMessage, e); - throw new AmazonServiceException(errorMessage, e); - } catch (AmazonClientException e) { - String errorMessage = "Failed to store the message content in an S3 object. SQS message was not sent."; - LOG.error(errorMessage, e); - throw new AmazonClientException(errorMessage, e); - } - } - - private static long getStringSizeInBytes(String str) { - CountingOutputStream counterOutputStream = new CountingOutputStream(); - try { - Writer writer = new OutputStreamWriter(counterOutputStream, "UTF-8"); - writer.write(str); - writer.flush(); - writer.close(); - } catch (IOException e) { - String errorMessage = "Failed to calculate the size of message payload."; - LOG.error(errorMessage, e); - throw new AmazonClientException(errorMessage, e); - } - return counterOutputStream.getTotalSize(); - } + public PurgeQueueResult purgeQueue(PurgeQueueRequest purgeQueueRequest) + throws AmazonServiceException, AmazonClientException { + LOG.warn("Calling purgeQueue deletes SQS messages without deleting their payload from S3."); + + if (purgeQueueRequest == null) { + String errorMessage = "purgeQueueRequest cannot be null."; + LOG.error(errorMessage); + throw new AmazonClientException(errorMessage); + } + + purgeQueueRequest.getRequestClientOptions().appendUserAgent(USER_AGENT_HEADER); + + return super.purgeQueue(purgeQueueRequest); + } + + private void checkMessageAttributes(Map messageAttributes) { + int msgAttributesSize = getMsgAttributesSize(messageAttributes); + if (msgAttributesSize > clientConfiguration.getPayloadSizeThreshold()) { + String errorMessage = "Total size of Message attributes is " + msgAttributesSize + + " bytes which is larger than the threshold of " + clientConfiguration.getPayloadSizeThreshold() + + " Bytes. Consider including the payload in the message body instead of message attributes."; + LOG.error(errorMessage); + throw new AmazonClientException(errorMessage); + } + + int messageAttributesNum = messageAttributes.size(); + if (messageAttributesNum > SQSExtendedClientConstants.MAX_ALLOWED_ATTRIBUTES) { + String errorMessage = "Number of message attributes [" + messageAttributesNum + + "] exceeds the maximum allowed for large-payload messages [" + + SQSExtendedClientConstants.MAX_ALLOWED_ATTRIBUTES + "]."; + LOG.error(errorMessage); + throw new AmazonClientException(errorMessage); + } + Optional largePayloadAttributeName = getReservedAttributeNameIfPresent(messageAttributes); + + if (largePayloadAttributeName.isPresent()) { + String errorMessage = "Message attribute name " + largePayloadAttributeName.get() + + " is reserved for use by SQS extended client."; + LOG.error(errorMessage); + throw new AmazonClientException(errorMessage); + } + } + + /** + * TODO: Wrap the message pointer as-is to the receiptHandle so that it can be generic + * and does not use any LargeMessageStore implementation specific details. + */ + private String embedS3PointerInReceiptHandle(String receiptHandle, String pointer) { + PayloadS3Pointer s3Pointer = PayloadS3Pointer.fromJson(pointer); + String s3MsgBucketName = s3Pointer.getS3BucketName(); + String s3MsgKey = s3Pointer.getS3Key(); + + String modifiedReceiptHandle = SQSExtendedClientConstants.S3_BUCKET_NAME_MARKER + s3MsgBucketName + + SQSExtendedClientConstants.S3_BUCKET_NAME_MARKER + SQSExtendedClientConstants.S3_KEY_MARKER + + s3MsgKey + SQSExtendedClientConstants.S3_KEY_MARKER + receiptHandle; + return modifiedReceiptHandle; + } + + private String getOrigReceiptHandle(String receiptHandle) { + int secondOccurence = receiptHandle.indexOf(SQSExtendedClientConstants.S3_KEY_MARKER, + receiptHandle.indexOf(SQSExtendedClientConstants.S3_KEY_MARKER) + 1); + return receiptHandle.substring(secondOccurence + SQSExtendedClientConstants.S3_KEY_MARKER.length()); + } + + private String getFromReceiptHandleByMarker(String receiptHandle, String marker) { + int firstOccurence = receiptHandle.indexOf(marker); + int secondOccurence = receiptHandle.indexOf(marker, firstOccurence + 1); + return receiptHandle.substring(firstOccurence + marker.length(), secondOccurence); + } + + private boolean isS3ReceiptHandle(String receiptHandle) { + return receiptHandle.contains(SQSExtendedClientConstants.S3_BUCKET_NAME_MARKER) + && receiptHandle.contains(SQSExtendedClientConstants.S3_KEY_MARKER); + } + + private String getMessagePointerFromModifiedReceiptHandle(String receiptHandle) { + String s3MsgBucketName = getFromReceiptHandleByMarker(receiptHandle, SQSExtendedClientConstants.S3_BUCKET_NAME_MARKER); + String s3MsgKey = getFromReceiptHandleByMarker(receiptHandle, SQSExtendedClientConstants.S3_KEY_MARKER); + + PayloadS3Pointer payloadS3Pointer = new PayloadS3Pointer(s3MsgBucketName, s3MsgKey); + return payloadS3Pointer.toJson(); + } + + private boolean isLarge(SendMessageRequest sendMessageRequest) { + int msgAttributesSize = getMsgAttributesSize(sendMessageRequest.getMessageAttributes()); + long msgBodySize = Util.getStringSizeInBytes(sendMessageRequest.getMessageBody()); + long totalMsgSize = msgAttributesSize + msgBodySize; + return (totalMsgSize > clientConfiguration.getPayloadSizeThreshold()); + } + + private boolean isLarge(SendMessageBatchRequestEntry batchEntry) { + int msgAttributesSize = getMsgAttributesSize(batchEntry.getMessageAttributes()); + long msgBodySize = Util.getStringSizeInBytes(batchEntry.getMessageBody()); + long totalMsgSize = msgAttributesSize + msgBodySize; + return (totalMsgSize > clientConfiguration.getPayloadSizeThreshold()); + } + + private Optional getReservedAttributeNameIfPresent(Map msgAttributes) { + String reservedAttributeName = null; + if (msgAttributes.containsKey(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME)) { + reservedAttributeName = SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME; + } else if (msgAttributes.containsKey(LEGACY_RESERVED_ATTRIBUTE_NAME)) { + reservedAttributeName = LEGACY_RESERVED_ATTRIBUTE_NAME; + } + return Optional.ofNullable(reservedAttributeName); + } + + private int getMsgAttributesSize(Map msgAttributes) { + int totalMsgAttributesSize = 0; + for (Entry entry : msgAttributes.entrySet()) { + totalMsgAttributesSize += Util.getStringSizeInBytes(entry.getKey()); + + MessageAttributeValue entryVal = entry.getValue(); + if (entryVal.getDataType() != null) { + totalMsgAttributesSize += Util.getStringSizeInBytes(entryVal.getDataType()); + } + + String stringVal = entryVal.getStringValue(); + if (stringVal != null) { + totalMsgAttributesSize += Util.getStringSizeInBytes(entryVal.getStringValue()); + } + + ByteBuffer binaryVal = entryVal.getBinaryValue(); + if (binaryVal != null) { + totalMsgAttributesSize += binaryVal.array().length; + } + } + return totalMsgAttributesSize; + } + + private SendMessageBatchRequestEntry storeMessageInS3(SendMessageBatchRequestEntry batchEntry) { + + // Read the content of the message from message body + String messageContentStr = batchEntry.getMessageBody(); + + Long messageContentSize = Util.getStringSizeInBytes(messageContentStr); + + // Add a new message attribute as a flag + MessageAttributeValue messageAttributeValue = new MessageAttributeValue(); + messageAttributeValue.setDataType("Number"); + messageAttributeValue.setStringValue(messageContentSize.toString()); + + if (!clientConfiguration.usesLegacyReservedAttributeName()) { + batchEntry.addMessageAttributesEntry(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME, + messageAttributeValue); + } else { + batchEntry.addMessageAttributesEntry(LEGACY_RESERVED_ATTRIBUTE_NAME, + messageAttributeValue); + } + + // Store the message content in S3. + String largeMessagePointer = payloadStore.storeOriginalPayload(messageContentStr, + messageContentSize); + batchEntry.setMessageBody(largeMessagePointer); + + return batchEntry; + } + + private SendMessageRequest storeMessageInS3(SendMessageRequest sendMessageRequest) { + + // Read the content of the message from message body + String messageContentStr = sendMessageRequest.getMessageBody(); + + Long messageContentSize = Util.getStringSizeInBytes(messageContentStr); + + // Add a new message attribute as a flag + MessageAttributeValue messageAttributeValue = new MessageAttributeValue(); + messageAttributeValue.setDataType("Number"); + messageAttributeValue.setStringValue(messageContentSize.toString()); + + if (!clientConfiguration.usesLegacyReservedAttributeName()) { + sendMessageRequest.addMessageAttributesEntry(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME, + messageAttributeValue); + } else { + sendMessageRequest.addMessageAttributesEntry(LEGACY_RESERVED_ATTRIBUTE_NAME, + messageAttributeValue); + } + + // Store the message content in S3. + String largeMessagePointer = payloadStore.storeOriginalPayload(messageContentStr, + messageContentSize); + sendMessageRequest.setMessageBody(largeMessagePointer); + + return sendMessageRequest; + } } diff --git a/src/main/java/com/amazon/sqs/javamessaging/AmazonSQSExtendedClientBase.java b/src/main/java/com/amazon/sqs/javamessaging/AmazonSQSExtendedClientBase.java index c1fd0ae..70edbae 100644 --- a/src/main/java/com/amazon/sqs/javamessaging/AmazonSQSExtendedClientBase.java +++ b/src/main/java/com/amazon/sqs/javamessaging/AmazonSQSExtendedClientBase.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2010-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -86,11 +86,11 @@ import java.util.Map; abstract class AmazonSQSExtendedClientBase implements AmazonSQS { - AmazonSQS amazonSqsToBeExtended; + AmazonSQS amazonSqsToBeExtended; - public AmazonSQSExtendedClientBase(AmazonSQS sqsClient) { - amazonSqsToBeExtended = sqsClient; - } + public AmazonSQSExtendedClientBase(AmazonSQS sqsClient) { + amazonSqsToBeExtended = sqsClient; + } /** *

@@ -111,10 +111,10 @@ public AmazonSQSExtendedClientBase(AmazonSQS sqsClient) { * * @param sendMessageRequest Container for the necessary parameters to * execute the SendMessage service method on AmazonSQS. - * + * * @return The response from the SendMessage service method, as returned * by AmazonSQS. - * + * * @throws InvalidMessageContentsException * @throws UnsupportedOperationException * @@ -126,11 +126,11 @@ public AmazonSQSExtendedClientBase(AmazonSQS sqsClient) { * If an error response is returned by AmazonSQS indicating * either a problem with the data in the request, or a server side issue. */ - public SendMessageResult sendMessage(SendMessageRequest sendMessageRequest) { - return amazonSqsToBeExtended.sendMessage(sendMessageRequest); - } + public SendMessageResult sendMessage(SendMessageRequest sendMessageRequest) { + return amazonSqsToBeExtended.sendMessage(sendMessageRequest); + } - /** + /** *

* Retrieves one or more messages, with a maximum limit of 10 messages, * from the specified queue. Long poll support is enabled by using the @@ -152,7 +152,7 @@ public SendMessageResult sendMessage(SendMessageRequest sendMessageRequest) { *

* For each message returned, the response includes the following: *

- * + * *
    *
  • * Message body @@ -180,7 +180,7 @@ public SendMessageResult sendMessage(SendMessageRequest sendMessageRequest) { * MD5 digest of the message attributes. *

    *
  • - * + * *
*

* The receipt handle is the identifier you must provide when deleting @@ -205,10 +205,10 @@ public SendMessageResult sendMessage(SendMessageRequest sendMessageRequest) { * * @param receiveMessageRequest Container for the necessary parameters to * execute the ReceiveMessage service method on AmazonSQS. - * + * * @return The response from the ReceiveMessage service method, as * returned by AmazonSQS. - * + * * @throws OverLimitException * * @throws AmazonClientException @@ -219,9 +219,9 @@ public SendMessageResult sendMessage(SendMessageRequest sendMessageRequest) { * If an error response is returned by AmazonSQS indicating * either a problem with the data in the request, or a server side issue. */ - public ReceiveMessageResult receiveMessage(ReceiveMessageRequest receiveMessageRequest) { - return amazonSqsToBeExtended.receiveMessage(receiveMessageRequest); - } + public ReceiveMessageResult receiveMessage(ReceiveMessageRequest receiveMessageRequest) { + return amazonSqsToBeExtended.receiveMessage(receiveMessageRequest); + } /** *

@@ -256,7 +256,7 @@ public ReceiveMessageResult receiveMessage(ReceiveMessageRequest receiveMessageR * * @return The response from the DeleteMessage service method, as returned * by AmazonSQS. - * + * * @throws ReceiptHandleIsInvalidException * @throws InvalidIdFormatException * @@ -268,1787 +268,1787 @@ public ReceiveMessageResult receiveMessage(ReceiveMessageRequest receiveMessageR * If an error response is returned by AmazonSQS indicating * either a problem with the data in the request, or a server side issue. */ - public DeleteMessageResult deleteMessage(DeleteMessageRequest deleteMessageRequest) { - return amazonSqsToBeExtended.deleteMessage(deleteMessageRequest); - } - - /** - *

- * Delivers a message to the specified queue. With Amazon SQS, you now have - * the ability to send large payload messages that are up to 256KB (262,144 - * bytes) in size. To send large payloads, you must use an AWS SDK that - * supports SigV4 signing. To verify whether SigV4 is supported for an AWS - * SDK, check the SDK release notes. - *

- *

- * IMPORTANT: The following list shows the characters (in Unicode) - * allowed in your message, according to the W3C XML specification. For more - * information, go to http://www.w3.org/TR/REC-xml/#charsets If you send any - * characters not included in the list, your request will be rejected. #x9 | - * #xA | #xD | [#x20 to #xD7FF] | [#xE000 to #xFFFD] | [#x10000 to #x10FFFF] - *

- * - * @param queueUrl - * The URL of the Amazon SQS queue to take action on. - * @param messageBody - * The message to send. String maximum 256 KB in size. For a list - * of allowed characters, see the preceding important note. - * - * @return The response from the SendMessage service method, as returned by - * AmazonSQS. - * - * @throws InvalidMessageContentsException - * @throws UnsupportedOperationException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public SendMessageResult sendMessage(String queueUrl, String messageBody) throws AmazonServiceException, - AmazonClientException { - - return amazonSqsToBeExtended.sendMessage(queueUrl, messageBody); - } - - /** - *

- * Retrieves one or more messages, with a maximum limit of 10 messages, from - * the specified queue. Long poll support is enabled by using the - * WaitTimeSeconds parameter. For more information, see Amazon SQS Long Poll in the Amazon SQS Developer Guide . - *

- *

- * Short poll is the default behavior where a weighted random set of - * machines is sampled on a ReceiveMessage call. This means - * only the messages on the sampled machines are returned. If the number of - * messages in the queue is small (less than 1000), it is likely you will - * get fewer messages than you requested per ReceiveMessage - * call. If the number of messages in the queue is extremely small, you - * might not receive any messages in a particular - * ReceiveMessage response; in which case you should repeat the - * request. - *

- *

- * For each message returned, the response includes the following: - *

- * - *
    - *
  • - *

    - * Message body - *

    - *
  • - *
  • - *

    - * MD5 digest of the message body. For information about MD5, go to - * http://www.faqs.org/rfcs/rfc1321.html . - *

    - *
  • - *
  • - *

    - * Message ID you received when you sent the message to the queue. - *

    - *
  • - *
  • - *

    - * Receipt handle. - *

    - *
  • - *
  • - *

    - * Message attributes. - *

    - *
  • - *
  • - *

    - * MD5 digest of the message attributes. - *

    - *
  • - * - *
- *

- * The receipt handle is the identifier you must provide when deleting the - * message. For more information, see Queue and Message Identifiers in the Amazon SQS Developer - * Guide . - *

- *

- * You can provide the VisibilityTimeout parameter in your - * request, which will be applied to the messages that Amazon SQS returns in - * the response. If you do not include the parameter, the overall visibility - * timeout for the queue is used for the returned messages. For more - * information, see Visibility Timeout in the Amazon SQS Developer Guide . - *

- *

- * NOTE: Going forward, new attributes might be added. If you are - * writing code that calls this action, we recommend that you structure your - * code so that it can handle new attributes gracefully. - *

- * - * @param queueUrl - * The URL of the Amazon SQS queue to take action on. - * - * @return The response from the ReceiveMessage service method, as returned - * by AmazonSQS. - * - * @throws OverLimitException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public ReceiveMessageResult receiveMessage(String queueUrl) throws AmazonServiceException, AmazonClientException { - - return amazonSqsToBeExtended.receiveMessage(queueUrl); - } - - /** - *

- * Deletes the specified message from the specified queue. You specify the - * message by using the message's receipt handle and not the - * message ID you received when you sent the message. Even if - * the message is locked by another reader due to the visibility timeout - * setting, it is still deleted from the queue. If you leave a message in - * the queue for longer than the queue's configured retention period, Amazon - * SQS automatically deletes it. - *

- *

- * NOTE: The receipt handle is associated with a specific instance of - * receiving the message. If you receive a message more than once, the - * receipt handle you get each time you receive the message is different. - * When you request DeleteMessage, if you don't provide the most recently - * received receipt handle for the message, the request will still succeed, - * but the message might not be deleted. - *

- *

- * IMPORTANT: It is possible you will receive a message even after - * you have deleted it. This might happen on rare occasions if one of the - * servers storing a copy of the message is unavailable when you request to - * delete the message. The copy remains on the server and might be returned - * to you again on a subsequent receive request. You should create your - * system to be idempotent so that receiving a particular message more than - * once is not a problem. - *

- * - * @param queueUrl - * The URL of the Amazon SQS queue to take action on. - * @param receiptHandle - * The receipt handle associated with the message to delete. - * - * @return The response from the DeleteMessage service method, as returned - * by AmazonSQS. - * - * @throws ReceiptHandleIsInvalidException - * @throws InvalidIdFormatException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public DeleteMessageResult deleteMessage(String queueUrl, String receiptHandle) - throws AmazonServiceException, AmazonClientException { - - return amazonSqsToBeExtended.deleteMessage(queueUrl, receiptHandle); - } - - /** - *

- * Sets the value of one or more queue attributes. When you change a queue's - * attributes, the change can take up to 60 seconds for most of the - * attributes to propagate throughout the SQS system. Changes made to the - * MessageRetentionPeriod attribute can take up to 15 minutes. - *

- *

- * NOTE:Going forward, new attributes might be added. If you are - * writing code that calls this action, we recommend that you structure your - * code so that it can handle new attributes gracefully. - *

- * - * @param setQueueAttributesRequest - * Container for the necessary parameters to execute the - * SetQueueAttributes service method on AmazonSQS. - * - * - * @throws InvalidAttributeNameException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public SetQueueAttributesResult setQueueAttributes(SetQueueAttributesRequest setQueueAttributesRequest) - throws AmazonServiceException, AmazonClientException { - - return amazonSqsToBeExtended.setQueueAttributes(setQueueAttributesRequest); - - } - - /** - *

- * Changes the visibility timeout of multiple messages. This is a batch - * version of ChangeMessageVisibility. The result of the action on each - * message is reported individually in the response. You can send up to 10 - * ChangeMessageVisibility requests with each - * ChangeMessageVisibilityBatch action. - *

- *

- * IMPORTANT:Because the batch request can result in a combination of - * successful and unsuccessful actions, you should check for batch errors - * even when the call returns an HTTP status code of 200. - *

- *

- * NOTE:Some API actions take lists of parameters. These lists are - * specified using the param.n notation. Values of n are integers starting - * from 1. For example, a parameter list with two elements looks like this: - *

- *

- * &Attribute.1=this - *

- *

- * &Attribute.2=that - *

- * - * @param changeMessageVisibilityBatchRequest - * Container for the necessary parameters to execute the - * ChangeMessageVisibilityBatch service method on AmazonSQS. - * - * @return The response from the ChangeMessageVisibilityBatch service - * method, as returned by AmazonSQS. - * - * @throws BatchEntryIdsNotDistinctException - * @throws TooManyEntriesInBatchRequestException - * @throws InvalidBatchEntryIdException - * @throws EmptyBatchRequestException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public ChangeMessageVisibilityBatchResult changeMessageVisibilityBatch( - ChangeMessageVisibilityBatchRequest changeMessageVisibilityBatchRequest) throws AmazonServiceException, - AmazonClientException { - - return amazonSqsToBeExtended.changeMessageVisibilityBatch(changeMessageVisibilityBatchRequest); - } - - /** - *

- * Changes the visibility timeout of a specified message in a queue to a new - * value. The maximum allowed timeout value you can set the value to is 12 - * hours. This means you can't extend the timeout of a message in an - * existing queue to more than a total visibility timeout of 12 hours. (For - * more information visibility timeout, see Visibility Timeout in the Amazon SQS Developer Guide .) - *

- *

- * For example, let's say you have a message and its default message - * visibility timeout is 30 minutes. You could call - * ChangeMessageVisiblity with a value of two hours and the - * effective timeout would be two hours and 30 minutes. When that time comes - * near you could again extend the time out by calling - * ChangeMessageVisiblity, but this time the maximum allowed timeout would - * be 9 hours and 30 minutes. - *

- *

- * NOTE: There is a 120,000 limit for the number of inflight messages - * per queue. Messages are inflight after they have been received from the - * queue by a consuming component, but have not yet been deleted from the - * queue. If you reach the 120,000 limit, you will receive an OverLimit - * error message from Amazon SQS. To help avoid reaching the limit, you - * should delete the messages from the queue after they have been processed. - * You can also increase the number of queues you use to process the - * messages. - *

- *

- * IMPORTANT:If you attempt to set the VisibilityTimeout to an amount - * more than the maximum time left, Amazon SQS returns an error. It will not - * automatically recalculate and increase the timeout to the maximum time - * remaining. - *

- *

- * IMPORTANT:Unlike with a queue, when you change the visibility - * timeout for a specific message, that timeout value is applied immediately - * but is not saved in memory for that message. If you don't delete a - * message after it is received, the visibility timeout for the message the - * next time it is received reverts to the original timeout value, not the - * value you set with the ChangeMessageVisibility action. - *

- * - * @param changeMessageVisibilityRequest - * Container for the necessary parameters to execute the - * ChangeMessageVisibility service method on AmazonSQS. - * - * - * @throws ReceiptHandleIsInvalidException - * @throws MessageNotInflightException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public ChangeMessageVisibilityResult changeMessageVisibility(ChangeMessageVisibilityRequest changeMessageVisibilityRequest) - throws AmazonServiceException, AmazonClientException { - - return amazonSqsToBeExtended.changeMessageVisibility(changeMessageVisibilityRequest); - } - - /** - *

- * Returns the URL of an existing queue. This action provides a simple way - * to retrieve the URL of an Amazon SQS queue. - *

- *

- * To access a queue that belongs to another AWS account, use the - * QueueOwnerAWSAccountId parameter to specify the account ID - * of the queue's owner. The queue's owner must grant you permission to - * access the queue. For more information about shared queue access, see - * AddPermission or go to Shared Queues in the Amazon SQS Developer Guide . - *

- * - * @param getQueueUrlRequest - * Container for the necessary parameters to execute the - * GetQueueUrl service method on AmazonSQS. - * - * @return The response from the GetQueueUrl service method, as returned by - * AmazonSQS. - * - * @throws QueueDoesNotExistException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public GetQueueUrlResult getQueueUrl(GetQueueUrlRequest getQueueUrlRequest) throws AmazonServiceException, - AmazonClientException { - - return amazonSqsToBeExtended.getQueueUrl(getQueueUrlRequest); - } - - /** - *

- * Revokes any permissions in the queue policy that matches the specified - * Label parameter. Only the owner of the queue can remove - * permissions. - *

- * - * @param removePermissionRequest - * Container for the necessary parameters to execute the - * RemovePermission service method on AmazonSQS. - * - * - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public RemovePermissionResult removePermission(RemovePermissionRequest removePermissionRequest) - throws AmazonServiceException, AmazonClientException { - - return amazonSqsToBeExtended.removePermission(removePermissionRequest); - } - - /** - *

- * Gets attributes for the specified queue. The following attributes are - * supported: - *

    - *
  • All - returns all values.
  • - *
  • ApproximateNumberOfMessages - returns the approximate - * number of visible messages in a queue. For more information, see Resources Required to Process Messages in the Amazon SQS - * Developer Guide .
  • - *
  • ApproximateNumberOfMessagesNotVisible - returns the - * approximate number of messages that are not timed-out and not deleted. - * For more information, see Resources Required to Process Messages in the Amazon SQS - * Developer Guide .
  • - *
  • VisibilityTimeout - returns the visibility timeout for - * the queue. For more information about visibility timeout, see Visibility Timeout in the Amazon SQS Developer Guide .
  • - *
  • CreatedTimestamp - returns the time when the queue was - * created (epoch time in seconds).
  • - *
  • LastModifiedTimestamp - returns the time when the queue - * was last changed (epoch time in seconds).
  • - *
  • Policy - returns the queue's policy.
  • - *
  • MaximumMessageSize - returns the limit of how many bytes - * a message can contain before Amazon SQS rejects it.
  • - *
  • MessageRetentionPeriod - returns the number of seconds - * Amazon SQS retains a message.
  • - *
  • QueueArn - returns the queue's Amazon resource name - * (ARN).
  • - *
  • ApproximateNumberOfMessagesDelayed - returns the - * approximate number of messages that are pending to be added to the queue. - *
  • - *
  • DelaySeconds - returns the default delay on the queue in - * seconds.
  • - *
  • ReceiveMessageWaitTimeSeconds - returns the time for - * which a ReceiveMessage call will wait for a message to arrive.
  • - *
  • RedrivePolicy - returns the parameters for dead letter - * queue functionality of the source queue. For more information about - * RedrivePolicy and dead letter queues, see Using Amazon SQS Dead Letter Queues in the Amazon SQS Developer - * Guide .
  • - * - *
- * - *

- *

- * NOTE:Going forward, new attributes might be added. If you are - * writing code that calls this action, we recommend that you structure your - * code so that it can handle new attributes gracefully. - *

- *

- * NOTE:Some API actions take lists of parameters. These lists are - * specified using the param.n notation. Values of n are integers starting - * from 1. For example, a parameter list with two elements looks like this: - *

- *

- * &Attribute.1=this - *

- *

- * &Attribute.2=that - *

- * - * @param getQueueAttributesRequest - * Container for the necessary parameters to execute the - * GetQueueAttributes service method on AmazonSQS. - * - * @return The response from the GetQueueAttributes service method, as - * returned by AmazonSQS. - * - * @throws InvalidAttributeNameException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public GetQueueAttributesResult getQueueAttributes(GetQueueAttributesRequest getQueueAttributesRequest) - throws AmazonServiceException, AmazonClientException { - - return amazonSqsToBeExtended.getQueueAttributes(getQueueAttributesRequest); - } - - /** - *

- * Delivers up to ten messages to the specified queue. This is a batch - * version of SendMessage. The result of the send action on each message is - * reported individually in the response. The maximum allowed individual - * message size is 256 KB (262,144 bytes). - *

- *

- * The maximum total payload size (i.e., the sum of all a batch's individual - * message lengths) is also 256 KB (262,144 bytes). - *

- *

- * If the DelaySeconds parameter is not specified for an entry, - * the default for the queue is used. - *

- *

- * IMPORTANT:The following list shows the characters (in Unicode) - * that are allowed in your message, according to the W3C XML specification. - * For more information, go to http://www.faqs.org/rfcs/rfc1321.html. If you - * send any characters that are not included in the list, your request will - * be rejected. #x9 | #xA | #xD | [#x20 to #xD7FF] | [#xE000 to #xFFFD] | - * [#x10000 to #x10FFFF] - *

- *

- * IMPORTANT: Because the batch request can result in a combination - * of successful and unsuccessful actions, you should check for batch errors - * even when the call returns an HTTP status code of 200. - *

- *

- * NOTE:Some API actions take lists of parameters. These lists are - * specified using the param.n notation. Values of n are integers starting - * from 1. For example, a parameter list with two elements looks like this: - *

- *

- * &Attribute.1=this - *

- *

- * &Attribute.2=that - *

- * - * @param sendMessageBatchRequest - * Container for the necessary parameters to execute the - * SendMessageBatch service method on AmazonSQS. - * - * @return The response from the SendMessageBatch service method, as - * returned by AmazonSQS. - * - * @throws BatchEntryIdsNotDistinctException - * @throws TooManyEntriesInBatchRequestException - * @throws BatchRequestTooLongException - * @throws UnsupportedOperationException - * @throws InvalidBatchEntryIdException - * @throws EmptyBatchRequestException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public SendMessageBatchResult sendMessageBatch(SendMessageBatchRequest sendMessageBatchRequest) - throws AmazonServiceException, AmazonClientException { - - return amazonSqsToBeExtended.sendMessageBatch(sendMessageBatchRequest); - } - - /** - *

- * Deletes the messages in a queue specified by the queue URL . - *

- *

- * IMPORTANT:When you use the PurgeQueue API, the deleted messages in - * the queue cannot be retrieved. - *

- *

- * When you purge a queue, the message deletion process takes up to 60 - * seconds. All messages sent to the queue before calling - * PurgeQueue will be deleted; messages sent to the queue while - * it is being purged may be deleted. While the queue is being purged, - * messages sent to the queue before PurgeQueue was called may - * be received, but will be deleted within the next minute. - *

- * - * @param purgeQueueRequest - * Container for the necessary parameters to execute the - * PurgeQueue service method on AmazonSQS. - * - * - * @throws PurgeQueueInProgressException - * @throws QueueDoesNotExistException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public PurgeQueueResult purgeQueue(PurgeQueueRequest purgeQueueRequest) - throws AmazonServiceException, AmazonClientException { - - return amazonSqsToBeExtended.purgeQueue(purgeQueueRequest); - - } - - /** - *

- * Returns a list of your queues that have the RedrivePolicy queue attribute - * configured with a dead letter queue. - *

- *

- * For more information about using dead letter queues, see Using Amazon SQS Dead Letter Queues . - *

- * - * @param listDeadLetterSourceQueuesRequest - * Container for the necessary parameters to execute the - * ListDeadLetterSourceQueues service method on AmazonSQS. - * - * @return The response from the ListDeadLetterSourceQueues service method, - * as returned by AmazonSQS. - * - * @throws QueueDoesNotExistException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public ListDeadLetterSourceQueuesResult listDeadLetterSourceQueues( - ListDeadLetterSourceQueuesRequest listDeadLetterSourceQueuesRequest) throws AmazonServiceException, - AmazonClientException { - - return amazonSqsToBeExtended.listDeadLetterSourceQueues(listDeadLetterSourceQueuesRequest); - } - - /** - *

- * Deletes the queue specified by the queue URL , regardless of - * whether the queue is empty. If the specified queue does not exist, Amazon - * SQS returns a successful response. - *

- *

- * IMPORTANT: Use DeleteQueue with care; once you delete your queue, - * any messages in the queue are no longer available. - *

- *

- * When you delete a queue, the deletion process takes up to 60 seconds. - * Requests you send involving that queue during the 60 seconds might - * succeed. For example, a SendMessage request might succeed, but after the - * 60 seconds, the queue and that message you sent no longer exist. Also, - * when you delete a queue, you must wait at least 60 seconds before - * creating a queue with the same name. - *

- *

- * We reserve the right to delete queues that have had no activity for more - * than 30 days. For more information, see How Amazon SQS Queues Work in the Amazon SQS Developer - * Guide . - *

- * - * @param deleteQueueRequest - * Container for the necessary parameters to execute the - * DeleteQueue service method on AmazonSQS. - * - * - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public DeleteQueueResult deleteQueue(DeleteQueueRequest deleteQueueRequest) - throws AmazonServiceException, AmazonClientException { - - return amazonSqsToBeExtended.deleteQueue(deleteQueueRequest); - } - - /** - *

- * Returns a list of your queues. The maximum number of queues that can be - * returned is 1000. If you specify a value for the optional - * QueueNamePrefix parameter, only queues with a name beginning - * with the specified value are returned. - *

- * - * @param listQueuesRequest - * Container for the necessary parameters to execute the - * ListQueues service method on AmazonSQS. - * - * @return The response from the ListQueues service method, as returned by - * AmazonSQS. - * - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public ListQueuesResult listQueues(ListQueuesRequest listQueuesRequest) throws AmazonServiceException, - AmazonClientException { - - return amazonSqsToBeExtended.listQueues(listQueuesRequest); - } - - /** - *

- * Deletes up to ten messages from the specified queue. This is a batch - * version of DeleteMessage. The result of the delete action on each message - * is reported individually in the response. - *

- *

- * IMPORTANT: Because the batch request can result in a combination - * of successful and unsuccessful actions, you should check for batch errors - * even when the call returns an HTTP status code of 200. - *

- *

- * NOTE:Some API actions take lists of parameters. These lists are - * specified using the param.n notation. Values of n are integers starting - * from 1. For example, a parameter list with two elements looks like this: - *

- *

- * &Attribute.1=this - *

- *

- * &Attribute.2=that - *

- * - * @param deleteMessageBatchRequest - * Container for the necessary parameters to execute the - * DeleteMessageBatch service method on AmazonSQS. - * - * @return The response from the DeleteMessageBatch service method, as - * returned by AmazonSQS. - * - * @throws BatchEntryIdsNotDistinctException - * @throws TooManyEntriesInBatchRequestException - * @throws InvalidBatchEntryIdException - * @throws EmptyBatchRequestException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public DeleteMessageBatchResult deleteMessageBatch(DeleteMessageBatchRequest deleteMessageBatchRequest) - throws AmazonServiceException, AmazonClientException { - - return amazonSqsToBeExtended.deleteMessageBatch(deleteMessageBatchRequest); - } - - /** - *

- * Creates a new queue, or returns the URL of an existing one. When you - * request CreateQueue , you provide a name for the queue. To - * successfully create a new queue, you must provide a name that is unique - * within the scope of your own queues. - *

- *

- * NOTE: If you delete a queue, you must wait at least 60 seconds - * before creating a queue with the same name. - *

- *

- * You may pass one or more attributes in the request. If you do not provide - * a value for any attribute, the queue will have the default value for that - * attribute. Permitted attributes are the same that can be set using - * SetQueueAttributes. - *

- *

- * NOTE: Use GetQueueUrl to get a queue's URL. GetQueueUrl requires - * only the QueueName parameter. - *

- *

- * If you provide the name of an existing queue, along with the exact names - * and values of all the queue's attributes, CreateQueue - * returns the queue URL for the existing queue. If the queue name, - * attribute names, or attribute values do not match an existing queue, - * CreateQueue returns an error. - *

- *

- * NOTE:Some API actions take lists of parameters. These lists are - * specified using the param.n notation. Values of n are integers starting - * from 1. For example, a parameter list with two elements looks like this: - *

- *

- * &Attribute.1=this - *

- *

- * &Attribute.2=that - *

- * - * @param createQueueRequest - * Container for the necessary parameters to execute the - * CreateQueue service method on AmazonSQS. - * - * @return The response from the CreateQueue service method, as returned by - * AmazonSQS. - * - * @throws QueueNameExistsException - * @throws QueueDeletedRecentlyException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public CreateQueueResult createQueue(CreateQueueRequest createQueueRequest) throws AmazonServiceException, - AmazonClientException { - - return amazonSqsToBeExtended.createQueue(createQueueRequest); - } - - /** - *

- * Adds a permission to a queue for a specific - * principal . This allows for sharing access to the queue. - *

- *

- * When you create a queue, you have full control access rights for the - * queue. Only you (as owner of the queue) can grant or deny permissions to - * the queue. For more information about these permissions, see Shared Queues in the Amazon SQS Developer Guide . - *

- *

- * NOTE: AddPermission writes an Amazon SQS-generated policy. If you - * want to write your own policy, use SetQueueAttributes to upload your - * policy. For more information about writing your own policy, see Using The - * Access Policy Language in the Amazon SQS Developer Guide. - *

- *

- * NOTE:Some API actions take lists of parameters. These lists are - * specified using the param.n notation. Values of n are integers starting - * from 1. For example, a parameter list with two elements looks like this: - *

- *

- * &Attribute.1=this - *

- *

- * &Attribute.2=that - *

- * - * @param addPermissionRequest - * Container for the necessary parameters to execute the - * AddPermission service method on AmazonSQS. - * - * - * @throws OverLimitException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public AddPermissionResult addPermission(AddPermissionRequest addPermissionRequest) - throws AmazonServiceException, AmazonClientException { - - return amazonSqsToBeExtended.addPermission(addPermissionRequest); - } - - /** - *

- * Returns a list of your queues. The maximum number of queues that can be - * returned is 1000. If you specify a value for the optional - * QueueNamePrefix parameter, only queues with a name beginning - * with the specified value are returned. - *

- * - * @return The response from the ListQueues service method, as returned by - * AmazonSQS. - * - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public ListQueuesResult listQueues() throws AmazonServiceException, AmazonClientException { - - return amazonSqsToBeExtended.listQueues(); - } - - /** - *

- * Sets the value of one or more queue attributes. When you change a queue's - * attributes, the change can take up to 60 seconds for most of the - * attributes to propagate throughout the SQS system. Changes made to the - * MessageRetentionPeriod attribute can take up to 15 minutes. - *

- *

- * NOTE:Going forward, new attributes might be added. If you are - * writing code that calls this action, we recommend that you structure your - * code so that it can handle new attributes gracefully. - *

- * - * @param queueUrl - * The URL of the Amazon SQS queue to take action on. - * @param attributes - * A map of attributes to set. - *

- * The following lists the names, descriptions, and values of the - * special request parameters the SetQueueAttributes - * action uses: - *

- *

    - *
  • DelaySeconds - The time in seconds that the - * delivery of all messages in the queue will be delayed. An - * integer from 0 to 900 (15 minutes). The default for this - * attribute is 0 (zero).
  • - *
  • MaximumMessageSize - The limit of how many - * bytes a message can contain before Amazon SQS rejects it. An - * integer from 1024 bytes (1 KiB) up to 262144 bytes (256 KiB). - * The default for this attribute is 262144 (256 KiB).
  • - *
  • MessageRetentionPeriod - The number of - * seconds Amazon SQS retains a message. Integer representing - * seconds, from 60 (1 minute) to 1209600 (14 days). The default - * for this attribute is 345600 (4 days).
  • - *
  • Policy - The queue's policy. A valid AWS - * policy. For more information about policy structure, see Overview of AWS IAM Policies in the Amazon IAM User - * Guide.
  • - *
  • ReceiveMessageWaitTimeSeconds - The time for - * which a ReceiveMessage call will wait for a message to arrive. - * An integer from 0 to 20 (seconds). The default for this - * attribute is 0.
  • - *
  • VisibilityTimeout - The visibility timeout - * for the queue. An integer from 0 to 43200 (12 hours). The - * default for this attribute is 30. For more information about - * visibility timeout, see Visibility Timeout in the Amazon - * SQS Developer Guide.
  • - *
  • RedrivePolicy - The parameters for dead - * letter queue functionality of the source queue. For more - * information about RedrivePolicy and dead letter queues, see - * Using Amazon SQS Dead Letter Queues in the Amazon SQS - * Developer Guide.
  • - *
- * - * @return The response from the SetQueueAttributes service method, as - * returned by AmazonSQS. - * - * @throws InvalidAttributeNameException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public SetQueueAttributesResult setQueueAttributes(String queueUrl, Map attributes) - throws AmazonServiceException, AmazonClientException { - - return amazonSqsToBeExtended.setQueueAttributes(queueUrl, attributes); - } - - /** - *

- * Changes the visibility timeout of multiple messages. This is a batch - * version of ChangeMessageVisibility. The result of the action on each - * message is reported individually in the response. You can send up to 10 - * ChangeMessageVisibility requests with each - * ChangeMessageVisibilityBatch action. - *

- *

- * IMPORTANT:Because the batch request can result in a combination of - * successful and unsuccessful actions, you should check for batch errors - * even when the call returns an HTTP status code of 200. - *

- *

- * NOTE:Some API actions take lists of parameters. These lists are - * specified using the param.n notation. Values of n are integers starting - * from 1. For example, a parameter list with two elements looks like this: - *

- *

- * &Attribute.1=this - *

- *

- * &Attribute.2=that - *

- * - * @param queueUrl - * The URL of the Amazon SQS queue to take action on. - * @param entries - * A list of receipt handles of the messages for which the - * visibility timeout must be changed. - * - * @return The response from the ChangeMessageVisibilityBatch service - * method, as returned by AmazonSQS. - * - * @throws BatchEntryIdsNotDistinctException - * @throws TooManyEntriesInBatchRequestException - * @throws InvalidBatchEntryIdException - * @throws EmptyBatchRequestException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public ChangeMessageVisibilityBatchResult changeMessageVisibilityBatch(String queueUrl, - List entries) throws AmazonServiceException, - AmazonClientException { - - return amazonSqsToBeExtended.changeMessageVisibilityBatch(queueUrl, entries); - } - - /** - *

- * Changes the visibility timeout of a specified message in a queue to a new - * value. The maximum allowed timeout value you can set the value to is 12 - * hours. This means you can't extend the timeout of a message in an - * existing queue to more than a total visibility timeout of 12 hours. (For - * more information visibility timeout, see Visibility Timeout in the Amazon SQS Developer Guide .) - *

- *

- * For example, let's say you have a message and its default message - * visibility timeout is 30 minutes. You could call - * ChangeMessageVisiblity with a value of two hours and the - * effective timeout would be two hours and 30 minutes. When that time comes - * near you could again extend the time out by calling - * ChangeMessageVisiblity, but this time the maximum allowed timeout would - * be 9 hours and 30 minutes. - *

- *

- * NOTE: There is a 120,000 limit for the number of inflight messages - * per queue. Messages are inflight after they have been received from the - * queue by a consuming component, but have not yet been deleted from the - * queue. If you reach the 120,000 limit, you will receive an OverLimit - * error message from Amazon SQS. To help avoid reaching the limit, you - * should delete the messages from the queue after they have been processed. - * You can also increase the number of queues you use to process the - * messages. - *

- *

- * IMPORTANT:If you attempt to set the VisibilityTimeout to an amount - * more than the maximum time left, Amazon SQS returns an error. It will not - * automatically recalculate and increase the timeout to the maximum time - * remaining. - *

- *

- * IMPORTANT:Unlike with a queue, when you change the visibility - * timeout for a specific message, that timeout value is applied immediately - * but is not saved in memory for that message. If you don't delete a - * message after it is received, the visibility timeout for the message the - * next time it is received reverts to the original timeout value, not the - * value you set with the ChangeMessageVisibility action. - *

- * - * @param queueUrl - * The URL of the Amazon SQS queue to take action on. - * @param receiptHandle - * The receipt handle associated with the message whose - * visibility timeout should be changed. This parameter is - * returned by the ReceiveMessage action. - * @param visibilityTimeout - * The new value (in seconds - from 0 to 43200 - maximum 12 - * hours) for the message's visibility timeout. - * - * @return The response from the ChangeMessageVisibility service method, as - * returned by AmazonSQS. - * - * @throws ReceiptHandleIsInvalidException - * @throws MessageNotInflightException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public ChangeMessageVisibilityResult changeMessageVisibility(String queueUrl, String receiptHandle, Integer visibilityTimeout) - throws AmazonServiceException, AmazonClientException { - - return amazonSqsToBeExtended.changeMessageVisibility(queueUrl, receiptHandle, visibilityTimeout); - } - - /** - *

- * Returns the URL of an existing queue. This action provides a simple way - * to retrieve the URL of an Amazon SQS queue. - *

- *

- * To access a queue that belongs to another AWS account, use the - * QueueOwnerAWSAccountId parameter to specify the account ID - * of the queue's owner. The queue's owner must grant you permission to - * access the queue. For more information about shared queue access, see - * AddPermission or go to Shared Queues in the Amazon SQS Developer Guide . - *

- * - * @param queueName - * The name of the queue whose URL must be fetched. Maximum 80 - * characters; alphanumeric characters, hyphens (-), and - * underscores (_) are allowed. - * - * @return The response from the GetQueueUrl service method, as returned by - * AmazonSQS. - * - * @throws QueueDoesNotExistException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public GetQueueUrlResult getQueueUrl(String queueName) throws AmazonServiceException, AmazonClientException { - - return amazonSqsToBeExtended.getQueueUrl(queueName); - } - - /** - *

- * Revokes any permissions in the queue policy that matches the specified - * Label parameter. Only the owner of the queue can remove - * permissions. - *

- * - * @param queueUrl - * The URL of the Amazon SQS queue to take action on. - * @param label - * The identification of the permission to remove. This is the - * label added with the AddPermission action. - * - * @return The response from the RemovePermission service method, as - * returned by AmazonSQS. - * - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public RemovePermissionResult removePermission(String queueUrl, String label) - throws AmazonServiceException, AmazonClientException { - - return amazonSqsToBeExtended.removePermission(queueUrl, label); - } - - /** - *

- * Gets attributes for the specified queue. The following attributes are - * supported: - *

    - *
  • All - returns all values.
  • - *
  • ApproximateNumberOfMessages - returns the approximate - * number of visible messages in a queue. For more information, see Resources Required to Process Messages in the Amazon SQS - * Developer Guide .
  • - *
  • ApproximateNumberOfMessagesNotVisible - returns the - * approximate number of messages that are not timed-out and not deleted. - * For more information, see Resources Required to Process Messages in the Amazon SQS - * Developer Guide .
  • - *
  • VisibilityTimeout - returns the visibility timeout for - * the queue. For more information about visibility timeout, see Visibility Timeout in the Amazon SQS Developer Guide .
  • - *
  • CreatedTimestamp - returns the time when the queue was - * created (epoch time in seconds).
  • - *
  • LastModifiedTimestamp - returns the time when the queue - * was last changed (epoch time in seconds).
  • - *
  • Policy - returns the queue's policy.
  • - *
  • MaximumMessageSize - returns the limit of how many bytes - * a message can contain before Amazon SQS rejects it.
  • - *
  • MessageRetentionPeriod - returns the number of seconds - * Amazon SQS retains a message.
  • - *
  • QueueArn - returns the queue's Amazon resource name - * (ARN).
  • - *
  • ApproximateNumberOfMessagesDelayed - returns the - * approximate number of messages that are pending to be added to the queue. - *
  • - *
  • DelaySeconds - returns the default delay on the queue in - * seconds.
  • - *
  • ReceiveMessageWaitTimeSeconds - returns the time for - * which a ReceiveMessage call will wait for a message to arrive.
  • - *
  • RedrivePolicy - returns the parameters for dead letter - * queue functionality of the source queue. For more information about - * RedrivePolicy and dead letter queues, see Using Amazon SQS Dead Letter Queues in the Amazon SQS Developer - * Guide .
  • - * - *
- * - *

- *

- * NOTE:Going forward, new attributes might be added. If you are - * writing code that calls this action, we recommend that you structure your - * code so that it can handle new attributes gracefully. - *

- *

- * NOTE:Some API actions take lists of parameters. These lists are - * specified using the param.n notation. Values of n are integers starting - * from 1. For example, a parameter list with two elements looks like this: - *

- *

- * &Attribute.1=this - *

- *

- * &Attribute.2=that - *

- * - * @param queueUrl - * The URL of the Amazon SQS queue to take action on. - * @param attributeNames - * A list of attributes to retrieve information for. - * - * @return The response from the GetQueueAttributes service method, as - * returned by AmazonSQS. - * - * @throws InvalidAttributeNameException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public GetQueueAttributesResult getQueueAttributes(String queueUrl, List attributeNames) - throws AmazonServiceException, AmazonClientException { - - return amazonSqsToBeExtended.getQueueAttributes(queueUrl, attributeNames); - } - - /** - *

- * Delivers up to ten messages to the specified queue. This is a batch - * version of SendMessage. The result of the send action on each message is - * reported individually in the response. The maximum allowed individual - * message size is 256 KB (262,144 bytes). - *

- *

- * The maximum total payload size (i.e., the sum of all a batch's individual - * message lengths) is also 256 KB (262,144 bytes). - *

- *

- * If the DelaySeconds parameter is not specified for an entry, - * the default for the queue is used. - *

- *

- * IMPORTANT:The following list shows the characters (in Unicode) - * that are allowed in your message, according to the W3C XML specification. - * For more information, go to http://www.faqs.org/rfcs/rfc1321.html. If you - * send any characters that are not included in the list, your request will - * be rejected. #x9 | #xA | #xD | [#x20 to #xD7FF] | [#xE000 to #xFFFD] | - * [#x10000 to #x10FFFF] - *

- *

- * IMPORTANT: Because the batch request can result in a combination - * of successful and unsuccessful actions, you should check for batch errors - * even when the call returns an HTTP status code of 200. - *

- *

- * NOTE:Some API actions take lists of parameters. These lists are - * specified using the param.n notation. Values of n are integers starting - * from 1. For example, a parameter list with two elements looks like this: - *

- *

- * &Attribute.1=this - *

- *

- * &Attribute.2=that - *

- * - * @param queueUrl - * The URL of the Amazon SQS queue to take action on. - * @param entries - * A list of SendMessageBatchRequestEntry items. - * - * @return The response from the SendMessageBatch service method, as - * returned by AmazonSQS. - * - * @throws BatchEntryIdsNotDistinctException - * @throws TooManyEntriesInBatchRequestException - * @throws BatchRequestTooLongException - * @throws UnsupportedOperationException - * @throws InvalidBatchEntryIdException - * @throws EmptyBatchRequestException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public SendMessageBatchResult sendMessageBatch(String queueUrl, List entries) - throws AmazonServiceException, AmazonClientException { - - return amazonSqsToBeExtended.sendMessageBatch(queueUrl, entries); - } - - /** - *

- * Deletes the queue specified by the queue URL , regardless of - * whether the queue is empty. If the specified queue does not exist, Amazon - * SQS returns a successful response. - *

- *

- * IMPORTANT: Use DeleteQueue with care; once you delete your queue, - * any messages in the queue are no longer available. - *

- *

- * When you delete a queue, the deletion process takes up to 60 seconds. - * Requests you send involving that queue during the 60 seconds might - * succeed. For example, a SendMessage request might succeed, but after the - * 60 seconds, the queue and that message you sent no longer exist. Also, - * when you delete a queue, you must wait at least 60 seconds before - * creating a queue with the same name. - *

- *

- * We reserve the right to delete queues that have had no activity for more - * than 30 days. For more information, see How Amazon SQS Queues Work in the Amazon SQS Developer - * Guide . - *

- * - * @param queueUrl - * The URL of the Amazon SQS queue to take action on. - * - * @return The response from the DeleteQueue service method, as returned by - * AmazonSQS. - * - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public DeleteQueueResult deleteQueue(String queueUrl) throws AmazonServiceException, AmazonClientException { - - return amazonSqsToBeExtended.deleteQueue(queueUrl); - } - - /** - *

- * Returns a list of your queues. The maximum number of queues that can be - * returned is 1000. If you specify a value for the optional - * QueueNamePrefix parameter, only queues with a name beginning - * with the specified value are returned. - *

- * - * @param queueNamePrefix - * A string to use for filtering the list results. Only those - * queues whose name begins with the specified string are - * returned. - * - * @return The response from the ListQueues service method, as returned by - * AmazonSQS. - * - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public ListQueuesResult listQueues(String queueNamePrefix) throws AmazonServiceException, AmazonClientException { - - return amazonSqsToBeExtended.listQueues(queueNamePrefix); - } - - /** - *

- * Deletes up to ten messages from the specified queue. This is a batch - * version of DeleteMessage. The result of the delete action on each message - * is reported individually in the response. - *

- *

- * IMPORTANT: Because the batch request can result in a combination - * of successful and unsuccessful actions, you should check for batch errors - * even when the call returns an HTTP status code of 200. - *

- *

- * NOTE:Some API actions take lists of parameters. These lists are - * specified using the param.n notation. Values of n are integers starting - * from 1. For example, a parameter list with two elements looks like this: - *

- *

- * &Attribute.1=this - *

- *

- * &Attribute.2=that - *

- * - * @param queueUrl - * The URL of the Amazon SQS queue to take action on. - * @param entries - * A list of receipt handles for the messages to be deleted. - * - * @return The response from the DeleteMessageBatch service method, as - * returned by AmazonSQS. - * - * @throws BatchEntryIdsNotDistinctException - * @throws TooManyEntriesInBatchRequestException - * @throws InvalidBatchEntryIdException - * @throws EmptyBatchRequestException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public DeleteMessageBatchResult deleteMessageBatch(String queueUrl, List entries) - throws AmazonServiceException, AmazonClientException { - - return amazonSqsToBeExtended.deleteMessageBatch(queueUrl, entries); - } - - /** - *

- * Creates a new queue, or returns the URL of an existing one. When you - * request CreateQueue , you provide a name for the queue. To - * successfully create a new queue, you must provide a name that is unique - * within the scope of your own queues. - *

- *

- * NOTE: If you delete a queue, you must wait at least 60 seconds - * before creating a queue with the same name. - *

- *

- * You may pass one or more attributes in the request. If you do not provide - * a value for any attribute, the queue will have the default value for that - * attribute. Permitted attributes are the same that can be set using - * SetQueueAttributes. - *

- *

- * NOTE: Use GetQueueUrl to get a queue's URL. GetQueueUrl requires - * only the QueueName parameter. - *

- *

- * If you provide the name of an existing queue, along with the exact names - * and values of all the queue's attributes, CreateQueue - * returns the queue URL for the existing queue. If the queue name, - * attribute names, or attribute values do not match an existing queue, - * CreateQueue returns an error. - *

- *

- * NOTE:Some API actions take lists of parameters. These lists are - * specified using the param.n notation. Values of n are integers starting - * from 1. For example, a parameter list with two elements looks like this: - *

- *

- * &Attribute.1=this - *

- *

- * &Attribute.2=that - *

- * - * @param queueName - * The name for the queue to be created. - * - * @return The response from the CreateQueue service method, as returned by - * AmazonSQS. - * - * @throws QueueNameExistsException - * @throws QueueDeletedRecentlyException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public CreateQueueResult createQueue(String queueName) throws AmazonServiceException, AmazonClientException { - - return amazonSqsToBeExtended.createQueue(queueName); - } - - /** - *

- * Adds a permission to a queue for a specific - * principal . This allows for sharing access to the queue. - *

- *

- * When you create a queue, you have full control access rights for the - * queue. Only you (as owner of the queue) can grant or deny permissions to - * the queue. For more information about these permissions, see Shared Queues in the Amazon SQS Developer Guide . - *

- *

- * NOTE: AddPermission writes an Amazon SQS-generated policy. If you - * want to write your own policy, use SetQueueAttributes to upload your - * policy. For more information about writing your own policy, see Using The - * Access Policy Language in the Amazon SQS Developer Guide. - *

- *

- * NOTE:Some API actions take lists of parameters. These lists are - * specified using the param.n notation. Values of n are integers starting - * from 1. For example, a parameter list with two elements looks like this: - *

- *

- * &Attribute.1=this - *

- *

- * &Attribute.2=that - *

- * - * @param queueUrl - * The URL of the Amazon SQS queue to take action on. - * @param label - * The unique identification of the permission you're setting - * (e.g., AliceSendMessage). Constraints: Maximum 80 - * characters; alphanumeric characters, hyphens (-), and - * underscores (_) are allowed. - * @param aWSAccountIds - * The AWS account number of the principal who will be given permission. The principal - * must have an AWS account, but does not need to be signed up - * for Amazon SQS. For information about locating the AWS account - * identification, see Your AWS Identifiers in the Amazon SQS Developer - * Guide. - * @param actions - * The action the client wants to allow for the specified - * principal. The following are valid values: - * * | SendMessage | - * ReceiveMessage | DeleteMessage | ChangeMessageVisibility | - * GetQueueAttributes | GetQueueUrl. For more information about these - * actions, see Understanding Permissions in the Amazon SQS Developer - * Guide. - *

- * Specifying SendMessage, - * DeleteMessage, or - * ChangeMessageVisibility for the - * ActionName.n also grants permissions for the - * corresponding batch versions of those actions: - * SendMessageBatch, DeleteMessageBatch - * , and ChangeMessageVisibilityBatch. - * - * @return The response from the AddPermission service method, as returned - * by AmazonSQS. - * - * @throws OverLimitException - * - * @throws AmazonClientException - * If any internal errors are encountered inside the client - * while attempting to make the request or handle the response. - * For example if a network connection is not available. - * @throws AmazonServiceException - * If an error response is returned by AmazonSQS indicating - * either a problem with the data in the request, or a server - * side issue. - */ - public AddPermissionResult addPermission(String queueUrl, String label, List aWSAccountIds, List actions) - throws AmazonServiceException, AmazonClientException { - - return amazonSqsToBeExtended.addPermission(queueUrl, label, aWSAccountIds, actions); - } - - /** - * Returns additional metadata for a previously executed successful, - * request, typically used for debugging issues where a service isn't acting - * as expected. This data isn't considered part of the result data returned - * by an operation, so it's available through this separate, diagnostic - * interface. - *

- * Response metadata is only cached for a limited period of time, so if you - * need to access this extra diagnostic information for an executed request, - * you should use this method to retrieve it as soon as possible after - * executing the request. - * - * @param request - * The originally executed request - * - * @return The response metadata for the specified request, or null if none - * is available. - */ - public ResponseMetadata getCachedResponseMetadata(AmazonWebServiceRequest request) { - - return amazonSqsToBeExtended.getCachedResponseMetadata(request); - } - - /** - * Overrides the default endpoint for this client ("sqs.us-east-1.amazonaws.com"). - * Callers can use this method to control which AWS region they want to work with. - *

- * Callers can pass in just the endpoint (ex: "sqs.us-east-1.amazonaws.com") or a full - * URL, including the protocol (ex: "sqs.us-east-1.amazonaws.com"). If the - * protocol is not specified here, the default protocol from this client's - * {@link ClientConfiguration} will be used, which by default is HTTPS. - *

- * For more information on using AWS regions with the AWS SDK for Java, and - * a complete list of all available endpoints for all AWS services, see: - * - * http://developer.amazonwebservices.com/connect/entry.jspa?externalID=3912 - *

- * This method is not threadsafe. An endpoint should be configured when the - * client is created and before any service requests are made. Changing it - * afterwards creates inevitable race conditions for any service requests in - * transit or retrying. - * - * @param endpoint - * The endpoint (ex: "sqs.us-east-1.amazonaws.com") or a full URL, - * including the protocol (ex: "sqs.us-east-1.amazonaws.com") of - * the region specific AWS endpoint this client will communicate - * with. - * - * @throws IllegalArgumentException - * If any problems are detected with the specified endpoint. - */ - public void setEndpoint(String endpoint) throws IllegalArgumentException { - - amazonSqsToBeExtended.setEndpoint(endpoint); - - } - - /** - * An alternative to {@link AmazonSQS#setEndpoint(String)}, sets the - * regional endpoint for this client's service calls. Callers can use this - * method to control which AWS region they want to work with. - *

- * By default, all service endpoints in all regions use the https protocol. - * To use http instead, specify it in the {@link ClientConfiguration} - * supplied at construction. - *

- * This method is not threadsafe. A region should be configured when the - * client is created and before any service requests are made. Changing it - * afterwards creates inevitable race conditions for any service requests in - * transit or retrying. - * - * @param region - * The region this client will communicate with. See - * {@link Region#getRegion(com.amazonaws.regions.Regions)} for - * accessing a given region. - * @throws java.lang.IllegalArgumentException - * If the given region is null, or if this service isn't - * available in the given region. See - * {@link Region#isServiceSupported(String)} - * @see Region#getRegion(com.amazonaws.regions.Regions) - * @see Region#createClient(Class, AWSCredentialsProvider, ClientConfiguration) - */ - public void setRegion(Region region) throws IllegalArgumentException { - - amazonSqsToBeExtended.setRegion(region); - - } - - /** - * Shuts down this client object, releasing any resources that might be held - * open. This is an optional method, and callers are not expected to call - * it, but can if they want to explicitly release any open resources. Once a - * client has been shutdown, it should not be used to make any more - * requests. - */ - public void shutdown() { - - amazonSqsToBeExtended.shutdown(); - } - - /** {@inheritDoc} */ - @Override public ListQueueTagsResult listQueueTags(final ListQueueTagsRequest listQueueTagsRequest) { - return amazonSqsToBeExtended.listQueueTags(listQueueTagsRequest); - } - - /** {@inheritDoc} */ - @Override public ListQueueTagsResult listQueueTags(final String queueUrl) { - return amazonSqsToBeExtended.listQueueTags(queueUrl); - } - - /** {@inheritDoc} */ - @Override public TagQueueResult tagQueue(final TagQueueRequest tagQueueRequest) { - return amazonSqsToBeExtended.tagQueue(tagQueueRequest); - } - - /** {@inheritDoc} */ - @Override public TagQueueResult tagQueue(final String queueUrl, final Map tags) { - return amazonSqsToBeExtended.tagQueue(queueUrl, tags); - } - - /** {@inheritDoc} */ - @Override public UntagQueueResult untagQueue(final UntagQueueRequest untagQueueRequest) { - return amazonSqsToBeExtended.untagQueue(untagQueueRequest); - } - - /** {@inheritDoc} */ - @Override public UntagQueueResult untagQueue(final String queueUrl, final List tagKeys) { - return amazonSqsToBeExtended.untagQueue(queueUrl, tagKeys); - } + public DeleteMessageResult deleteMessage(DeleteMessageRequest deleteMessageRequest) { + return amazonSqsToBeExtended.deleteMessage(deleteMessageRequest); + } + + /** + *

+ * Delivers a message to the specified queue. With Amazon SQS, you now have + * the ability to send large payload messages that are up to 256KB (262,144 + * bytes) in size. To send large payloads, you must use an AWS SDK that + * supports SigV4 signing. To verify whether SigV4 is supported for an AWS + * SDK, check the SDK release notes. + *

+ *

+ * IMPORTANT: The following list shows the characters (in Unicode) + * allowed in your message, according to the W3C XML specification. For more + * information, go to http://www.w3.org/TR/REC-xml/#charsets If you send any + * characters not included in the list, your request will be rejected. #x9 | + * #xA | #xD | [#x20 to #xD7FF] | [#xE000 to #xFFFD] | [#x10000 to #x10FFFF] + *

+ * + * @param queueUrl + * The URL of the Amazon SQS queue to take action on. + * @param messageBody + * The message to send. String maximum 256 KB in size. For a list + * of allowed characters, see the preceding important note. + * + * @return The response from the SendMessage service method, as returned by + * AmazonSQS. + * + * @throws InvalidMessageContentsException + * @throws UnsupportedOperationException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public SendMessageResult sendMessage(String queueUrl, String messageBody) throws AmazonServiceException, + AmazonClientException { + + return amazonSqsToBeExtended.sendMessage(queueUrl, messageBody); + } + + /** + *

+ * Retrieves one or more messages, with a maximum limit of 10 messages, from + * the specified queue. Long poll support is enabled by using the + * WaitTimeSeconds parameter. For more information, see Amazon SQS Long Poll in the Amazon SQS Developer Guide . + *

+ *

+ * Short poll is the default behavior where a weighted random set of + * machines is sampled on a ReceiveMessage call. This means + * only the messages on the sampled machines are returned. If the number of + * messages in the queue is small (less than 1000), it is likely you will + * get fewer messages than you requested per ReceiveMessage + * call. If the number of messages in the queue is extremely small, you + * might not receive any messages in a particular + * ReceiveMessage response; in which case you should repeat the + * request. + *

+ *

+ * For each message returned, the response includes the following: + *

+ * + *
    + *
  • + *

    + * Message body + *

    + *
  • + *
  • + *

    + * MD5 digest of the message body. For information about MD5, go to + * http://www.faqs.org/rfcs/rfc1321.html . + *

    + *
  • + *
  • + *

    + * Message ID you received when you sent the message to the queue. + *

    + *
  • + *
  • + *

    + * Receipt handle. + *

    + *
  • + *
  • + *

    + * Message attributes. + *

    + *
  • + *
  • + *

    + * MD5 digest of the message attributes. + *

    + *
  • + * + *
+ *

+ * The receipt handle is the identifier you must provide when deleting the + * message. For more information, see Queue and Message Identifiers in the Amazon SQS Developer + * Guide . + *

+ *

+ * You can provide the VisibilityTimeout parameter in your + * request, which will be applied to the messages that Amazon SQS returns in + * the response. If you do not include the parameter, the overall visibility + * timeout for the queue is used for the returned messages. For more + * information, see Visibility Timeout in the Amazon SQS Developer Guide . + *

+ *

+ * NOTE: Going forward, new attributes might be added. If you are + * writing code that calls this action, we recommend that you structure your + * code so that it can handle new attributes gracefully. + *

+ * + * @param queueUrl + * The URL of the Amazon SQS queue to take action on. + * + * @return The response from the ReceiveMessage service method, as returned + * by AmazonSQS. + * + * @throws OverLimitException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public ReceiveMessageResult receiveMessage(String queueUrl) throws AmazonServiceException, AmazonClientException { + + return amazonSqsToBeExtended.receiveMessage(queueUrl); + } + + /** + *

+ * Deletes the specified message from the specified queue. You specify the + * message by using the message's receipt handle and not the + * message ID you received when you sent the message. Even if + * the message is locked by another reader due to the visibility timeout + * setting, it is still deleted from the queue. If you leave a message in + * the queue for longer than the queue's configured retention period, Amazon + * SQS automatically deletes it. + *

+ *

+ * NOTE: The receipt handle is associated with a specific instance of + * receiving the message. If you receive a message more than once, the + * receipt handle you get each time you receive the message is different. + * When you request DeleteMessage, if you don't provide the most recently + * received receipt handle for the message, the request will still succeed, + * but the message might not be deleted. + *

+ *

+ * IMPORTANT: It is possible you will receive a message even after + * you have deleted it. This might happen on rare occasions if one of the + * servers storing a copy of the message is unavailable when you request to + * delete the message. The copy remains on the server and might be returned + * to you again on a subsequent receive request. You should create your + * system to be idempotent so that receiving a particular message more than + * once is not a problem. + *

+ * + * @param queueUrl + * The URL of the Amazon SQS queue to take action on. + * @param receiptHandle + * The receipt handle associated with the message to delete. + * + * @return The response from the DeleteMessage service method, as returned + * by AmazonSQS. + * + * @throws ReceiptHandleIsInvalidException + * @throws InvalidIdFormatException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public DeleteMessageResult deleteMessage(String queueUrl, String receiptHandle) + throws AmazonServiceException, AmazonClientException { + + return amazonSqsToBeExtended.deleteMessage(queueUrl, receiptHandle); + } + + /** + *

+ * Sets the value of one or more queue attributes. When you change a queue's + * attributes, the change can take up to 60 seconds for most of the + * attributes to propagate throughout the SQS system. Changes made to the + * MessageRetentionPeriod attribute can take up to 15 minutes. + *

+ *

+ * NOTE:Going forward, new attributes might be added. If you are + * writing code that calls this action, we recommend that you structure your + * code so that it can handle new attributes gracefully. + *

+ * + * @param setQueueAttributesRequest + * Container for the necessary parameters to execute the + * SetQueueAttributes service method on AmazonSQS. + * + * + * @throws InvalidAttributeNameException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public SetQueueAttributesResult setQueueAttributes(SetQueueAttributesRequest setQueueAttributesRequest) + throws AmazonServiceException, AmazonClientException { + + return amazonSqsToBeExtended.setQueueAttributes(setQueueAttributesRequest); + + } + + /** + *

+ * Changes the visibility timeout of multiple messages. This is a batch + * version of ChangeMessageVisibility. The result of the action on each + * message is reported individually in the response. You can send up to 10 + * ChangeMessageVisibility requests with each + * ChangeMessageVisibilityBatch action. + *

+ *

+ * IMPORTANT:Because the batch request can result in a combination of + * successful and unsuccessful actions, you should check for batch errors + * even when the call returns an HTTP status code of 200. + *

+ *

+ * NOTE:Some API actions take lists of parameters. These lists are + * specified using the param.n notation. Values of n are integers starting + * from 1. For example, a parameter list with two elements looks like this: + *

+ *

+ * &Attribute.1=this + *

+ *

+ * &Attribute.2=that + *

+ * + * @param changeMessageVisibilityBatchRequest + * Container for the necessary parameters to execute the + * ChangeMessageVisibilityBatch service method on AmazonSQS. + * + * @return The response from the ChangeMessageVisibilityBatch service + * method, as returned by AmazonSQS. + * + * @throws BatchEntryIdsNotDistinctException + * @throws TooManyEntriesInBatchRequestException + * @throws InvalidBatchEntryIdException + * @throws EmptyBatchRequestException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public ChangeMessageVisibilityBatchResult changeMessageVisibilityBatch( + ChangeMessageVisibilityBatchRequest changeMessageVisibilityBatchRequest) throws AmazonServiceException, + AmazonClientException { + + return amazonSqsToBeExtended.changeMessageVisibilityBatch(changeMessageVisibilityBatchRequest); + } + + /** + *

+ * Changes the visibility timeout of a specified message in a queue to a new + * value. The maximum allowed timeout value you can set the value to is 12 + * hours. This means you can't extend the timeout of a message in an + * existing queue to more than a total visibility timeout of 12 hours. (For + * more information visibility timeout, see Visibility Timeout in the Amazon SQS Developer Guide .) + *

+ *

+ * For example, let's say you have a message and its default message + * visibility timeout is 30 minutes. You could call + * ChangeMessageVisiblity with a value of two hours and the + * effective timeout would be two hours and 30 minutes. When that time comes + * near you could again extend the time out by calling + * ChangeMessageVisiblity, but this time the maximum allowed timeout would + * be 9 hours and 30 minutes. + *

+ *

+ * NOTE: There is a 120,000 limit for the number of inflight messages + * per queue. Messages are inflight after they have been received from the + * queue by a consuming component, but have not yet been deleted from the + * queue. If you reach the 120,000 limit, you will receive an OverLimit + * error message from Amazon SQS. To help avoid reaching the limit, you + * should delete the messages from the queue after they have been processed. + * You can also increase the number of queues you use to process the + * messages. + *

+ *

+ * IMPORTANT:If you attempt to set the VisibilityTimeout to an amount + * more than the maximum time left, Amazon SQS returns an error. It will not + * automatically recalculate and increase the timeout to the maximum time + * remaining. + *

+ *

+ * IMPORTANT:Unlike with a queue, when you change the visibility + * timeout for a specific message, that timeout value is applied immediately + * but is not saved in memory for that message. If you don't delete a + * message after it is received, the visibility timeout for the message the + * next time it is received reverts to the original timeout value, not the + * value you set with the ChangeMessageVisibility action. + *

+ * + * @param changeMessageVisibilityRequest + * Container for the necessary parameters to execute the + * ChangeMessageVisibility service method on AmazonSQS. + * + * + * @throws ReceiptHandleIsInvalidException + * @throws MessageNotInflightException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public ChangeMessageVisibilityResult changeMessageVisibility(ChangeMessageVisibilityRequest changeMessageVisibilityRequest) + throws AmazonServiceException, AmazonClientException { + + return amazonSqsToBeExtended.changeMessageVisibility(changeMessageVisibilityRequest); + } + + /** + *

+ * Returns the URL of an existing queue. This action provides a simple way + * to retrieve the URL of an Amazon SQS queue. + *

+ *

+ * To access a queue that belongs to another AWS account, use the + * QueueOwnerAWSAccountId parameter to specify the account ID + * of the queue's owner. The queue's owner must grant you permission to + * access the queue. For more information about shared queue access, see + * AddPermission or go to Shared Queues in the Amazon SQS Developer Guide . + *

+ * + * @param getQueueUrlRequest + * Container for the necessary parameters to execute the + * GetQueueUrl service method on AmazonSQS. + * + * @return The response from the GetQueueUrl service method, as returned by + * AmazonSQS. + * + * @throws QueueDoesNotExistException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public GetQueueUrlResult getQueueUrl(GetQueueUrlRequest getQueueUrlRequest) throws AmazonServiceException, + AmazonClientException { + + return amazonSqsToBeExtended.getQueueUrl(getQueueUrlRequest); + } + + /** + *

+ * Revokes any permissions in the queue policy that matches the specified + * Label parameter. Only the owner of the queue can remove + * permissions. + *

+ * + * @param removePermissionRequest + * Container for the necessary parameters to execute the + * RemovePermission service method on AmazonSQS. + * + * + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public RemovePermissionResult removePermission(RemovePermissionRequest removePermissionRequest) + throws AmazonServiceException, AmazonClientException { + + return amazonSqsToBeExtended.removePermission(removePermissionRequest); + } + + /** + *

+ * Gets attributes for the specified queue. The following attributes are + * supported: + *

    + *
  • All - returns all values.
  • + *
  • ApproximateNumberOfMessages - returns the approximate + * number of visible messages in a queue. For more information, see Resources Required to Process Messages in the Amazon SQS + * Developer Guide .
  • + *
  • ApproximateNumberOfMessagesNotVisible - returns the + * approximate number of messages that are not timed-out and not deleted. + * For more information, see Resources Required to Process Messages in the Amazon SQS + * Developer Guide .
  • + *
  • VisibilityTimeout - returns the visibility timeout for + * the queue. For more information about visibility timeout, see Visibility Timeout in the Amazon SQS Developer Guide .
  • + *
  • CreatedTimestamp - returns the time when the queue was + * created (epoch time in seconds).
  • + *
  • LastModifiedTimestamp - returns the time when the queue + * was last changed (epoch time in seconds).
  • + *
  • Policy - returns the queue's policy.
  • + *
  • MaximumMessageSize - returns the limit of how many bytes + * a message can contain before Amazon SQS rejects it.
  • + *
  • MessageRetentionPeriod - returns the number of seconds + * Amazon SQS retains a message.
  • + *
  • QueueArn - returns the queue's Amazon resource name + * (ARN).
  • + *
  • ApproximateNumberOfMessagesDelayed - returns the + * approximate number of messages that are pending to be added to the queue. + *
  • + *
  • DelaySeconds - returns the default delay on the queue in + * seconds.
  • + *
  • ReceiveMessageWaitTimeSeconds - returns the time for + * which a ReceiveMessage call will wait for a message to arrive.
  • + *
  • RedrivePolicy - returns the parameters for dead letter + * queue functionality of the source queue. For more information about + * RedrivePolicy and dead letter queues, see Using Amazon SQS Dead Letter Queues in the Amazon SQS Developer + * Guide .
  • + * + *
+ * + *

+ *

+ * NOTE:Going forward, new attributes might be added. If you are + * writing code that calls this action, we recommend that you structure your + * code so that it can handle new attributes gracefully. + *

+ *

+ * NOTE:Some API actions take lists of parameters. These lists are + * specified using the param.n notation. Values of n are integers starting + * from 1. For example, a parameter list with two elements looks like this: + *

+ *

+ * &Attribute.1=this + *

+ *

+ * &Attribute.2=that + *

+ * + * @param getQueueAttributesRequest + * Container for the necessary parameters to execute the + * GetQueueAttributes service method on AmazonSQS. + * + * @return The response from the GetQueueAttributes service method, as + * returned by AmazonSQS. + * + * @throws InvalidAttributeNameException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public GetQueueAttributesResult getQueueAttributes(GetQueueAttributesRequest getQueueAttributesRequest) + throws AmazonServiceException, AmazonClientException { + + return amazonSqsToBeExtended.getQueueAttributes(getQueueAttributesRequest); + } + + /** + *

+ * Delivers up to ten messages to the specified queue. This is a batch + * version of SendMessage. The result of the send action on each message is + * reported individually in the response. The maximum allowed individual + * message size is 256 KB (262,144 bytes). + *

+ *

+ * The maximum total payload size (i.e., the sum of all a batch's individual + * message lengths) is also 256 KB (262,144 bytes). + *

+ *

+ * If the DelaySeconds parameter is not specified for an entry, + * the default for the queue is used. + *

+ *

+ * IMPORTANT:The following list shows the characters (in Unicode) + * that are allowed in your message, according to the W3C XML specification. + * For more information, go to http://www.faqs.org/rfcs/rfc1321.html. If you + * send any characters that are not included in the list, your request will + * be rejected. #x9 | #xA | #xD | [#x20 to #xD7FF] | [#xE000 to #xFFFD] | + * [#x10000 to #x10FFFF] + *

+ *

+ * IMPORTANT: Because the batch request can result in a combination + * of successful and unsuccessful actions, you should check for batch errors + * even when the call returns an HTTP status code of 200. + *

+ *

+ * NOTE:Some API actions take lists of parameters. These lists are + * specified using the param.n notation. Values of n are integers starting + * from 1. For example, a parameter list with two elements looks like this: + *

+ *

+ * &Attribute.1=this + *

+ *

+ * &Attribute.2=that + *

+ * + * @param sendMessageBatchRequest + * Container for the necessary parameters to execute the + * SendMessageBatch service method on AmazonSQS. + * + * @return The response from the SendMessageBatch service method, as + * returned by AmazonSQS. + * + * @throws BatchEntryIdsNotDistinctException + * @throws TooManyEntriesInBatchRequestException + * @throws BatchRequestTooLongException + * @throws UnsupportedOperationException + * @throws InvalidBatchEntryIdException + * @throws EmptyBatchRequestException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public SendMessageBatchResult sendMessageBatch(SendMessageBatchRequest sendMessageBatchRequest) + throws AmazonServiceException, AmazonClientException { + + return amazonSqsToBeExtended.sendMessageBatch(sendMessageBatchRequest); + } + + /** + *

+ * Deletes the messages in a queue specified by the queue URL . + *

+ *

+ * IMPORTANT:When you use the PurgeQueue API, the deleted messages in + * the queue cannot be retrieved. + *

+ *

+ * When you purge a queue, the message deletion process takes up to 60 + * seconds. All messages sent to the queue before calling + * PurgeQueue will be deleted; messages sent to the queue while + * it is being purged may be deleted. While the queue is being purged, + * messages sent to the queue before PurgeQueue was called may + * be received, but will be deleted within the next minute. + *

+ * + * @param purgeQueueRequest + * Container for the necessary parameters to execute the + * PurgeQueue service method on AmazonSQS. + * + * + * @throws PurgeQueueInProgressException + * @throws QueueDoesNotExistException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public PurgeQueueResult purgeQueue(PurgeQueueRequest purgeQueueRequest) + throws AmazonServiceException, AmazonClientException { + + return amazonSqsToBeExtended.purgeQueue(purgeQueueRequest); + + } + + /** + *

+ * Returns a list of your queues that have the RedrivePolicy queue attribute + * configured with a dead letter queue. + *

+ *

+ * For more information about using dead letter queues, see Using Amazon SQS Dead Letter Queues . + *

+ * + * @param listDeadLetterSourceQueuesRequest + * Container for the necessary parameters to execute the + * ListDeadLetterSourceQueues service method on AmazonSQS. + * + * @return The response from the ListDeadLetterSourceQueues service method, + * as returned by AmazonSQS. + * + * @throws QueueDoesNotExistException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public ListDeadLetterSourceQueuesResult listDeadLetterSourceQueues( + ListDeadLetterSourceQueuesRequest listDeadLetterSourceQueuesRequest) throws AmazonServiceException, + AmazonClientException { + + return amazonSqsToBeExtended.listDeadLetterSourceQueues(listDeadLetterSourceQueuesRequest); + } + + /** + *

+ * Deletes the queue specified by the queue URL , regardless of + * whether the queue is empty. If the specified queue does not exist, Amazon + * SQS returns a successful response. + *

+ *

+ * IMPORTANT: Use DeleteQueue with care; once you delete your queue, + * any messages in the queue are no longer available. + *

+ *

+ * When you delete a queue, the deletion process takes up to 60 seconds. + * Requests you send involving that queue during the 60 seconds might + * succeed. For example, a SendMessage request might succeed, but after the + * 60 seconds, the queue and that message you sent no longer exist. Also, + * when you delete a queue, you must wait at least 60 seconds before + * creating a queue with the same name. + *

+ *

+ * We reserve the right to delete queues that have had no activity for more + * than 30 days. For more information, see How Amazon SQS Queues Work in the Amazon SQS Developer + * Guide . + *

+ * + * @param deleteQueueRequest + * Container for the necessary parameters to execute the + * DeleteQueue service method on AmazonSQS. + * + * + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public DeleteQueueResult deleteQueue(DeleteQueueRequest deleteQueueRequest) + throws AmazonServiceException, AmazonClientException { + + return amazonSqsToBeExtended.deleteQueue(deleteQueueRequest); + } + + /** + *

+ * Returns a list of your queues. The maximum number of queues that can be + * returned is 1000. If you specify a value for the optional + * QueueNamePrefix parameter, only queues with a name beginning + * with the specified value are returned. + *

+ * + * @param listQueuesRequest + * Container for the necessary parameters to execute the + * ListQueues service method on AmazonSQS. + * + * @return The response from the ListQueues service method, as returned by + * AmazonSQS. + * + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public ListQueuesResult listQueues(ListQueuesRequest listQueuesRequest) throws AmazonServiceException, + AmazonClientException { + + return amazonSqsToBeExtended.listQueues(listQueuesRequest); + } + + /** + *

+ * Deletes up to ten messages from the specified queue. This is a batch + * version of DeleteMessage. The result of the delete action on each message + * is reported individually in the response. + *

+ *

+ * IMPORTANT: Because the batch request can result in a combination + * of successful and unsuccessful actions, you should check for batch errors + * even when the call returns an HTTP status code of 200. + *

+ *

+ * NOTE:Some API actions take lists of parameters. These lists are + * specified using the param.n notation. Values of n are integers starting + * from 1. For example, a parameter list with two elements looks like this: + *

+ *

+ * &Attribute.1=this + *

+ *

+ * &Attribute.2=that + *

+ * + * @param deleteMessageBatchRequest + * Container for the necessary parameters to execute the + * DeleteMessageBatch service method on AmazonSQS. + * + * @return The response from the DeleteMessageBatch service method, as + * returned by AmazonSQS. + * + * @throws BatchEntryIdsNotDistinctException + * @throws TooManyEntriesInBatchRequestException + * @throws InvalidBatchEntryIdException + * @throws EmptyBatchRequestException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public DeleteMessageBatchResult deleteMessageBatch(DeleteMessageBatchRequest deleteMessageBatchRequest) + throws AmazonServiceException, AmazonClientException { + + return amazonSqsToBeExtended.deleteMessageBatch(deleteMessageBatchRequest); + } + + /** + *

+ * Creates a new queue, or returns the URL of an existing one. When you + * request CreateQueue , you provide a name for the queue. To + * successfully create a new queue, you must provide a name that is unique + * within the scope of your own queues. + *

+ *

+ * NOTE: If you delete a queue, you must wait at least 60 seconds + * before creating a queue with the same name. + *

+ *

+ * You may pass one or more attributes in the request. If you do not provide + * a value for any attribute, the queue will have the default value for that + * attribute. Permitted attributes are the same that can be set using + * SetQueueAttributes. + *

+ *

+ * NOTE: Use GetQueueUrl to get a queue's URL. GetQueueUrl requires + * only the QueueName parameter. + *

+ *

+ * If you provide the name of an existing queue, along with the exact names + * and values of all the queue's attributes, CreateQueue + * returns the queue URL for the existing queue. If the queue name, + * attribute names, or attribute values do not match an existing queue, + * CreateQueue returns an error. + *

+ *

+ * NOTE:Some API actions take lists of parameters. These lists are + * specified using the param.n notation. Values of n are integers starting + * from 1. For example, a parameter list with two elements looks like this: + *

+ *

+ * &Attribute.1=this + *

+ *

+ * &Attribute.2=that + *

+ * + * @param createQueueRequest + * Container for the necessary parameters to execute the + * CreateQueue service method on AmazonSQS. + * + * @return The response from the CreateQueue service method, as returned by + * AmazonSQS. + * + * @throws QueueNameExistsException + * @throws QueueDeletedRecentlyException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public CreateQueueResult createQueue(CreateQueueRequest createQueueRequest) throws AmazonServiceException, + AmazonClientException { + + return amazonSqsToBeExtended.createQueue(createQueueRequest); + } + + /** + *

+ * Adds a permission to a queue for a specific + * principal . This allows for sharing access to the queue. + *

+ *

+ * When you create a queue, you have full control access rights for the + * queue. Only you (as owner of the queue) can grant or deny permissions to + * the queue. For more information about these permissions, see Shared Queues in the Amazon SQS Developer Guide . + *

+ *

+ * NOTE: AddPermission writes an Amazon SQS-generated policy. If you + * want to write your own policy, use SetQueueAttributes to upload your + * policy. For more information about writing your own policy, see Using The + * Access Policy Language in the Amazon SQS Developer Guide. + *

+ *

+ * NOTE:Some API actions take lists of parameters. These lists are + * specified using the param.n notation. Values of n are integers starting + * from 1. For example, a parameter list with two elements looks like this: + *

+ *

+ * &Attribute.1=this + *

+ *

+ * &Attribute.2=that + *

+ * + * @param addPermissionRequest + * Container for the necessary parameters to execute the + * AddPermission service method on AmazonSQS. + * + * + * @throws OverLimitException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public AddPermissionResult addPermission(AddPermissionRequest addPermissionRequest) + throws AmazonServiceException, AmazonClientException { + + return amazonSqsToBeExtended.addPermission(addPermissionRequest); + } + + /** + *

+ * Returns a list of your queues. The maximum number of queues that can be + * returned is 1000. If you specify a value for the optional + * QueueNamePrefix parameter, only queues with a name beginning + * with the specified value are returned. + *

+ * + * @return The response from the ListQueues service method, as returned by + * AmazonSQS. + * + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public ListQueuesResult listQueues() throws AmazonServiceException, AmazonClientException { + + return amazonSqsToBeExtended.listQueues(); + } + + /** + *

+ * Sets the value of one or more queue attributes. When you change a queue's + * attributes, the change can take up to 60 seconds for most of the + * attributes to propagate throughout the SQS system. Changes made to the + * MessageRetentionPeriod attribute can take up to 15 minutes. + *

+ *

+ * NOTE:Going forward, new attributes might be added. If you are + * writing code that calls this action, we recommend that you structure your + * code so that it can handle new attributes gracefully. + *

+ * + * @param queueUrl + * The URL of the Amazon SQS queue to take action on. + * @param attributes + * A map of attributes to set. + *

+ * The following lists the names, descriptions, and values of the + * special request parameters the SetQueueAttributes + * action uses: + *

+ *

    + *
  • DelaySeconds - The time in seconds that the + * delivery of all messages in the queue will be delayed. An + * integer from 0 to 900 (15 minutes). The default for this + * attribute is 0 (zero).
  • + *
  • MaximumMessageSize - The limit of how many + * bytes a message can contain before Amazon SQS rejects it. An + * integer from 1024 bytes (1 KiB) up to 262144 bytes (256 KiB). + * The default for this attribute is 262144 (256 KiB).
  • + *
  • MessageRetentionPeriod - The number of + * seconds Amazon SQS retains a message. Integer representing + * seconds, from 60 (1 minute) to 1209600 (14 days). The default + * for this attribute is 345600 (4 days).
  • + *
  • Policy - The queue's policy. A valid AWS + * policy. For more information about policy structure, see Overview of AWS IAM Policies in the Amazon IAM User + * Guide.
  • + *
  • ReceiveMessageWaitTimeSeconds - The time for + * which a ReceiveMessage call will wait for a message to arrive. + * An integer from 0 to 20 (seconds). The default for this + * attribute is 0.
  • + *
  • VisibilityTimeout - The visibility timeout + * for the queue. An integer from 0 to 43200 (12 hours). The + * default for this attribute is 30. For more information about + * visibility timeout, see Visibility Timeout in the Amazon + * SQS Developer Guide.
  • + *
  • RedrivePolicy - The parameters for dead + * letter queue functionality of the source queue. For more + * information about RedrivePolicy and dead letter queues, see + * Using Amazon SQS Dead Letter Queues in the Amazon SQS + * Developer Guide.
  • + *
+ * + * @return The response from the SetQueueAttributes service method, as + * returned by AmazonSQS. + * + * @throws InvalidAttributeNameException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public SetQueueAttributesResult setQueueAttributes(String queueUrl, Map attributes) + throws AmazonServiceException, AmazonClientException { + + return amazonSqsToBeExtended.setQueueAttributes(queueUrl, attributes); + } + + /** + *

+ * Changes the visibility timeout of multiple messages. This is a batch + * version of ChangeMessageVisibility. The result of the action on each + * message is reported individually in the response. You can send up to 10 + * ChangeMessageVisibility requests with each + * ChangeMessageVisibilityBatch action. + *

+ *

+ * IMPORTANT:Because the batch request can result in a combination of + * successful and unsuccessful actions, you should check for batch errors + * even when the call returns an HTTP status code of 200. + *

+ *

+ * NOTE:Some API actions take lists of parameters. These lists are + * specified using the param.n notation. Values of n are integers starting + * from 1. For example, a parameter list with two elements looks like this: + *

+ *

+ * &Attribute.1=this + *

+ *

+ * &Attribute.2=that + *

+ * + * @param queueUrl + * The URL of the Amazon SQS queue to take action on. + * @param entries + * A list of receipt handles of the messages for which the + * visibility timeout must be changed. + * + * @return The response from the ChangeMessageVisibilityBatch service + * method, as returned by AmazonSQS. + * + * @throws BatchEntryIdsNotDistinctException + * @throws TooManyEntriesInBatchRequestException + * @throws InvalidBatchEntryIdException + * @throws EmptyBatchRequestException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public ChangeMessageVisibilityBatchResult changeMessageVisibilityBatch(String queueUrl, + List entries) throws AmazonServiceException, + AmazonClientException { + + return amazonSqsToBeExtended.changeMessageVisibilityBatch(queueUrl, entries); + } + + /** + *

+ * Changes the visibility timeout of a specified message in a queue to a new + * value. The maximum allowed timeout value you can set the value to is 12 + * hours. This means you can't extend the timeout of a message in an + * existing queue to more than a total visibility timeout of 12 hours. (For + * more information visibility timeout, see Visibility Timeout in the Amazon SQS Developer Guide .) + *

+ *

+ * For example, let's say you have a message and its default message + * visibility timeout is 30 minutes. You could call + * ChangeMessageVisiblity with a value of two hours and the + * effective timeout would be two hours and 30 minutes. When that time comes + * near you could again extend the time out by calling + * ChangeMessageVisiblity, but this time the maximum allowed timeout would + * be 9 hours and 30 minutes. + *

+ *

+ * NOTE: There is a 120,000 limit for the number of inflight messages + * per queue. Messages are inflight after they have been received from the + * queue by a consuming component, but have not yet been deleted from the + * queue. If you reach the 120,000 limit, you will receive an OverLimit + * error message from Amazon SQS. To help avoid reaching the limit, you + * should delete the messages from the queue after they have been processed. + * You can also increase the number of queues you use to process the + * messages. + *

+ *

+ * IMPORTANT:If you attempt to set the VisibilityTimeout to an amount + * more than the maximum time left, Amazon SQS returns an error. It will not + * automatically recalculate and increase the timeout to the maximum time + * remaining. + *

+ *

+ * IMPORTANT:Unlike with a queue, when you change the visibility + * timeout for a specific message, that timeout value is applied immediately + * but is not saved in memory for that message. If you don't delete a + * message after it is received, the visibility timeout for the message the + * next time it is received reverts to the original timeout value, not the + * value you set with the ChangeMessageVisibility action. + *

+ * + * @param queueUrl + * The URL of the Amazon SQS queue to take action on. + * @param receiptHandle + * The receipt handle associated with the message whose + * visibility timeout should be changed. This parameter is + * returned by the ReceiveMessage action. + * @param visibilityTimeout + * The new value (in seconds - from 0 to 43200 - maximum 12 + * hours) for the message's visibility timeout. + * + * @return The response from the ChangeMessageVisibility service method, as + * returned by AmazonSQS. + * + * @throws ReceiptHandleIsInvalidException + * @throws MessageNotInflightException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public ChangeMessageVisibilityResult changeMessageVisibility(String queueUrl, String receiptHandle, Integer visibilityTimeout) + throws AmazonServiceException, AmazonClientException { + + return amazonSqsToBeExtended.changeMessageVisibility(queueUrl, receiptHandle, visibilityTimeout); + } + + /** + *

+ * Returns the URL of an existing queue. This action provides a simple way + * to retrieve the URL of an Amazon SQS queue. + *

+ *

+ * To access a queue that belongs to another AWS account, use the + * QueueOwnerAWSAccountId parameter to specify the account ID + * of the queue's owner. The queue's owner must grant you permission to + * access the queue. For more information about shared queue access, see + * AddPermission or go to Shared Queues in the Amazon SQS Developer Guide . + *

+ * + * @param queueName + * The name of the queue whose URL must be fetched. Maximum 80 + * characters; alphanumeric characters, hyphens (-), and + * underscores (_) are allowed. + * + * @return The response from the GetQueueUrl service method, as returned by + * AmazonSQS. + * + * @throws QueueDoesNotExistException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public GetQueueUrlResult getQueueUrl(String queueName) throws AmazonServiceException, AmazonClientException { + + return amazonSqsToBeExtended.getQueueUrl(queueName); + } + + /** + *

+ * Revokes any permissions in the queue policy that matches the specified + * Label parameter. Only the owner of the queue can remove + * permissions. + *

+ * + * @param queueUrl + * The URL of the Amazon SQS queue to take action on. + * @param label + * The identification of the permission to remove. This is the + * label added with the AddPermission action. + * + * @return The response from the RemovePermission service method, as + * returned by AmazonSQS. + * + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public RemovePermissionResult removePermission(String queueUrl, String label) + throws AmazonServiceException, AmazonClientException { + + return amazonSqsToBeExtended.removePermission(queueUrl, label); + } + + /** + *

+ * Gets attributes for the specified queue. The following attributes are + * supported: + *

    + *
  • All - returns all values.
  • + *
  • ApproximateNumberOfMessages - returns the approximate + * number of visible messages in a queue. For more information, see Resources Required to Process Messages in the Amazon SQS + * Developer Guide .
  • + *
  • ApproximateNumberOfMessagesNotVisible - returns the + * approximate number of messages that are not timed-out and not deleted. + * For more information, see Resources Required to Process Messages in the Amazon SQS + * Developer Guide .
  • + *
  • VisibilityTimeout - returns the visibility timeout for + * the queue. For more information about visibility timeout, see Visibility Timeout in the Amazon SQS Developer Guide .
  • + *
  • CreatedTimestamp - returns the time when the queue was + * created (epoch time in seconds).
  • + *
  • LastModifiedTimestamp - returns the time when the queue + * was last changed (epoch time in seconds).
  • + *
  • Policy - returns the queue's policy.
  • + *
  • MaximumMessageSize - returns the limit of how many bytes + * a message can contain before Amazon SQS rejects it.
  • + *
  • MessageRetentionPeriod - returns the number of seconds + * Amazon SQS retains a message.
  • + *
  • QueueArn - returns the queue's Amazon resource name + * (ARN).
  • + *
  • ApproximateNumberOfMessagesDelayed - returns the + * approximate number of messages that are pending to be added to the queue. + *
  • + *
  • DelaySeconds - returns the default delay on the queue in + * seconds.
  • + *
  • ReceiveMessageWaitTimeSeconds - returns the time for + * which a ReceiveMessage call will wait for a message to arrive.
  • + *
  • RedrivePolicy - returns the parameters for dead letter + * queue functionality of the source queue. For more information about + * RedrivePolicy and dead letter queues, see Using Amazon SQS Dead Letter Queues in the Amazon SQS Developer + * Guide .
  • + * + *
+ * + *

+ *

+ * NOTE:Going forward, new attributes might be added. If you are + * writing code that calls this action, we recommend that you structure your + * code so that it can handle new attributes gracefully. + *

+ *

+ * NOTE:Some API actions take lists of parameters. These lists are + * specified using the param.n notation. Values of n are integers starting + * from 1. For example, a parameter list with two elements looks like this: + *

+ *

+ * &Attribute.1=this + *

+ *

+ * &Attribute.2=that + *

+ * + * @param queueUrl + * The URL of the Amazon SQS queue to take action on. + * @param attributeNames + * A list of attributes to retrieve information for. + * + * @return The response from the GetQueueAttributes service method, as + * returned by AmazonSQS. + * + * @throws InvalidAttributeNameException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public GetQueueAttributesResult getQueueAttributes(String queueUrl, List attributeNames) + throws AmazonServiceException, AmazonClientException { + + return amazonSqsToBeExtended.getQueueAttributes(queueUrl, attributeNames); + } + + /** + *

+ * Delivers up to ten messages to the specified queue. This is a batch + * version of SendMessage. The result of the send action on each message is + * reported individually in the response. The maximum allowed individual + * message size is 256 KB (262,144 bytes). + *

+ *

+ * The maximum total payload size (i.e., the sum of all a batch's individual + * message lengths) is also 256 KB (262,144 bytes). + *

+ *

+ * If the DelaySeconds parameter is not specified for an entry, + * the default for the queue is used. + *

+ *

+ * IMPORTANT:The following list shows the characters (in Unicode) + * that are allowed in your message, according to the W3C XML specification. + * For more information, go to http://www.faqs.org/rfcs/rfc1321.html. If you + * send any characters that are not included in the list, your request will + * be rejected. #x9 | #xA | #xD | [#x20 to #xD7FF] | [#xE000 to #xFFFD] | + * [#x10000 to #x10FFFF] + *

+ *

+ * IMPORTANT: Because the batch request can result in a combination + * of successful and unsuccessful actions, you should check for batch errors + * even when the call returns an HTTP status code of 200. + *

+ *

+ * NOTE:Some API actions take lists of parameters. These lists are + * specified using the param.n notation. Values of n are integers starting + * from 1. For example, a parameter list with two elements looks like this: + *

+ *

+ * &Attribute.1=this + *

+ *

+ * &Attribute.2=that + *

+ * + * @param queueUrl + * The URL of the Amazon SQS queue to take action on. + * @param entries + * A list of SendMessageBatchRequestEntry items. + * + * @return The response from the SendMessageBatch service method, as + * returned by AmazonSQS. + * + * @throws BatchEntryIdsNotDistinctException + * @throws TooManyEntriesInBatchRequestException + * @throws BatchRequestTooLongException + * @throws UnsupportedOperationException + * @throws InvalidBatchEntryIdException + * @throws EmptyBatchRequestException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public SendMessageBatchResult sendMessageBatch(String queueUrl, List entries) + throws AmazonServiceException, AmazonClientException { + + return amazonSqsToBeExtended.sendMessageBatch(queueUrl, entries); + } + + /** + *

+ * Deletes the queue specified by the queue URL , regardless of + * whether the queue is empty. If the specified queue does not exist, Amazon + * SQS returns a successful response. + *

+ *

+ * IMPORTANT: Use DeleteQueue with care; once you delete your queue, + * any messages in the queue are no longer available. + *

+ *

+ * When you delete a queue, the deletion process takes up to 60 seconds. + * Requests you send involving that queue during the 60 seconds might + * succeed. For example, a SendMessage request might succeed, but after the + * 60 seconds, the queue and that message you sent no longer exist. Also, + * when you delete a queue, you must wait at least 60 seconds before + * creating a queue with the same name. + *

+ *

+ * We reserve the right to delete queues that have had no activity for more + * than 30 days. For more information, see How Amazon SQS Queues Work in the Amazon SQS Developer + * Guide . + *

+ * + * @param queueUrl + * The URL of the Amazon SQS queue to take action on. + * + * @return The response from the DeleteQueue service method, as returned by + * AmazonSQS. + * + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public DeleteQueueResult deleteQueue(String queueUrl) throws AmazonServiceException, AmazonClientException { + + return amazonSqsToBeExtended.deleteQueue(queueUrl); + } + + /** + *

+ * Returns a list of your queues. The maximum number of queues that can be + * returned is 1000. If you specify a value for the optional + * QueueNamePrefix parameter, only queues with a name beginning + * with the specified value are returned. + *

+ * + * @param queueNamePrefix + * A string to use for filtering the list results. Only those + * queues whose name begins with the specified string are + * returned. + * + * @return The response from the ListQueues service method, as returned by + * AmazonSQS. + * + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public ListQueuesResult listQueues(String queueNamePrefix) throws AmazonServiceException, AmazonClientException { + + return amazonSqsToBeExtended.listQueues(queueNamePrefix); + } + + /** + *

+ * Deletes up to ten messages from the specified queue. This is a batch + * version of DeleteMessage. The result of the delete action on each message + * is reported individually in the response. + *

+ *

+ * IMPORTANT: Because the batch request can result in a combination + * of successful and unsuccessful actions, you should check for batch errors + * even when the call returns an HTTP status code of 200. + *

+ *

+ * NOTE:Some API actions take lists of parameters. These lists are + * specified using the param.n notation. Values of n are integers starting + * from 1. For example, a parameter list with two elements looks like this: + *

+ *

+ * &Attribute.1=this + *

+ *

+ * &Attribute.2=that + *

+ * + * @param queueUrl + * The URL of the Amazon SQS queue to take action on. + * @param entries + * A list of receipt handles for the messages to be deleted. + * + * @return The response from the DeleteMessageBatch service method, as + * returned by AmazonSQS. + * + * @throws BatchEntryIdsNotDistinctException + * @throws TooManyEntriesInBatchRequestException + * @throws InvalidBatchEntryIdException + * @throws EmptyBatchRequestException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public DeleteMessageBatchResult deleteMessageBatch(String queueUrl, List entries) + throws AmazonServiceException, AmazonClientException { + + return amazonSqsToBeExtended.deleteMessageBatch(queueUrl, entries); + } + + /** + *

+ * Creates a new queue, or returns the URL of an existing one. When you + * request CreateQueue , you provide a name for the queue. To + * successfully create a new queue, you must provide a name that is unique + * within the scope of your own queues. + *

+ *

+ * NOTE: If you delete a queue, you must wait at least 60 seconds + * before creating a queue with the same name. + *

+ *

+ * You may pass one or more attributes in the request. If you do not provide + * a value for any attribute, the queue will have the default value for that + * attribute. Permitted attributes are the same that can be set using + * SetQueueAttributes. + *

+ *

+ * NOTE: Use GetQueueUrl to get a queue's URL. GetQueueUrl requires + * only the QueueName parameter. + *

+ *

+ * If you provide the name of an existing queue, along with the exact names + * and values of all the queue's attributes, CreateQueue + * returns the queue URL for the existing queue. If the queue name, + * attribute names, or attribute values do not match an existing queue, + * CreateQueue returns an error. + *

+ *

+ * NOTE:Some API actions take lists of parameters. These lists are + * specified using the param.n notation. Values of n are integers starting + * from 1. For example, a parameter list with two elements looks like this: + *

+ *

+ * &Attribute.1=this + *

+ *

+ * &Attribute.2=that + *

+ * + * @param queueName + * The name for the queue to be created. + * + * @return The response from the CreateQueue service method, as returned by + * AmazonSQS. + * + * @throws QueueNameExistsException + * @throws QueueDeletedRecentlyException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public CreateQueueResult createQueue(String queueName) throws AmazonServiceException, AmazonClientException { + + return amazonSqsToBeExtended.createQueue(queueName); + } + + /** + *

+ * Adds a permission to a queue for a specific + * principal . This allows for sharing access to the queue. + *

+ *

+ * When you create a queue, you have full control access rights for the + * queue. Only you (as owner of the queue) can grant or deny permissions to + * the queue. For more information about these permissions, see Shared Queues in the Amazon SQS Developer Guide . + *

+ *

+ * NOTE: AddPermission writes an Amazon SQS-generated policy. If you + * want to write your own policy, use SetQueueAttributes to upload your + * policy. For more information about writing your own policy, see Using The + * Access Policy Language in the Amazon SQS Developer Guide. + *

+ *

+ * NOTE:Some API actions take lists of parameters. These lists are + * specified using the param.n notation. Values of n are integers starting + * from 1. For example, a parameter list with two elements looks like this: + *

+ *

+ * &Attribute.1=this + *

+ *

+ * &Attribute.2=that + *

+ * + * @param queueUrl + * The URL of the Amazon SQS queue to take action on. + * @param label + * The unique identification of the permission you're setting + * (e.g., AliceSendMessage). Constraints: Maximum 80 + * characters; alphanumeric characters, hyphens (-), and + * underscores (_) are allowed. + * @param aWSAccountIds + * The AWS account number of the principal who will be given permission. The principal + * must have an AWS account, but does not need to be signed up + * for Amazon SQS. For information about locating the AWS account + * identification, see Your AWS Identifiers in the Amazon SQS Developer + * Guide. + * @param actions + * The action the client wants to allow for the specified + * principal. The following are valid values: + * * | SendMessage | + * ReceiveMessage | DeleteMessage | ChangeMessageVisibility | + * GetQueueAttributes | GetQueueUrl. For more information about these + * actions, see Understanding Permissions in the Amazon SQS Developer + * Guide. + *

+ * Specifying SendMessage, + * DeleteMessage, or + * ChangeMessageVisibility for the + * ActionName.n also grants permissions for the + * corresponding batch versions of those actions: + * SendMessageBatch, DeleteMessageBatch + * , and ChangeMessageVisibilityBatch. + * + * @return The response from the AddPermission service method, as returned + * by AmazonSQS. + * + * @throws OverLimitException + * + * @throws AmazonClientException + * If any internal errors are encountered inside the client + * while attempting to make the request or handle the response. + * For example if a network connection is not available. + * @throws AmazonServiceException + * If an error response is returned by AmazonSQS indicating + * either a problem with the data in the request, or a server + * side issue. + */ + public AddPermissionResult addPermission(String queueUrl, String label, List aWSAccountIds, List actions) + throws AmazonServiceException, AmazonClientException { + + return amazonSqsToBeExtended.addPermission(queueUrl, label, aWSAccountIds, actions); + } + + /** + * Returns additional metadata for a previously executed successful, + * request, typically used for debugging issues where a service isn't acting + * as expected. This data isn't considered part of the result data returned + * by an operation, so it's available through this separate, diagnostic + * interface. + *

+ * Response metadata is only cached for a limited period of time, so if you + * need to access this extra diagnostic information for an executed request, + * you should use this method to retrieve it as soon as possible after + * executing the request. + * + * @param request + * The originally executed request + * + * @return The response metadata for the specified request, or null if none + * is available. + */ + public ResponseMetadata getCachedResponseMetadata(AmazonWebServiceRequest request) { + + return amazonSqsToBeExtended.getCachedResponseMetadata(request); + } + + /** + * Overrides the default endpoint for this client ("sqs.us-east-1.amazonaws.com"). + * Callers can use this method to control which AWS region they want to work with. + *

+ * Callers can pass in just the endpoint (ex: "sqs.us-east-1.amazonaws.com") or a full + * URL, including the protocol (ex: "sqs.us-east-1.amazonaws.com"). If the + * protocol is not specified here, the default protocol from this client's + * {@link ClientConfiguration} will be used, which by default is HTTPS. + *

+ * For more information on using AWS regions with the AWS SDK for Java, and + * a complete list of all available endpoints for all AWS services, see: + * + * http://developer.amazonwebservices.com/connect/entry.jspa?externalID=3912 + *

+ * This method is not threadsafe. An endpoint should be configured when the + * client is created and before any service requests are made. Changing it + * afterwards creates inevitable race conditions for any service requests in + * transit or retrying. + * + * @param endpoint + * The endpoint (ex: "sqs.us-east-1.amazonaws.com") or a full URL, + * including the protocol (ex: "sqs.us-east-1.amazonaws.com") of + * the region specific AWS endpoint this client will communicate + * with. + * + * @throws IllegalArgumentException + * If any problems are detected with the specified endpoint. + */ + public void setEndpoint(String endpoint) throws IllegalArgumentException { + + amazonSqsToBeExtended.setEndpoint(endpoint); + + } + + /** + * An alternative to {@link AmazonSQS#setEndpoint(String)}, sets the + * regional endpoint for this client's service calls. Callers can use this + * method to control which AWS region they want to work with. + *

+ * By default, all service endpoints in all regions use the https protocol. + * To use http instead, specify it in the {@link ClientConfiguration} + * supplied at construction. + *

+ * This method is not threadsafe. A region should be configured when the + * client is created and before any service requests are made. Changing it + * afterwards creates inevitable race conditions for any service requests in + * transit or retrying. + * + * @param region + * The region this client will communicate with. See + * {@link Region#getRegion(com.amazonaws.regions.Regions)} for + * accessing a given region. + * @throws java.lang.IllegalArgumentException + * If the given region is null, or if this service isn't + * available in the given region. See + * {@link Region#isServiceSupported(String)} + * @see Region#getRegion(com.amazonaws.regions.Regions) + * @see Region#createClient(Class, AWSCredentialsProvider, ClientConfiguration) + */ + public void setRegion(Region region) throws IllegalArgumentException { + + amazonSqsToBeExtended.setRegion(region); + + } + + /** + * Shuts down this client object, releasing any resources that might be held + * open. This is an optional method, and callers are not expected to call + * it, but can if they want to explicitly release any open resources. Once a + * client has been shutdown, it should not be used to make any more + * requests. + */ + public void shutdown() { + + amazonSqsToBeExtended.shutdown(); + } + + /** {@inheritDoc} */ + @Override public ListQueueTagsResult listQueueTags(final ListQueueTagsRequest listQueueTagsRequest) { + return amazonSqsToBeExtended.listQueueTags(listQueueTagsRequest); + } + + /** {@inheritDoc} */ + @Override public ListQueueTagsResult listQueueTags(final String queueUrl) { + return amazonSqsToBeExtended.listQueueTags(queueUrl); + } + + /** {@inheritDoc} */ + @Override public TagQueueResult tagQueue(final TagQueueRequest tagQueueRequest) { + return amazonSqsToBeExtended.tagQueue(tagQueueRequest); + } + + /** {@inheritDoc} */ + @Override public TagQueueResult tagQueue(final String queueUrl, final Map tags) { + return amazonSqsToBeExtended.tagQueue(queueUrl, tags); + } + + /** {@inheritDoc} */ + @Override public UntagQueueResult untagQueue(final UntagQueueRequest untagQueueRequest) { + return amazonSqsToBeExtended.untagQueue(untagQueueRequest); + } + + /** {@inheritDoc} */ + @Override public UntagQueueResult untagQueue(final String queueUrl, final List tagKeys) { + return amazonSqsToBeExtended.untagQueue(queueUrl, tagKeys); + } } diff --git a/src/main/java/com/amazon/sqs/javamessaging/CountingOutputStream.java b/src/main/java/com/amazon/sqs/javamessaging/CountingOutputStream.java deleted file mode 100644 index d99fbe8..0000000 --- a/src/main/java/com/amazon/sqs/javamessaging/CountingOutputStream.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.sqs.javamessaging; - -import java.io.OutputStream; - -/** - * This class is used for checking the size of a string without copying the - * whole string into memory and converting it to bytes array. Compared to - * String.getBytes().length, it is more efficient and reliable for large - * strings. - */ -class CountingOutputStream extends OutputStream { - private long totalSize; - - @Override - public void write(int b) { - ++totalSize; - } - - @Override - public void write(byte[] b) { - totalSize += b.length; - } - - @Override - public void write(byte[] b, int offset, int len) { - - totalSize += len; - } - - public long getTotalSize() { - return totalSize; - } -} diff --git a/src/main/java/com/amazon/sqs/javamessaging/ExtendedClientConfiguration.java b/src/main/java/com/amazon/sqs/javamessaging/ExtendedClientConfiguration.java index 4852178..2ef4231 100644 --- a/src/main/java/com/amazon/sqs/javamessaging/ExtendedClientConfiguration.java +++ b/src/main/java/com/amazon/sqs/javamessaging/ExtendedClientConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2010-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -15,203 +15,138 @@ package com.amazon.sqs.javamessaging; -import com.amazonaws.AmazonClientException; import com.amazonaws.services.s3.AmazonS3; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import com.amazonaws.services.s3.model.SSEAwsKeyManagementParams; import com.amazonaws.annotation.NotThreadSafe; +import software.amazon.payloadoffloading.PayloadStorageConfiguration; -import java.util.List; /** * Amazon SQS extended client configuration options such as Amazon S3 client, * bucket name, and message size threshold for large-payload messages. */ @NotThreadSafe -public class ExtendedClientConfiguration { - private static final Log LOG = LogFactory.getLog(ExtendedClientConfiguration.class); - - private AmazonS3 s3; - private String s3BucketName; - private boolean largePayloadSupport = false; - private boolean alwaysThroughS3 = false; - private int messageSizeThreshold = SQSExtendedClientConstants.DEFAULT_MESSAGE_SIZE_THRESHOLD; - - public ExtendedClientConfiguration() { - s3 = null; - s3BucketName = null; - } - - public ExtendedClientConfiguration(ExtendedClientConfiguration other) { - this.s3 = other.s3; - this.s3BucketName = other.s3BucketName; - this.largePayloadSupport = other.largePayloadSupport; - this.alwaysThroughS3 = other.alwaysThroughS3; - this.messageSizeThreshold = other.messageSizeThreshold; - } - - /** - * Enables support for large-payload messages. - * - * @param s3 - * Amazon S3 client which is going to be used for storing - * large-payload messages. - * @param s3BucketName - * Name of the bucket which is going to be used for storing - * large-payload messages. The bucket must be already created and - * configured in s3. - */ - public void setLargePayloadSupportEnabled(AmazonS3 s3, String s3BucketName) { - if (s3 == null || s3BucketName == null) { - String errorMessage = "S3 client and/or S3 bucket name cannot be null."; - LOG.error(errorMessage); - throw new AmazonClientException(errorMessage); - } - if (isLargePayloadSupportEnabled()) { - LOG.warn("Large-payload support is already enabled. Overwriting AmazonS3Client and S3BucketName."); - } - this.s3 = s3; - this.s3BucketName = s3BucketName; - largePayloadSupport = true; - LOG.info("Large-payload support enabled."); - } - - /** - * Enables support for large-payload messages. - * - * @param s3 - * Amazon S3 client which is going to be used for storing - * large-payload messages. - * @param s3BucketName - * Name of the bucket which is going to be used for storing - * large-payload messages. The bucket must be already created and - * configured in s3. - * @return the updated ExtendedClientConfiguration object. - */ - public ExtendedClientConfiguration withLargePayloadSupportEnabled(AmazonS3 s3, String s3BucketName) { - setLargePayloadSupportEnabled(s3, s3BucketName); - return this; - } - - /** - * Disables support for large-payload messages. - */ - public void setLargePayloadSupportDisabled() { - s3 = null; - s3BucketName = null; - largePayloadSupport = false; - LOG.info("Large-payload support disabled."); - } - - /** - * Disables support for large-payload messages. - * @return the updated ExtendedClientConfiguration object. - */ - public ExtendedClientConfiguration withLargePayloadSupportDisabled() { - setLargePayloadSupportDisabled(); - return this; - } - - /** - * Check if the support for large-payload message if enabled. - * - * @return true if support for large-payload messages is enabled. - */ - public boolean isLargePayloadSupportEnabled() { - return largePayloadSupport; - } - - /** - * Gets the Amazon S3 client which is being used for storing large-payload - * messages. - * - * @return Reference to the Amazon S3 client which is being used. - */ - public AmazonS3 getAmazonS3Client() { - return s3; - } - - /** - * Gets the name of the S3 bucket which is being used for storing - * large-payload messages. - * - * @return The name of the bucket which is being used. - */ - public String getS3BucketName() { - return s3BucketName; - } - - /** - * Sets the message size threshold for storing message payloads in Amazon - * S3. - * - * @param messageSizeThreshold - * Message size threshold to be used for storing in Amazon S3. - * Default: 256KB. - */ - public void setMessageSizeThreshold(int messageSizeThreshold) { - this.messageSizeThreshold = messageSizeThreshold; - } - - /** - * Sets the message size threshold for storing message payloads in Amazon - * S3. - * - * @param messageSizeThreshold - * Message size threshold to be used for storing in Amazon S3. - * Default: 256KB. - * @return the updated ExtendedClientConfiguration object. - */ - public ExtendedClientConfiguration withMessageSizeThreshold(int messageSizeThreshold) { - setMessageSizeThreshold(messageSizeThreshold); - return this; - } - - /** - * Gets the message size threshold for storing message payloads in Amazon - * S3. - * - * @return Message size threshold which is being used for storing in Amazon - * S3. Default: 256KB. - */ - public int getMessageSizeThreshold() { - return messageSizeThreshold; - } - - /** - * Sets whether or not all messages regardless of their payload size should - * be stored in Amazon S3. - * - * @param alwaysThroughS3 - * Whether or not all messages regardless of their payload size - * should be stored in Amazon S3. Default: false - */ - public void setAlwaysThroughS3(boolean alwaysThroughS3) { - this.alwaysThroughS3 = alwaysThroughS3; - } - - /** - * Sets whether or not all messages regardless of their payload size should - * be stored in Amazon S3. - * - * @param alwaysThroughS3 - * Whether or not all messages regardless of their payload size - * should be stored in Amazon S3. Default: false - * @return the updated ExtendedClientConfiguration object. - */ - public ExtendedClientConfiguration withAlwaysThroughS3(boolean alwaysThroughS3) { - setAlwaysThroughS3(alwaysThroughS3); - return this; - } - - /** - * Checks whether or not all messages regardless of their payload size are - * being stored in Amazon S3. - * - * @return True if all messages regardless of their payload size are being - * stored in Amazon S3. Default: false - */ - public boolean isAlwaysThroughS3() { - return alwaysThroughS3; - } -} +public class ExtendedClientConfiguration extends PayloadStorageConfiguration { + + private boolean cleanupS3Payload = true; + private boolean useLegacyReservedAttributeName = true; + + public ExtendedClientConfiguration() { + super(); + this.setPayloadSizeThreshold(SQSExtendedClientConstants.DEFAULT_MESSAGE_SIZE_THRESHOLD); + } + + public ExtendedClientConfiguration(ExtendedClientConfiguration other) { + super(other); + this.cleanupS3Payload = other.doesCleanupS3Payload(); + this.useLegacyReservedAttributeName = other.usesLegacyReservedAttributeName(); + } + + /** + * Enables support for payload messages. + * @param s3 + * Amazon S3 client which is going to be used for storing + * payload messages. + * @param s3BucketName + * Name of the bucket which is going to be used for storing + * payload messages. The bucket must be already created and + * configured in s3. + * @param cleanupS3Payload + * If set to true, would handle deleting the S3 object as part + * of deleting the message from SQS queue. Otherwise, would not + * attempt to delete the object from S3. If opted to not delete S3 + * objects its the responsibility to the message producer to handle + * the clean up appropriately. + */ + public void setPayloadSupportEnabled(AmazonS3 s3, String s3BucketName, boolean cleanupS3Payload) { + setPayloadSupportEnabled(s3, s3BucketName); + this.cleanupS3Payload = cleanupS3Payload; + } + + /** + * Enables support for payload messages. + * @param s3 + * Amazon S3 client which is going to be used for storing + * payload messages. + * @param s3BucketName + * Name of the bucket which is going to be used for storing + * payload messages. The bucket must be already created and + * configured in s3. + * @param cleanupS3Payload + * If set to true, would handle deleting the S3 object as part + * of deleting the message from SQS queue. Otherwise, would not + * attempt to delete the object from S3. If opted to not delete S3 + * objects its the responsibility to the message producer to handle + * the clean up appropriately. + */ + public ExtendedClientConfiguration withPayloadSupportEnabled(AmazonS3 s3, String s3BucketName, boolean cleanupS3Payload) { + setPayloadSupportEnabled(s3, s3BucketName, cleanupS3Payload); + return this; + } + + /** + * Disables the utilization legacy payload attribute name when sending messages. + */ + public void setLegacyReservedAttributeNameDisabled() { + this.useLegacyReservedAttributeName = false; + } + + /** + * Disables the utilization legacy payload attribute name when sending messages. + */ + public ExtendedClientConfiguration withLegacyReservedAttributeNameDisabled() { + setLegacyReservedAttributeNameDisabled(); + return this; + } + + /** + * Checks whether or not clean up large objects in S3 is enabled. + * + * @return True if clean up is enabled when deleting the concerning SQS message. + * Default: true + */ + public boolean doesCleanupS3Payload() { + return cleanupS3Payload; + } + + /** + * Checks whether or not the configuration uses the legacy reserved attribute name. + * + * @return True if legacy reserved attribute name is used. + * Default: true + */ + + public boolean usesLegacyReservedAttributeName() { + return useLegacyReservedAttributeName; + } + + @Override + public ExtendedClientConfiguration withAlwaysThroughS3(boolean alwaysThroughS3) { + setAlwaysThroughS3(alwaysThroughS3); + return this; + } + + @Override + public ExtendedClientConfiguration withPayloadSupportEnabled(AmazonS3 s3, String s3BucketName) { + this.setPayloadSupportEnabled(s3, s3BucketName); + return this; + } + + @Override + public ExtendedClientConfiguration withSSEAwsKeyManagementParams(SSEAwsKeyManagementParams sseAwsKeyManagementParams) { + this.setSSEAwsKeyManagementParams(sseAwsKeyManagementParams); + return this; + } + + @Override + public ExtendedClientConfiguration withPayloadSizeThreshold(int payloadSizeThreshold) { + this.setPayloadSizeThreshold(payloadSizeThreshold); + return this; + } + + @Override + public ExtendedClientConfiguration withPayloadSupportDisabled() { + this.setPayloadSupportDisabled(); + return this; + } +} \ No newline at end of file diff --git a/src/main/java/com/amazon/sqs/javamessaging/JsonDataConverter.java b/src/main/java/com/amazon/sqs/javamessaging/JsonDataConverter.java deleted file mode 100644 index 8deebab..0000000 --- a/src/main/java/com/amazon/sqs/javamessaging/JsonDataConverter.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.sqs.javamessaging; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.SerializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.ObjectWriter; -import com.fasterxml.jackson.databind.ObjectMapper.DefaultTyping; - -/** - * This class implements conversion through Jackson JSON processor. Methods are - * provided for serializing an object to JSON and deserializing from JSON to an - * object. - */ -class JsonDataConverter { - - protected final ObjectMapper objectMapper; - - public JsonDataConverter() { - this(new ObjectMapper()); - objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); - objectMapper.enableDefaultTyping(DefaultTyping.NON_FINAL); - } - - public JsonDataConverter(ObjectMapper objectMapper) { - this.objectMapper = objectMapper; - } - - public String serializeToJson(Object obj) throws JsonProcessingException { - ObjectWriter objectWriter = objectMapper.writer(); - return objectWriter.writeValueAsString(obj); - } - - public T deserializeFromJson(String jsonText, Class objectType) throws Exception { - return objectMapper.readValue(jsonText, objectType); - } - -} diff --git a/src/main/java/com/amazon/sqs/javamessaging/MessageS3Pointer.java b/src/main/java/com/amazon/sqs/javamessaging/MessageS3Pointer.java deleted file mode 100644 index 5cbe4eb..0000000 --- a/src/main/java/com/amazon/sqs/javamessaging/MessageS3Pointer.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.sqs.javamessaging; - -/** - * This class is used for carrying pointer to Amazon S3 objects which contain - * message payloads. For a large-payload messages, an instance of this class - * will be serialized to JSON and sent through Amazon SQS. - * - */ -class MessageS3Pointer { - private String s3BucketName; - private String s3Key; - - public MessageS3Pointer() { - } - - public MessageS3Pointer(String s3BucketName, String s3Key) { - this.s3BucketName = s3BucketName; - this.s3Key = s3Key; - } - - public String getS3BucketName() { - return s3BucketName; - } - - public void setS3BucketName(String s3BucketName) { - this.s3BucketName = s3BucketName; - } - - public String getS3Key() { - return s3Key; - } - - public void setS3Key(String s3Key) { - this.s3Key = s3Key; - } - -} diff --git a/src/main/java/com/amazon/sqs/javamessaging/SQSExtendedClientConstants.java b/src/main/java/com/amazon/sqs/javamessaging/SQSExtendedClientConstants.java index 51a5e11..f41d271 100644 --- a/src/main/java/com/amazon/sqs/javamessaging/SQSExtendedClientConstants.java +++ b/src/main/java/com/amazon/sqs/javamessaging/SQSExtendedClientConstants.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2010-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -15,14 +15,11 @@ package com.amazon.sqs.javamessaging; -import com.amazonaws.util.VersionInfoUtils; -class SQSExtendedClientConstants { - public static final String RESERVED_ATTRIBUTE_NAME = "SQSLargePayloadSize"; - public static final int MAX_ALLOWED_ATTRIBUTES = 10 - 1; // 10 for SQS, 1 for the reserved attribute - public static final int DEFAULT_MESSAGE_SIZE_THRESHOLD = 262144; - public static final String S3_BUCKET_NAME_MARKER = "-..s3BucketName..-"; - public static final String S3_KEY_MARKER = "-..s3Key..-"; - - static final String USER_AGENT_HEADER = AmazonSQSExtendedClient.class.getSimpleName() + "/" + VersionInfoUtils.getVersion(); +public class SQSExtendedClientConstants { + public static final String RESERVED_ATTRIBUTE_NAME = "ExtendedPayloadSize"; + public static final int MAX_ALLOWED_ATTRIBUTES = 10 - 1; // 10 for SQS, 1 for the reserved attribute + public static final int DEFAULT_MESSAGE_SIZE_THRESHOLD = 262144; + public static final String S3_BUCKET_NAME_MARKER = "-..s3BucketName..-"; + public static final String S3_KEY_MARKER = "-..s3Key..-"; } diff --git a/src/test/java/com/amazon/sqs/javamessaging/AmazonSQSExtendedClientTest.java b/src/test/java/com/amazon/sqs/javamessaging/AmazonSQSExtendedClientTest.java index 3dd70c3..40cf85f 100644 --- a/src/test/java/com/amazon/sqs/javamessaging/AmazonSQSExtendedClientTest.java +++ b/src/test/java/com/amazon/sqs/javamessaging/AmazonSQSExtendedClientTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2010-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -15,35 +15,28 @@ package com.amazon.sqs.javamessaging; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.IntStream; import com.amazonaws.services.s3.AmazonS3; +import com.amazonaws.services.s3.model.GetObjectRequest; import com.amazonaws.services.s3.model.PutObjectRequest; +import com.amazonaws.services.s3.model.S3Object; +import com.amazonaws.services.s3.model.SSEAwsKeyManagementParams; import com.amazonaws.services.sqs.AmazonSQS; import com.amazonaws.services.sqs.AmazonSQSClient; -import com.amazonaws.services.sqs.model.MessageAttributeValue; -import com.amazonaws.services.sqs.model.ReceiveMessageRequest; -import com.amazonaws.services.sqs.model.ReceiveMessageResult; -import com.amazonaws.services.sqs.model.SendMessageBatchRequest; -import com.amazonaws.services.sqs.model.SendMessageBatchRequestEntry; -import com.amazonaws.services.sqs.model.SendMessageRequest; - -import junit.framework.Assert; +import com.amazonaws.services.sqs.model.*; + +import com.amazonaws.util.StringInputStream; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; +import software.amazon.payloadoffloading.PayloadS3Pointer; import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.isA; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; /** * Tests the AmazonSQSExtendedClient class. @@ -51,29 +44,46 @@ public class AmazonSQSExtendedClientTest { private AmazonSQS extendedSqsWithDefaultConfig; + private AmazonSQS extendedSqsWithCustomKMS; + private AmazonSQS extendedSqsWithDefaultKMS; + private AmazonSQS extendedSqsWithGenericReservedAttributeName; private AmazonSQS mockSqsBackend; private AmazonS3 mockS3; private static final String S3_BUCKET_NAME = "test-bucket-name"; private static final String SQS_QUEUE_URL = "test-queue-url"; + private static final String S3_SERVER_SIDE_ENCRYPTION_KMS_KEY_ID = "test-customer-managed-kms-key-id"; private static final int LESS_THAN_SQS_SIZE_LIMIT = 3; private static final int SQS_SIZE_LIMIT = 262144; private static final int MORE_THAN_SQS_SIZE_LIMIT = SQS_SIZE_LIMIT + 1; // should be > 1 and << SQS_SIZE_LIMIT - private static final int ARBITRATY_SMALLER_THRESSHOLD = 500; + private static final int ARBITRARY_SMALLER_THRESHOLD = 500; @Before - public void setupClient() { + public void setupClients() { mockS3 = mock(AmazonS3.class); mockSqsBackend = mock(AmazonSQS.class); when(mockS3.putObject(isA(PutObjectRequest.class))).thenReturn(null); ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration() - .withLargePayloadSupportEnabled(mockS3, S3_BUCKET_NAME); + .withPayloadSupportEnabled(mockS3, S3_BUCKET_NAME); - extendedSqsWithDefaultConfig = spy(new AmazonSQSExtendedClient(mockSqsBackend, extendedClientConfiguration)); + ExtendedClientConfiguration extendedClientConfigurationWithCustomKMS = new ExtendedClientConfiguration() + .withPayloadSupportEnabled(mockS3, S3_BUCKET_NAME) + .withSSEAwsKeyManagementParams(new SSEAwsKeyManagementParams(S3_SERVER_SIDE_ENCRYPTION_KMS_KEY_ID)); + + ExtendedClientConfiguration extendedClientConfigurationWithDefaultKMS = new ExtendedClientConfiguration() + .withPayloadSupportEnabled(mockS3, S3_BUCKET_NAME) + .withSSEAwsKeyManagementParams(new SSEAwsKeyManagementParams()); + + ExtendedClientConfiguration extendedClientConfigurationWithGenericReservedAttributeName = new ExtendedClientConfiguration() + .withPayloadSupportEnabled(mockS3, S3_BUCKET_NAME).withLegacyReservedAttributeNameDisabled(); + extendedSqsWithDefaultConfig = spy(new AmazonSQSExtendedClient(mockSqsBackend, extendedClientConfiguration)); + extendedSqsWithCustomKMS = spy(new AmazonSQSExtendedClient(mockSqsBackend, extendedClientConfigurationWithCustomKMS)); + extendedSqsWithDefaultKMS = spy(new AmazonSQSExtendedClient(mockSqsBackend, extendedClientConfigurationWithDefaultKMS)); + extendedSqsWithGenericReservedAttributeName = spy(new AmazonSQSExtendedClient(mockSqsBackend, extendedClientConfigurationWithGenericReservedAttributeName)); } @Test @@ -86,6 +96,81 @@ public void testWhenSendLargeMessageThenPayloadIsStoredInS3() { verify(mockS3, times(1)).putObject(isA(PutObjectRequest.class)); } + @Test + public void testWhenSendLargeMessage_WithoutKMS_ThenPayloadIsStoredInS3AndKMSKeyIdIsNotUsed() { + String messageBody = generateStringWithLength(MORE_THAN_SQS_SIZE_LIMIT); + + SendMessageRequest messageRequest = new SendMessageRequest(SQS_QUEUE_URL, messageBody); + extendedSqsWithDefaultConfig.sendMessage(messageRequest); + + ArgumentCaptor putObjectRequestArgumentCaptor = ArgumentCaptor.forClass(PutObjectRequest.class); + verify(mockS3, times(1)).putObject(putObjectRequestArgumentCaptor.capture()); + + Assert.assertNull(putObjectRequestArgumentCaptor.getValue().getSSEAwsKeyManagementParams()); + Assert.assertEquals(putObjectRequestArgumentCaptor.getValue().getBucketName(), S3_BUCKET_NAME); + } + + @Test + public void testWhenSendLargeMessage_WithCustomKMS_ThenPayloadIsStoredInS3AndCorrectKMSKeyIdIsNotUsed() { + String messageBody = generateStringWithLength(MORE_THAN_SQS_SIZE_LIMIT); + + SendMessageRequest messageRequest = new SendMessageRequest(SQS_QUEUE_URL, messageBody); + extendedSqsWithCustomKMS.sendMessage(messageRequest); + + ArgumentCaptor putObjectRequestArgumentCaptor = ArgumentCaptor.forClass(PutObjectRequest.class); + verify(mockS3, times(1)).putObject(putObjectRequestArgumentCaptor.capture()); + + Assert.assertEquals(putObjectRequestArgumentCaptor.getValue().getSSEAwsKeyManagementParams() + .getAwsKmsKeyId(), S3_SERVER_SIDE_ENCRYPTION_KMS_KEY_ID); + Assert.assertEquals(putObjectRequestArgumentCaptor.getValue().getBucketName(), S3_BUCKET_NAME); + } + + @Test + public void testWhenSendLargeMessage_WithDefaultKMS_ThenPayloadIsStoredInS3AndCorrectKMSKeyIdIsNotUsed() { + String messageBody = generateStringWithLength(MORE_THAN_SQS_SIZE_LIMIT); + + SendMessageRequest messageRequest = new SendMessageRequest(SQS_QUEUE_URL, messageBody); + extendedSqsWithDefaultKMS.sendMessage(messageRequest); + + ArgumentCaptor putObjectRequestArgumentCaptor = ArgumentCaptor.forClass(PutObjectRequest.class); + verify(mockS3, times(1)).putObject(putObjectRequestArgumentCaptor.capture()); + + Assert.assertTrue(putObjectRequestArgumentCaptor.getValue().getSSEAwsKeyManagementParams() != null && + putObjectRequestArgumentCaptor.getValue().getSSEAwsKeyManagementParams().getAwsKmsKeyId() == null); + Assert.assertEquals(putObjectRequestArgumentCaptor.getValue().getBucketName(), S3_BUCKET_NAME); + } + + @Test + public void testSendLargeMessageWithDefaultConfigThenLegacyReservedAttributeNameIsUsed(){ + int messageLength = MORE_THAN_SQS_SIZE_LIMIT; + String messageBody = generateStringWithLength(messageLength); + SendMessageRequest messageRequest = new SendMessageRequest(SQS_QUEUE_URL, messageBody); + extendedSqsWithDefaultConfig.sendMessage(messageRequest); + + ArgumentCaptor sendMessageRequestCaptor = ArgumentCaptor.forClass(SendMessageRequest.class); + verify(mockSqsBackend).sendMessage(sendMessageRequestCaptor.capture()); + + Map attributes = sendMessageRequestCaptor.getValue().getMessageAttributes(); + Assert.assertTrue(attributes.keySet().contains(AmazonSQSExtendedClient.LEGACY_RESERVED_ATTRIBUTE_NAME)); + Assert.assertFalse(attributes.keySet().contains(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME)); + + } + + @Test + public void testSendLargeMessageWithGenericReservedAttributeNameConfigThenGenericReservedAttributeNameIsUsed(){ + int messageLength = MORE_THAN_SQS_SIZE_LIMIT; + String messageBody = generateStringWithLength(messageLength); + SendMessageRequest messageRequest = new SendMessageRequest(SQS_QUEUE_URL, messageBody); + extendedSqsWithGenericReservedAttributeName.sendMessage(messageRequest); + + ArgumentCaptor sendMessageRequestCaptor = ArgumentCaptor.forClass(SendMessageRequest.class); + verify(mockSqsBackend).sendMessage(sendMessageRequestCaptor.capture()); + + Map attributes = sendMessageRequestCaptor.getValue().getMessageAttributes(); + Assert.assertTrue(attributes.keySet().contains(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME)); + Assert.assertFalse(attributes.keySet().contains(AmazonSQSExtendedClient.LEGACY_RESERVED_ATTRIBUTE_NAME)); + } + @Test public void testWhenSendSmallMessageThenS3IsNotUsed() { int messageLength = SQS_SIZE_LIMIT; @@ -102,7 +187,7 @@ public void testWhenSendMessageWithLargePayloadSupportDisabledThenS3IsNotUsedAnd int messageLength = MORE_THAN_SQS_SIZE_LIMIT; String messageBody = generateStringWithLength(messageLength); ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration() - .withLargePayloadSupportDisabled(); + .withPayloadSupportDisabled(); AmazonSQS sqsExtended = spy(new AmazonSQSExtendedClient(mockSqsBackend, extendedClientConfiguration)); SendMessageRequest messageRequest = new SendMessageRequest(SQS_QUEUE_URL, messageBody); @@ -117,7 +202,7 @@ public void testWhenSendMessageWithAlwaysThroughS3AndMessageIsSmallThenItIsStill int messageLength = LESS_THAN_SQS_SIZE_LIMIT; String messageBody = generateStringWithLength(messageLength); ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration() - .withLargePayloadSupportEnabled(mockS3, S3_BUCKET_NAME).withAlwaysThroughS3(true); + .withPayloadSupportEnabled(mockS3, S3_BUCKET_NAME).withAlwaysThroughS3(true); AmazonSQS sqsExtended = spy(new AmazonSQSExtendedClient(mock(AmazonSQSClient.class), extendedClientConfiguration)); SendMessageRequest messageRequest = new SendMessageRequest(SQS_QUEUE_URL, messageBody); @@ -128,10 +213,10 @@ public void testWhenSendMessageWithAlwaysThroughS3AndMessageIsSmallThenItIsStill @Test public void testWhenSendMessageWithSetMessageSizeThresholdThenThresholdIsHonored() { - int messageLength = ARBITRATY_SMALLER_THRESSHOLD * 2; + int messageLength = ARBITRARY_SMALLER_THRESHOLD * 2; String messageBody = generateStringWithLength(messageLength); ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration() - .withLargePayloadSupportEnabled(mockS3, S3_BUCKET_NAME).withMessageSizeThreshold(ARBITRATY_SMALLER_THRESSHOLD); + .withPayloadSupportEnabled(mockS3, S3_BUCKET_NAME).withPayloadSizeThreshold(ARBITRARY_SMALLER_THRESHOLD); AmazonSQS sqsExtended = spy(new AmazonSQSExtendedClient(mock(AmazonSQSClient.class), extendedClientConfiguration)); @@ -142,22 +227,48 @@ public void testWhenSendMessageWithSetMessageSizeThresholdThenThresholdIsHonored @Test public void testReceiveMessageMultipleTimesDoesNotAdditionallyAlterReceiveMessageRequest() { - ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration() - .withLargePayloadSupportEnabled(mockS3, S3_BUCKET_NAME); - AmazonSQS sqsExtended = spy(new AmazonSQSExtendedClient(mockSqsBackend, extendedClientConfiguration)); when(mockSqsBackend.receiveMessage(isA(ReceiveMessageRequest.class))).thenReturn(new ReceiveMessageResult()); ReceiveMessageRequest messageRequest = new ReceiveMessageRequest(); + ReceiveMessageRequest expectedRequest = new ReceiveMessageRequest() - .withMessageAttributeNames(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME); + .withMessageAttributeNames(AmazonSQSExtendedClient.RESERVED_ATTRIBUTE_NAMES); - sqsExtended.receiveMessage(messageRequest); + extendedSqsWithDefaultConfig.receiveMessage(messageRequest); Assert.assertEquals(expectedRequest, messageRequest); - sqsExtended.receiveMessage(messageRequest); + extendedSqsWithDefaultConfig.receiveMessage(messageRequest); Assert.assertEquals(expectedRequest, messageRequest); } + @Test + public void testReceiveMessage_when_MessageIsLarge_legacyReservedAttributeUsed() throws Exception { + testReceiveMessage_when_MessageIsLarge(AmazonSQSExtendedClient.LEGACY_RESERVED_ATTRIBUTE_NAME); + } + + @Test + public void testReceiveMessage_when_MessageIsLarge_ReservedAttributeUsed() throws Exception { + testReceiveMessage_when_MessageIsLarge(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME); + } + + @Test + public void testReceiveMessage_when_MessageIsSmall() throws Exception { + String expectedMessageAttributeName = "AnyMessageAttribute"; + String expectedMessage = "SmallMessage"; + Message message = new Message().addMessageAttributesEntry(expectedMessageAttributeName, mock(MessageAttributeValue.class)); + message.setBody(expectedMessage); + when(mockSqsBackend.receiveMessage(isA(ReceiveMessageRequest.class))).thenReturn(new ReceiveMessageResult().withMessages(message)); + + ReceiveMessageRequest messageRequest = new ReceiveMessageRequest(); + ReceiveMessageResult actualReceiveMessageResult = extendedSqsWithDefaultConfig.receiveMessage(messageRequest); + Message actualMessage = actualReceiveMessageResult.getMessages().get(0); + + Assert.assertEquals(expectedMessage, actualMessage.getBody()); + Assert.assertTrue(actualMessage.getMessageAttributes().keySet().contains(expectedMessageAttributeName)); + Assert.assertFalse(actualMessage.getMessageAttributes().keySet().containsAll(AmazonSQSExtendedClient.RESERVED_ATTRIBUTE_NAMES)); + verifyZeroInteractions(mockS3); + } + @Test public void testWhenMessageBatchIsSentThenOnlyMessagesLargerThanThresholdAreStoredInS3() { // This creates 10 messages, out of which only two are below the threshold (100K and 200K), @@ -189,7 +300,7 @@ public void testWhenMessageBatchIsSentThenOnlyMessagesLargerThanThresholdAreStor SendMessageBatchRequest batchRequest = new SendMessageBatchRequest(SQS_QUEUE_URL, batchEntries); extendedSqsWithDefaultConfig.sendMessageBatch(batchRequest); - // There should be 8 puts for the 8 messages above the threshhold + // There should be 8 puts for the 8 messages above the threshold verify(mockS3, times(8)).putObject(isA(PutObjectRequest.class)); } @@ -209,7 +320,7 @@ public void testWhenSmallMessageIsSentThenNoAttributeIsAdded() { } @Test - public void testWhenLargeMessgaeIsSentThenAttributeWithPayloadSizeIsAdded() { + public void testWhenLargeMessageIsSentThenAttributeWithPayloadSizeIsAdded() { int messageLength = MORE_THAN_SQS_SIZE_LIMIT; String messageBody = generateStringWithLength(messageLength); @@ -220,8 +331,133 @@ public void testWhenLargeMessgaeIsSentThenAttributeWithPayloadSizeIsAdded() { verify(mockSqsBackend).sendMessage(sendMessageRequestCaptor.capture()); Map attributes = sendMessageRequestCaptor.getValue().getMessageAttributes(); - Assert.assertEquals("Number", attributes.get(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME).getDataType()); - Assert.assertEquals(messageLength, (int)Integer.valueOf(attributes.get(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME).getStringValue())); + Assert.assertEquals("Number", attributes.get(AmazonSQSExtendedClient.LEGACY_RESERVED_ATTRIBUTE_NAME).getDataType()); + Assert.assertEquals(messageLength, (int) Integer.valueOf(attributes.get(AmazonSQSExtendedClient.LEGACY_RESERVED_ATTRIBUTE_NAME).getStringValue())); + } + + @Test + public void testDefaultExtendedClientDeletesSmallMessage() { + // given + String receiptHandle = UUID.randomUUID().toString(); + DeleteMessageRequest deleteRequest = new DeleteMessageRequest(SQS_QUEUE_URL, receiptHandle); + + // when + extendedSqsWithDefaultConfig.deleteMessage(deleteRequest); + + // then + ArgumentCaptor deleteRequestCaptor = ArgumentCaptor.forClass(DeleteMessageRequest.class); + verify(mockSqsBackend).deleteMessage(deleteRequestCaptor.capture()); + Assert.assertEquals(receiptHandle, deleteRequestCaptor.getValue().getReceiptHandle()); + verifyZeroInteractions(mockS3); + } + + @Test + public void testDefaultExtendedClientDeletesObjectS3UponMessageDelete() { + // given + String randomS3Key = UUID.randomUUID().toString(); + String originalReceiptHandle = UUID.randomUUID().toString(); + String largeMessageReceiptHandle = getLargeReceiptHandle(randomS3Key, originalReceiptHandle); + DeleteMessageRequest deleteRequest = new DeleteMessageRequest(SQS_QUEUE_URL, largeMessageReceiptHandle); + + // when + extendedSqsWithDefaultConfig.deleteMessage(deleteRequest); + + // then + ArgumentCaptor deleteRequestCaptor = ArgumentCaptor.forClass(DeleteMessageRequest.class); + verify(mockSqsBackend).deleteMessage(deleteRequestCaptor.capture()); + Assert.assertEquals(originalReceiptHandle, deleteRequestCaptor.getValue().getReceiptHandle()); + verify(mockS3).deleteObject(eq(S3_BUCKET_NAME), eq(randomS3Key)); + } + + @Test + public void testExtendedClientConfiguredDoesNotDeleteObjectFromS3UponDelete() { + // given + String randomS3Key = UUID.randomUUID().toString(); + String originalReceiptHandle = UUID.randomUUID().toString(); + String largeMessageReceiptHandle = getLargeReceiptHandle(randomS3Key, originalReceiptHandle); + DeleteMessageRequest deleteRequest = new DeleteMessageRequest(SQS_QUEUE_URL, largeMessageReceiptHandle); + + ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration() + .withPayloadSupportEnabled(mockS3, S3_BUCKET_NAME, false); + + AmazonSQS extendedSqs = spy(new AmazonSQSExtendedClient(mockSqsBackend, extendedClientConfiguration)); + + // when + extendedSqs.deleteMessage(deleteRequest); + + // then + ArgumentCaptor deleteRequestCaptor = ArgumentCaptor.forClass(DeleteMessageRequest.class); + verify(mockSqsBackend).deleteMessage(deleteRequestCaptor.capture()); + Assert.assertEquals(originalReceiptHandle, deleteRequestCaptor.getValue().getReceiptHandle()); + verifyZeroInteractions(mockS3); + } + + @Test + public void testExtendedClientConfiguredDoesNotDeletesObjectsFromS3UponDeleteBatch() { + // given + int batchSize = 10; + DeleteMessageBatchRequest deleteBatchRequest = generateLargeDeleteBatchRequest(batchSize); + ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration() + .withPayloadSupportEnabled(mockS3, S3_BUCKET_NAME, false); + AmazonSQS extendedSqs = spy(new AmazonSQSExtendedClient(mockSqsBackend, extendedClientConfiguration)); + + // when + extendedSqs.deleteMessageBatch(deleteBatchRequest); + + // then + verify(mockSqsBackend, times(1)).deleteMessageBatch(any(DeleteMessageBatchRequest.class)); + verifyZeroInteractions(mockS3); + } + + @Test + public void testDefaultExtendedClientDeletesObjectsFromS3UponDeleteBatch() { + // given + int batchSize = 10; + DeleteMessageBatchRequest deleteBatchRequest = generateLargeDeleteBatchRequest(batchSize); + + // when + extendedSqsWithDefaultConfig.deleteMessageBatch(deleteBatchRequest); + + // then + verify(mockSqsBackend, times(1)).deleteMessageBatch(any(DeleteMessageBatchRequest.class)); + verify(mockS3, times(batchSize)).deleteObject(eq(S3_BUCKET_NAME), anyString()); + } + + private void testReceiveMessage_when_MessageIsLarge(String reservedAttributeName) throws Exception { + Message message = new Message().addMessageAttributesEntry(reservedAttributeName, mock(MessageAttributeValue.class)); + String pointer = new PayloadS3Pointer(S3_BUCKET_NAME, "S3Key").toJson(); + message.setBody(pointer); + String expectedMessage = "LargeMessage"; + S3Object s3Object = new S3Object(); + s3Object.setObjectContent(new StringInputStream(expectedMessage)); + when(mockSqsBackend.receiveMessage(isA(ReceiveMessageRequest.class))).thenReturn(new ReceiveMessageResult().withMessages(message)); + when(mockS3.getObject(isA(GetObjectRequest.class))).thenReturn(s3Object); + + ReceiveMessageRequest messageRequest = new ReceiveMessageRequest(); + ReceiveMessageResult actualReceiveMessageResult = extendedSqsWithDefaultConfig.receiveMessage(messageRequest); + Message actualMessage = actualReceiveMessageResult.getMessages().get(0); + + Assert.assertEquals(expectedMessage, actualMessage.getBody()); + Assert.assertFalse(actualMessage.getMessageAttributes().keySet().containsAll(AmazonSQSExtendedClient.RESERVED_ATTRIBUTE_NAMES)); + verify(mockS3, times(1)).getObject(isA(GetObjectRequest.class)); + } + + private DeleteMessageBatchRequest generateLargeDeleteBatchRequest(int size) { + List deleteEntries = IntStream.range(0, size) + .mapToObj(i -> new DeleteMessageBatchRequestEntry(Integer.toString(i), getSampleLargeReceiptHandle())) + .collect(Collectors.toList()); + + return new DeleteMessageBatchRequest(SQS_QUEUE_URL, deleteEntries); + } + + private String getLargeReceiptHandle(String s3Key, String originalReceiptHandle) { + return SQSExtendedClientConstants.S3_BUCKET_NAME_MARKER + S3_BUCKET_NAME + + SQSExtendedClientConstants.S3_BUCKET_NAME_MARKER + SQSExtendedClientConstants.S3_KEY_MARKER + + s3Key + SQSExtendedClientConstants.S3_KEY_MARKER + originalReceiptHandle; + } + + private String getSampleLargeReceiptHandle() { + return getLargeReceiptHandle(UUID.randomUUID().toString(), UUID.randomUUID().toString()); } private String generateStringWithLength(int messageLength) { diff --git a/src/test/java/com/amazon/sqs/javamessaging/ExtendedClientConfigurationTest.java b/src/test/java/com/amazon/sqs/javamessaging/ExtendedClientConfigurationTest.java index 9949853..0bd5c79 100644 --- a/src/test/java/com/amazon/sqs/javamessaging/ExtendedClientConfigurationTest.java +++ b/src/test/java/com/amazon/sqs/javamessaging/ExtendedClientConfigurationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2010-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -16,11 +16,11 @@ package com.amazon.sqs.javamessaging; import com.amazonaws.services.s3.AmazonS3; -import com.amazonaws.services.s3.model.PutObjectRequest; -import junit.framework.Assert; +import com.amazonaws.services.s3.model.SSEAwsKeyManagementParams; + +import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import static org.mockito.Matchers.isA; import static org.mockito.Mockito.*; /** @@ -29,92 +29,74 @@ public class ExtendedClientConfigurationTest { private static String s3BucketName = "test-bucket-name"; + private static String s3ServerSideEncryptionKMSKeyId = "test-customer-managed-kms-key-id"; @Before public void setup() { - } @Test public void testCopyConstructor() { - AmazonS3 s3 = mock(AmazonS3.class); - when(s3.putObject(isA(PutObjectRequest.class))).thenReturn(null); boolean alwaysThroughS3 = true; int messageSizeThreshold = 500; + boolean doesCleanupS3Payload = false; ExtendedClientConfiguration extendedClientConfig = new ExtendedClientConfiguration(); - extendedClientConfig.withLargePayloadSupportEnabled(s3, s3BucketName) - .withAlwaysThroughS3(alwaysThroughS3).withMessageSizeThreshold(messageSizeThreshold); + extendedClientConfig.withPayloadSupportEnabled(s3, s3BucketName, doesCleanupS3Payload) + .withAlwaysThroughS3(alwaysThroughS3).withPayloadSizeThreshold(messageSizeThreshold) + .withSSEAwsKeyManagementParams(new SSEAwsKeyManagementParams(s3ServerSideEncryptionKMSKeyId)); ExtendedClientConfiguration newExtendedClientConfig = new ExtendedClientConfiguration(extendedClientConfig); Assert.assertEquals(s3, newExtendedClientConfig.getAmazonS3Client()); Assert.assertEquals(s3BucketName, newExtendedClientConfig.getS3BucketName()); - Assert.assertTrue(newExtendedClientConfig.isLargePayloadSupportEnabled()); + Assert.assertEquals(s3ServerSideEncryptionKMSKeyId, newExtendedClientConfig.getSSEAwsKeyManagementParams().getAwsKmsKeyId()); + Assert.assertTrue(newExtendedClientConfig.isPayloadSupportEnabled()); + Assert.assertEquals(doesCleanupS3Payload, newExtendedClientConfig.doesCleanupS3Payload()); Assert.assertEquals(alwaysThroughS3, newExtendedClientConfig.isAlwaysThroughS3()); - Assert.assertEquals(messageSizeThreshold, newExtendedClientConfig.getMessageSizeThreshold()); + Assert.assertEquals(messageSizeThreshold, newExtendedClientConfig.getPayloadSizeThreshold()); Assert.assertNotSame(newExtendedClientConfig, extendedClientConfig); } @Test - public void testLargePayloadSupportEnabled() { - + public void testLargePayloadSupportEnabledWithDefaultDeleteFromS3Config() { AmazonS3 s3 = mock(AmazonS3.class); - when(s3.putObject(isA(PutObjectRequest.class))).thenReturn(null); - ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration(); - extendedClientConfiguration.setLargePayloadSupportEnabled(s3, s3BucketName); + extendedClientConfiguration.setPayloadSupportEnabled(s3, s3BucketName); - Assert.assertTrue(extendedClientConfiguration.isLargePayloadSupportEnabled()); + Assert.assertTrue(extendedClientConfiguration.isPayloadSupportEnabled()); + Assert.assertTrue(extendedClientConfiguration.doesCleanupS3Payload()); Assert.assertNotNull(extendedClientConfiguration.getAmazonS3Client()); Assert.assertEquals(s3BucketName, extendedClientConfiguration.getS3BucketName()); } @Test - public void testDisableLargePayloadSupport() { + public void testLargePayloadSupportEnabledWithDeleteFromS3Enabled() { AmazonS3 s3 = mock(AmazonS3.class); - when(s3.putObject(isA(PutObjectRequest.class))).thenReturn(null); - - ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration(); - extendedClientConfiguration.setLargePayloadSupportDisabled(); - - Assert.assertNull(extendedClientConfiguration.getAmazonS3Client()); - Assert.assertNull(extendedClientConfiguration.getS3BucketName()); - - verify(s3, never()).putObject(isA(PutObjectRequest.class)); - } - - @Test - public void testAlwaysThroughS3() { - ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration(); + extendedClientConfiguration.setPayloadSupportEnabled(s3, s3BucketName, true); - extendedClientConfiguration.setAlwaysThroughS3(true); - Assert.assertTrue(extendedClientConfiguration.isAlwaysThroughS3()); - - extendedClientConfiguration.setAlwaysThroughS3(false); - Assert.assertFalse(extendedClientConfiguration.isAlwaysThroughS3()); + Assert.assertTrue(extendedClientConfiguration.isPayloadSupportEnabled()); + Assert.assertTrue(extendedClientConfiguration.doesCleanupS3Payload()); + Assert.assertNotNull(extendedClientConfiguration.getAmazonS3Client()); + Assert.assertEquals(s3BucketName, extendedClientConfiguration.getS3BucketName()); } @Test - public void testMessageSizeThreshold() { - + public void testLargePayloadSupportEnabledWithDeleteFromS3Disabled() { + AmazonS3 s3 = mock(AmazonS3.class); ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration(); + extendedClientConfiguration.setPayloadSupportEnabled(s3, s3BucketName, false); - Assert.assertEquals(SQSExtendedClientConstants.DEFAULT_MESSAGE_SIZE_THRESHOLD, - extendedClientConfiguration.getMessageSizeThreshold()); - - int messageLength = 1000; - extendedClientConfiguration.setMessageSizeThreshold(messageLength); - Assert.assertEquals(messageLength, extendedClientConfiguration.getMessageSizeThreshold()); - + Assert.assertTrue(extendedClientConfiguration.isPayloadSupportEnabled()); + Assert.assertFalse(extendedClientConfiguration.doesCleanupS3Payload()); + Assert.assertNotNull(extendedClientConfiguration.getAmazonS3Client()); + Assert.assertEquals(s3BucketName, extendedClientConfiguration.getS3BucketName()); } - - }