diff --git a/.gitignore b/.gitignore index 07827cc..1cdb3d4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ target/ -.idea/ \ No newline at end of file +.idea/ +*.iml \ No newline at end of file diff --git a/pom.xml b/pom.xml index 965b151..6ca2225 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.amazonaws amazon-sqs-java-extended-client-lib - 1.2.2 + 2.0.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. @@ -37,25 +37,32 @@ - 1.11.300 + 2.14.19 - com.amazonaws - aws-java-sdk-sqs + software.amazon.awssdk + sqs ${aws-java-sdk.version} - com.amazonaws - aws-java-sdk-s3 + software.amazon.awssdk + s3 ${aws-java-sdk.version} software.amazon.payloadoffloading payloadoffloading-common - 1.1.0 + 2.1.2 + + + + + commons-logging + commons-logging + 1.2 @@ -67,7 +74,7 @@ org.mockito mockito-core - 1.10.19 + 3.12.4 test diff --git a/src/main/java/com/amazon/sqs/javamessaging/AmazonSQSExtendedClient.java b/src/main/java/com/amazon/sqs/javamessaging/AmazonSQSExtendedClient.java index 452fa8a..e8f4d7d 100644 --- a/src/main/java/com/amazon/sqs/javamessaging/AmazonSQSExtendedClient.java +++ b/src/main/java/com/amazon/sqs/javamessaging/AmazonSQSExtendedClient.java @@ -15,48 +15,66 @@ package com.amazon.sqs.javamessaging; -import java.nio.ByteBuffer; -import java.util.*; -import java.util.Map.Entry; - -import com.amazonaws.AmazonClientException; -import com.amazonaws.AmazonServiceException; -import com.amazonaws.services.sqs.AmazonSQS; -import com.amazonaws.services.sqs.model.BatchEntryIdsNotDistinctException; -import com.amazonaws.services.sqs.model.BatchRequestTooLongException; -import com.amazonaws.services.sqs.model.ChangeMessageVisibilityBatchRequest; -import com.amazonaws.services.sqs.model.ChangeMessageVisibilityBatchRequestEntry; -import com.amazonaws.services.sqs.model.ChangeMessageVisibilityBatchResult; -import com.amazonaws.services.sqs.model.ChangeMessageVisibilityRequest; -import com.amazonaws.services.sqs.model.ChangeMessageVisibilityResult; -import com.amazonaws.services.sqs.model.DeleteMessageBatchRequest; -import com.amazonaws.services.sqs.model.DeleteMessageBatchRequestEntry; -import com.amazonaws.services.sqs.model.DeleteMessageBatchResult; -import com.amazonaws.services.sqs.model.DeleteMessageRequest; -import com.amazonaws.services.sqs.model.DeleteMessageResult; -import com.amazonaws.services.sqs.model.EmptyBatchRequestException; -import com.amazonaws.services.sqs.model.InvalidBatchEntryIdException; -import com.amazonaws.services.sqs.model.InvalidIdFormatException; -import com.amazonaws.services.sqs.model.InvalidMessageContentsException; -import com.amazonaws.services.sqs.model.Message; -import com.amazonaws.services.sqs.model.MessageAttributeValue; -import com.amazonaws.services.sqs.model.MessageNotInflightException; -import com.amazonaws.services.sqs.model.OverLimitException; -import com.amazonaws.services.sqs.model.PurgeQueueRequest; -import com.amazonaws.services.sqs.model.PurgeQueueResult; -import com.amazonaws.services.sqs.model.ReceiptHandleIsInvalidException; -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.SendMessageBatchResult; -import com.amazonaws.services.sqs.model.SendMessageRequest; -import com.amazonaws.services.sqs.model.SendMessageResult; -import com.amazonaws.services.sqs.model.TooManyEntriesInBatchRequestException; +import java.lang.UnsupportedOperationException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import software.amazon.payloadoffloading.*; +import software.amazon.awssdk.awscore.AwsRequest; +import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration; +import software.amazon.awssdk.awscore.exception.AwsServiceException; +import software.amazon.awssdk.core.ApiName; +import software.amazon.awssdk.core.SdkBytes; +import software.amazon.awssdk.core.exception.SdkClientException; +import software.amazon.awssdk.core.exception.SdkException; +import software.amazon.awssdk.core.util.VersionInfo; +import software.amazon.awssdk.services.sqs.SqsClient; + +import software.amazon.awssdk.services.sqs.model.BatchEntryIdsNotDistinctException; +import software.amazon.awssdk.services.sqs.model.BatchRequestTooLongException; +import software.amazon.awssdk.services.sqs.model.ChangeMessageVisibilityBatchRequest; +import software.amazon.awssdk.services.sqs.model.ChangeMessageVisibilityBatchRequestEntry; +import software.amazon.awssdk.services.sqs.model.ChangeMessageVisibilityBatchResponse; +import software.amazon.awssdk.services.sqs.model.ChangeMessageVisibilityRequest; +import software.amazon.awssdk.services.sqs.model.ChangeMessageVisibilityResponse; +import software.amazon.awssdk.services.sqs.model.DeleteMessageBatchRequest; +import software.amazon.awssdk.services.sqs.model.DeleteMessageBatchRequestEntry; +import software.amazon.awssdk.services.sqs.model.DeleteMessageBatchResponse; +import software.amazon.awssdk.services.sqs.model.DeleteMessageRequest; +import software.amazon.awssdk.services.sqs.model.DeleteMessageResponse; +import software.amazon.awssdk.services.sqs.model.EmptyBatchRequestException; +import software.amazon.awssdk.services.sqs.model.InvalidBatchEntryIdException; +import software.amazon.awssdk.services.sqs.model.InvalidIdFormatException; +import software.amazon.awssdk.services.sqs.model.InvalidMessageContentsException; +import software.amazon.awssdk.services.sqs.model.Message; +import software.amazon.awssdk.services.sqs.model.MessageAttributeValue; +import software.amazon.awssdk.services.sqs.model.MessageNotInflightException; +import software.amazon.awssdk.services.sqs.model.OverLimitException; +import software.amazon.awssdk.services.sqs.model.PurgeQueueInProgressException; +import software.amazon.awssdk.services.sqs.model.PurgeQueueRequest; +import software.amazon.awssdk.services.sqs.model.PurgeQueueResponse; +import software.amazon.awssdk.services.sqs.model.QueueDoesNotExistException; +import software.amazon.awssdk.services.sqs.model.ReceiptHandleIsInvalidException; +import software.amazon.awssdk.services.sqs.model.ReceiveMessageRequest; +import software.amazon.awssdk.services.sqs.model.ReceiveMessageResponse; +import software.amazon.awssdk.services.sqs.model.SendMessageBatchRequest; +import software.amazon.awssdk.services.sqs.model.SendMessageBatchRequestEntry; +import software.amazon.awssdk.services.sqs.model.SendMessageBatchResponse; +import software.amazon.awssdk.services.sqs.model.SendMessageRequest; +import software.amazon.awssdk.services.sqs.model.SendMessageResponse; +import software.amazon.awssdk.services.sqs.model.SqsException; +import software.amazon.awssdk.services.sqs.model.TooManyEntriesInBatchRequestException; +import software.amazon.awssdk.utils.StringUtils; +import software.amazon.payloadoffloading.PayloadS3Pointer; +import software.amazon.payloadoffloading.PayloadStore; +import software.amazon.payloadoffloading.S3BackedPayloadStore; +import software.amazon.payloadoffloading.S3Dao; +import software.amazon.payloadoffloading.Util; /** @@ -78,9 +96,11 @@ *
  • Delete the corresponding message object from an Amazon S3 bucket.
  • * */ -public class AmazonSQSExtendedClient extends AmazonSQSExtendedClientBase implements AmazonSQS { +public class AmazonSQSExtendedClient extends AmazonSQSExtendedClientBase implements SqsClient { + static final String USER_AGENT_NAME = AmazonSQSExtendedClient.class.getSimpleName(); + static final String USER_AGENT_VERSION = VersionInfo.SDK_VERSION; + 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); @@ -99,7 +119,7 @@ public class AmazonSQSExtendedClient extends AmazonSQSExtendedClientBase impleme * @param sqsClient * The Amazon SQS client to use to connect to Amazon SQS. */ - public AmazonSQSExtendedClient(AmazonSQS sqsClient) { + public AmazonSQSExtendedClient(SqsClient sqsClient) { this(sqsClient, new ExtendedClientConfiguration()); } @@ -118,71 +138,73 @@ public AmazonSQSExtendedClient(AmazonSQS sqsClient) { * The extended client configuration options controlling the * functionality of this client. */ - public AmazonSQSExtendedClient(AmazonSQS sqsClient, ExtendedClientConfiguration extendedClientConfig) { + public AmazonSQSExtendedClient(SqsClient sqsClient, ExtendedClientConfiguration extendedClientConfig) { super(sqsClient); this.clientConfiguration = new ExtendedClientConfiguration(extendedClientConfig); - S3Dao s3Dao = new S3Dao(clientConfiguration.getAmazonS3Client(), - clientConfiguration.getSSEAwsKeyManagementParams(), - clientConfiguration.getCannedAccessControlList()); + S3Dao s3Dao = new S3Dao(clientConfiguration.getS3Client(), + clientConfiguration.getServerSideEncryptionStrategy(), + clientConfiguration.getObjectCannedACL()); this.payloadStore = new S3BackedPayloadStore(s3Dao, clientConfiguration.getS3BucketName()); } /** *

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

    + * *

    - * 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] + * A message can include only XML, JSON, and unformatted text. The following Unicode characters are allowed: *

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

    + *

    + * #x9 | #xA | #xD | #x20 to #xD7FF | + * #xE000 to #xFFFD | #x10000 to #x10FFFF + *

    + *

    + * Any characters not included in this list will be rejected. For more information, see the W3C specification for characters. + *

    + *
    * * @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. - * + * @return Result of the SendMessage operation returned by the service. * @throws InvalidMessageContentsException + * The message contains characters outside the allowed set. * @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. + * Error code 400. Unsupported operation. + * @throws SdkException + * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for + * catch all scenarios. + * @throws SdkClientException + * If any client side error occurs such as an IO related failure, failure to get credentials, etc. + * @throws SqsException + * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. + * @sample SqsClient.SendMessage + * @see AWS API + * Documentation */ - public SendMessageResult sendMessage(SendMessageRequest sendMessageRequest) { + public SendMessageResponse 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); + throw SdkClientException.create(errorMessage); } - sendMessageRequest.getRequestClientOptions().appendUserAgent(USER_AGENT_HEADER); + SendMessageRequest.Builder sendMessageRequestBuilder = sendMessageRequest.toBuilder(); + sendMessageRequest = appendUserAgent(sendMessageRequestBuilder).build(); if (!clientConfiguration.isPayloadSupportEnabled()) { return super.sendMessage(sendMessageRequest); } - if (sendMessageRequest.getMessageBody() == null || "".equals(sendMessageRequest.getMessageBody())) { + if (StringUtils.isEmpty(sendMessageRequest.messageBody())) { String errorMessage = "messageBody cannot be null or empty."; LOG.error(errorMessage); - throw new AmazonClientException(errorMessage); + throw SdkClientException.create(errorMessage); } //Check message attributes for ExtendedClient related constraints - checkMessageAttributes(sendMessageRequest.getMessageAttributes()); + checkMessageAttributes(sendMessageRequest.messageAttributes()); if (clientConfiguration.isAlwaysThroughS3() || isLarge(sendMessageRequest)) { sendMessageRequest = storeMessageInS3(sendMessageRequest); @@ -192,372 +214,211 @@ public SendMessageResult sendMessage(SendMessageRequest 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 . + * Retrieves one or more messages (up to 10), from the specified queue. Using the WaitTimeSeconds + * parameter enables long-poll support. For more information, see Amazon + * SQS Long Polling in the Amazon Simple Queue Service 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. + * Short poll is the default behavior where a weighted random set of machines is sampled on a + * ReceiveMessage call. Thus, only the messages on the sampled machines are returned. If the number of + * messages in the queue is small (fewer than 1,000), you most likely 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. If this happens, 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 . + * The receipt handle is the identifier you must provide when deleting the message. For more information, see Queue and Message Identifiers in the Amazon Simple Queue Service 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 . + * You can provide the VisibilityTimeout parameter in your request. The parameter is applied to the + * messages that Amazon SQS returns in the response. If you don't 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 Simple Queue Service 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. + * A message that isn't deleted or a message whose visibility isn't extended before the visibility timeout expires + * counts as a failed receive. Depending on the configuration of the queue, the message might be sent to the + * dead-letter queue. *

    + * + *

    + * In the future, new attributes might be added. If you write 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. - * + * @return Result of the ReceiveMessage operation returned by the service. * @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. + * The specified action violates a limit. For example, ReceiveMessage returns this error if the + * maximum number of inflight messages is reached and AddPermission returns this error if the + * maximum number of permissions for the queue is reached. + * @throws SdkException + * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for + * catch all scenarios. + * @throws SdkClientException + * If any client side error occurs such as an IO related failure, failure to get credentials, etc. + * @throws SqsException + * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. + * @sample SqsClient.ReceiveMessage + * @see AWS API + * Documentation */ - public ReceiveMessageResult receiveMessage(ReceiveMessageRequest receiveMessageRequest) { + public ReceiveMessageResponse 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); + throw SdkClientException.create(errorMessage); } - receiveMessageRequest.getRequestClientOptions().appendUserAgent(USER_AGENT_HEADER); + ReceiveMessageRequest.Builder receiveMessageRequestBuilder = receiveMessageRequest.toBuilder(); + appendUserAgent(receiveMessageRequestBuilder); if (!clientConfiguration.isPayloadSupportEnabled()) { - return super.receiveMessage(receiveMessageRequest); + return super.receiveMessage(receiveMessageRequestBuilder.build()); } //Remove before adding to avoid any duplicates - receiveMessageRequest.getMessageAttributeNames().removeAll(RESERVED_ATTRIBUTE_NAMES); - receiveMessageRequest.getMessageAttributeNames().addAll(RESERVED_ATTRIBUTE_NAMES); + List messageAttributeNames = new ArrayList<>(receiveMessageRequest.messageAttributeNames()); + messageAttributeNames.removeAll(RESERVED_ATTRIBUTE_NAMES); + messageAttributeNames.addAll(RESERVED_ATTRIBUTE_NAMES); + receiveMessageRequestBuilder.attributeNamesWithStrings(messageAttributeNames); + receiveMessageRequest = receiveMessageRequestBuilder.build(); - ReceiveMessageResult receiveMessageResult = super.receiveMessage(receiveMessageRequest); + ReceiveMessageResponse receiveMessageResponse = super.receiveMessage(receiveMessageRequest); + ReceiveMessageResponse.Builder receiveMessageResponseBuilder = receiveMessageResponse.toBuilder(); - List messages = receiveMessageResult.getMessages(); - List messagesToIgnore = new ArrayList<>(); + List messages = receiveMessageResponse.messages(); + List modifiedMessages = new ArrayList<>(messages.size()); for (Message message : messages) { + Message.Builder messageBuilder = message.toBuilder(); // for each received message check if they are stored in S3. - Optional largePayloadAttributeName = getReservedAttributeNameIfPresent(message.getMessageAttributes()); + Optional largePayloadAttributeName = getReservedAttributeNameIfPresent(message.messageAttributes()); if (largePayloadAttributeName.isPresent()) { - String largeMessagePointer = message.getBody(); + String largeMessagePointer = message.body(); largeMessagePointer = largeMessagePointer.replace("com.amazon.sqs.javamessaging.MessageS3Pointer", "software.amazon.payloadoffloading.PayloadS3Pointer"); - final String originalBody; - try { - originalBody = payloadStore.getOriginalPayload(largeMessagePointer); - } catch (AmazonServiceException e) { - boolean isNoSuchKeyException = ((AmazonServiceException) e.getCause()).getErrorCode().equals("NoSuchKey"); - if (isNoSuchKeyException && clientConfiguration.ignoresPayloadNotFound()) { - deleteMessage(receiveMessageRequest.getQueueUrl(), message.getReceiptHandle()); - LOG.warn("SQS message deleted as it could not be found in S3"); - messagesToIgnore.add(message); - continue; - } - throw e; - } - - // Replace the large message pointer with the original message body - message.setBody(originalBody); + messageBuilder.body(payloadStore.getOriginalPayload(largeMessagePointer)); // remove the additional attribute before returning the message // to user. - message.getMessageAttributes().keySet().removeAll(RESERVED_ATTRIBUTE_NAMES); + Map messageAttributes = new HashMap<>(message.messageAttributes()); + messageAttributes.keySet().removeAll(RESERVED_ATTRIBUTE_NAMES); + messageBuilder.messageAttributes(messageAttributes); // Embed s3 object pointer in the receipt handle. String modifiedReceiptHandle = embedS3PointerInReceiptHandle( - message.getReceiptHandle(), + message.receiptHandle(), largeMessagePointer); - message.setReceiptHandle(modifiedReceiptHandle); + messageBuilder.receiptHandle(modifiedReceiptHandle); } + modifiedMessages.add(messageBuilder.build()); } - receiveMessageResult.getMessages().removeAll(messagesToIgnore); - 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); + receiveMessageResponseBuilder.messages(modifiedMessages); + return receiveMessageResponseBuilder.build(); } /** *

    - * 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. + * Deletes the specified message from the specified queue. To select the message to delete, use the + * ReceiptHandle of the message (not the MessageId which you receive when you send + * the message). Amazon SQS can delete a message from a queue even if a visibility timeout setting causes the + * message to be locked by another consumer. Amazon SQS automatically deletes messages left in a queue longer than + * the retention period configured for the queue. *

    + * *

    - * 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. + * The ReceiptHandle is associated with a specific instance of receiving a message. If you + * receive a message more than once, the ReceiptHandle is different each time you receive a message. + * When you use the DeleteMessage action, you must provide the most recently received + * ReceiptHandle for the message (otherwise, the request succeeds, 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. + * For standard queues, it is possible to receive a message even after you delete it. This might happen on rare + * occasions if one of the servers which stores a copy of the message is unavailable when you send the request to + * delete the message. The copy remains on the server and might be returned to you during a subsequent receive + * request. You should ensure that your application is idempotent, so that receiving a message more than once does + * not cause issues. *

    + *
    * * @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 + * @return Result of the DeleteMessage operation returned by the service. * @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. + * The specified receipt handle isn't valid for the current version. + * @throws ReceiptHandleIsInvalidException + * The specified receipt handle isn't valid. + * @throws SdkException + * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for + * catch all scenarios. + * @throws SdkClientException + * If any client side error occurs such as an IO related failure, failure to get credentials, etc. + * @throws SqsException + * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. + * @sample SqsClient.DeleteMessage + * @see AWS API + * Documentation */ - public DeleteMessageResult deleteMessage(DeleteMessageRequest deleteMessageRequest) { + public DeleteMessageResponse deleteMessage(DeleteMessageRequest deleteMessageRequest) { if (deleteMessageRequest == null) { String errorMessage = "deleteMessageRequest cannot be null."; LOG.error(errorMessage); - throw new AmazonClientException(errorMessage); + throw SdkClientException.create(errorMessage); } - deleteMessageRequest.getRequestClientOptions().appendUserAgent(USER_AGENT_HEADER); + DeleteMessageRequest.Builder deleteMessageRequestBuilder = deleteMessageRequest.toBuilder(); + appendUserAgent(deleteMessageRequestBuilder); if (!clientConfiguration.isPayloadSupportEnabled()) { - return super.deleteMessage(deleteMessageRequest); + return super.deleteMessage(deleteMessageRequestBuilder.build()); } - String receiptHandle = deleteMessageRequest.getReceiptHandle(); + String receiptHandle = deleteMessageRequest.receiptHandle(); String origReceiptHandle = receiptHandle; // Update original receipt handle if needed @@ -570,234 +431,200 @@ public DeleteMessageResult deleteMessage(DeleteMessageRequest deleteMessageReque } } - deleteMessageRequest.setReceiptHandle(origReceiptHandle); - return super.deleteMessage(deleteMessageRequest); + deleteMessageRequestBuilder.receiptHandle(origReceiptHandle); + return super.deleteMessage(deleteMessageRequestBuilder.build()); } /** *

    - * 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. + * Changes the visibility timeout of a specified message in a queue to a new value. The default visibility timeout + * for a message is 30 seconds. The minimum is 0 seconds. The maximum is 12 hours. For more information, see + * Visibility Timeout in the Amazon Simple Queue Service Developer Guide. *

    *

    - * 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. + * For example, you have a message with a visibility timeout of 5 minutes. After 3 minutes, you call + * ChangeMessageVisibility with a timeout of 10 minutes. You can continue to call + * ChangeMessageVisibility to extend the visibility timeout to the maximum allowed time. If you try to + * extend the visibility timeout beyond the maximum, your request is rejected. *

    *

    - * 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. + * An Amazon SQS message has three basic states: *

    - * - * @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); - } - - /** + *
      + *
    1. + *

      + * Sent to a queue by a producer. + *

      + *
    2. + *
    3. + *

      + * Received from the queue by a consumer. + *

      + *
    4. + *
    5. *

      - * 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 .) + * Deleted from the queue. + *

      + *
    6. + *
    + *

    + * A message is considered to be stored after it is sent to a queue by a producer, but not yet received from + * the queue by a consumer (that is, between states 1 and 2). There is no limit to the number of stored messages. A + * message is considered to be in flight after it is received from a queue by a consumer, but not yet deleted + * from the queue (that is, between states 2 and 3). There is a limit to the number of inflight messages. *

    *

    - * 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. + * Limits that apply to inflight messages are unrelated to the unlimited number of stored messages. *

    *

    - * 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. + * For most standard queues (depending on queue traffic and message backlog), there can be a maximum of + * approximately 120,000 inflight messages (received from a queue by a consumer, but not yet deleted from the + * queue). If you reach this limit, Amazon SQS returns the OverLimit error message. To avoid reaching + * the limit, you should delete messages from the queue after they're processed. You can also increase the number of + * queues you use to process your messages. To request a limit increase, file a support request. *

    *

    - * 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. + * For FIFO queues, there can be a maximum of 20,000 inflight messages (received from a queue by a consumer, but not + * yet deleted from the queue). If you reach this limit, Amazon SQS returns no error messages. *

    + * *

    - * 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. + * If you attempt to set the VisibilityTimeout to a value greater than the maximum time left, Amazon + * SQS returns an error. Amazon SQS doesn't automatically recalculate and increase the timeout to the maximum + * remaining time. *

    + *

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

    + *
    * * @param changeMessageVisibilityRequest - * Container for the necessary parameters to execute the - * ChangeMessageVisibility service method on AmazonSQS. - * - * - * @throws ReceiptHandleIsInvalidException + * @return Result of the ChangeMessageVisibility operation returned by the service. * @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. + * The specified message isn't in flight. + * @throws ReceiptHandleIsInvalidException + * The specified receipt handle isn't valid. + * @throws SdkException + * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for + * catch all scenarios. + * @throws SdkClientException + * If any client side error occurs such as an IO related failure, failure to get credentials, etc. + * @throws SqsException + * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. + * @sample SqsClient.ChangeMessageVisibility + * @see AWS + * API Documentation */ - public ChangeMessageVisibilityResult changeMessageVisibility(ChangeMessageVisibilityRequest changeMessageVisibilityRequest) - throws AmazonServiceException, AmazonClientException { + public ChangeMessageVisibilityResponse changeMessageVisibility(ChangeMessageVisibilityRequest changeMessageVisibilityRequest) + throws AwsServiceException, SdkClientException { - if (isS3ReceiptHandle(changeMessageVisibilityRequest.getReceiptHandle())) { - changeMessageVisibilityRequest.setReceiptHandle( - getOrigReceiptHandle(changeMessageVisibilityRequest.getReceiptHandle())); + ChangeMessageVisibilityRequest.Builder changeMessageVisibilityRequestBuilder = changeMessageVisibilityRequest.toBuilder(); + if (isS3ReceiptHandle(changeMessageVisibilityRequest.receiptHandle())) { + changeMessageVisibilityRequestBuilder.receiptHandle( + getOrigReceiptHandle(changeMessageVisibilityRequest.receiptHandle())); } - return amazonSqsToBeExtended.changeMessageVisibility(changeMessageVisibilityRequest); + return amazonSqsToBeExtended.changeMessageVisibility(changeMessageVisibilityRequestBuilder.build()); } /** *

    - * 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. + * Delivers up to ten messages to the specified queue. This is a batch version of SendMessage. + * For a FIFO queue, multiple messages within a single batch are enqueued in the order they are sent. + *

    + *

    + * The result of sending each message is reported individually in the response. 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. + *

    + *

    + * The maximum allowed individual message size and the maximum total payload size (the sum of the individual lengths + * of all of the batched messages) are both 256 KB (262,144 bytes). *

    + * *

    - * If the DelaySeconds parameter is not specified for an entry, - * the default for the queue is used. + * A message can include only XML, JSON, and unformatted text. The following Unicode characters are allowed: *

    *

    - * 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] + * #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. + * Any characters not included in this list will be rejected. For more information, see the W3C specification for characters. *

    - * 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: + * If you don't specify the DelaySeconds parameter for an entry, Amazon SQS uses the default value for + * the queue. *

    *

    - * &Attribute.1=this + * Some 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.2=that + * &AttributeName.1=first + *

    + *

    + * &AttributeName.2=second *

    * * @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 + * @return Result of the SendMessageBatch operation returned by the service. * @throws TooManyEntriesInBatchRequestException + * The batch request contains more entries than permissible. + * @throws EmptyBatchRequestException + * The batch request doesn't contain any entries. + * @throws BatchEntryIdsNotDistinctException + * Two or more batch entries in the request have the same Id. * @throws BatchRequestTooLongException - * @throws UnsupportedOperationException + * The length of all the messages put together is more than the limit. * @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. + * The Id of a batch entry in a batch request doesn't abide by the specification. + * @throws UnsupportedOperationException + * Error code 400. Unsupported operation. + * @throws SdkException + * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for + * catch all scenarios. + * @throws SdkClientException + * If any client side error occurs such as an IO related failure, failure to get credentials, etc. + * @throws SqsException + * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. + * @sample SqsClient.SendMessageBatch + * @see AWS API + * Documentation */ - public SendMessageBatchResult sendMessageBatch(SendMessageBatchRequest sendMessageBatchRequest) { + public SendMessageBatchResponse sendMessageBatch(SendMessageBatchRequest sendMessageBatchRequest) { if (sendMessageBatchRequest == null) { String errorMessage = "sendMessageBatchRequest cannot be null."; LOG.error(errorMessage); - throw new AmazonClientException(errorMessage); + throw SdkClientException.create(errorMessage); } - sendMessageBatchRequest.getRequestClientOptions().appendUserAgent(USER_AGENT_HEADER); + SendMessageBatchRequest.Builder sendMessageBatchRequestBuilder = sendMessageBatchRequest.toBuilder(); + appendUserAgent(sendMessageBatchRequestBuilder); + sendMessageBatchRequest = sendMessageBatchRequestBuilder.build(); if (!clientConfiguration.isPayloadSupportEnabled()) { return super.sendMessageBatch(sendMessageBatchRequest); } - List batchEntries = sendMessageBatchRequest.getEntries(); + List batchEntries = new ArrayList<>(sendMessageBatchRequest.entries().size()); - int index = 0; - for (SendMessageBatchRequestEntry entry : batchEntries) { + for (SendMessageBatchRequestEntry entry : sendMessageBatchRequest.entries()) { //Check message attributes for ExtendedClient related constraints - checkMessageAttributes(entry.getMessageAttributes()); + checkMessageAttributes(entry.messageAttributes()); if (clientConfiguration.isAlwaysThroughS3() || isLarge(entry)) { - batchEntries.set(index, storeMessageInS3(entry)); + entry = storeMessageInS3(entry); } - ++index; + batchEntries.add(entry); } return super.sendMessageBatch(sendMessageBatchRequest); @@ -805,130 +632,67 @@ public SendMessageBatchResult sendMessageBatch(SendMessageBatchRequest sendMessa /** *

    - * 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. + * Deletes up to ten messages from the specified queue. This is a batch version of + * DeleteMessage. The result of the action on each message is reported individually in the + * response. *

    + * *

    - * If the DelaySeconds parameter is not specified for an entry, - * the default for the queue is used. + * 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 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] + * Some 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: *

    *

    - * 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. + * &AttributeName.1=first *

    *

    - * 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: + * &AttributeName.2=second *

    - *

    - * &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 + * @param deleteMessageBatchRequest + * @return Result of the DeleteMessageBatch operation returned by the service. * @throws TooManyEntriesInBatchRequestException - * @throws BatchRequestTooLongException - * @throws UnsupportedOperationException - * @throws InvalidBatchEntryIdException + * The batch request contains more entries than permissible. * @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. - * + * The batch request doesn't contain any entries. * @throws BatchEntryIdsNotDistinctException - * @throws TooManyEntriesInBatchRequestException + * Two or more batch entries in the request have the same Id. * @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. + * The Id of a batch entry in a batch request doesn't abide by the specification. + * @throws SdkException + * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for + * catch all scenarios. + * @throws SdkClientException + * If any client side error occurs such as an IO related failure, failure to get credentials, etc. + * @throws SqsException + * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. + * @sample SqsClient.DeleteMessageBatch + * @see AWS API + * Documentation */ - public DeleteMessageBatchResult deleteMessageBatch(DeleteMessageBatchRequest deleteMessageBatchRequest) { + public DeleteMessageBatchResponse deleteMessageBatch(DeleteMessageBatchRequest deleteMessageBatchRequest) { if (deleteMessageBatchRequest == null) { String errorMessage = "deleteMessageBatchRequest cannot be null."; LOG.error(errorMessage); - throw new AmazonClientException(errorMessage); + throw SdkClientException.create(errorMessage); } - deleteMessageBatchRequest.getRequestClientOptions().appendUserAgent(USER_AGENT_HEADER); + DeleteMessageBatchRequest.Builder deleteMessageBatchRequestBuilder = deleteMessageBatchRequest.toBuilder(); + appendUserAgent(deleteMessageBatchRequestBuilder); if (!clientConfiguration.isPayloadSupportEnabled()) { return super.deleteMessageBatch(deleteMessageBatchRequest); } - for (DeleteMessageBatchRequestEntry entry : deleteMessageBatchRequest.getEntries()) { - String receiptHandle = entry.getReceiptHandle(); + List entries = new ArrayList<>(deleteMessageBatchRequest.entries().size()); + for (DeleteMessageBatchRequestEntry entry : deleteMessageBatchRequest.entries()) { + DeleteMessageBatchRequestEntry.Builder entryBuilder = entry.toBuilder(); + String receiptHandle = entry.receiptHandle(); String origReceiptHandle = receiptHandle; // Update original receipt handle if needed @@ -941,183 +705,130 @@ public DeleteMessageBatchResult deleteMessageBatch(DeleteMessageBatchRequest del } } - entry.setReceiptHandle(origReceiptHandle); + entryBuilder.receiptHandle(origReceiptHandle); + entries.add(entryBuilder.build()); } - 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); + deleteMessageBatchRequestBuilder.entries(entries); + return super.deleteMessageBatch(deleteMessageBatchRequestBuilder.build()); } /** *

    - * 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 + * 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. + * 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: + * Some 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 + * &AttributeName.1=first *

    *

    - * &Attribute.2=that + * &AttributeName.2=second *

    * * @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 + * @return Result of the ChangeMessageVisibilityBatch operation returned by the service. * @throws TooManyEntriesInBatchRequestException - * @throws InvalidBatchEntryIdException + * The batch request contains more entries than permissible. * @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. + * The batch request doesn't contain any entries. + * @throws BatchEntryIdsNotDistinctException + * Two or more batch entries in the request have the same Id. + * @throws InvalidBatchEntryIdException + * The Id of a batch entry in a batch request doesn't abide by the specification. + * @throws SdkException + * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for + * catch all scenarios. + * @throws SdkClientException + * If any client side error occurs such as an IO related failure, failure to get credentials, etc. + * @throws SqsException + * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. + * @sample SqsClient.ChangeMessageVisibilityBatch + * @see AWS API Documentation */ - public ChangeMessageVisibilityBatchResult changeMessageVisibilityBatch( - ChangeMessageVisibilityBatchRequest changeMessageVisibilityBatchRequest) throws AmazonServiceException, - AmazonClientException { - - for (ChangeMessageVisibilityBatchRequestEntry entry : changeMessageVisibilityBatchRequest.getEntries()) { - if (isS3ReceiptHandle(entry.getReceiptHandle())) { - entry.setReceiptHandle(getOrigReceiptHandle(entry.getReceiptHandle())); + public ChangeMessageVisibilityBatchResponse changeMessageVisibilityBatch( + ChangeMessageVisibilityBatchRequest changeMessageVisibilityBatchRequest) throws AwsServiceException, + SdkClientException { + + List entries = new ArrayList<>(changeMessageVisibilityBatchRequest.entries().size()); + for (ChangeMessageVisibilityBatchRequestEntry entry : changeMessageVisibilityBatchRequest.entries()) { + ChangeMessageVisibilityBatchRequestEntry.Builder entryBuilder = entry.toBuilder(); + if (isS3ReceiptHandle(entry.receiptHandle())) { + entryBuilder.receiptHandle(getOrigReceiptHandle(entry.receiptHandle())); } + entries.add(entryBuilder.build()); } - return amazonSqsToBeExtended.changeMessageVisibilityBatch(changeMessageVisibilityBatchRequest); + return amazonSqsToBeExtended.changeMessageVisibilityBatch( + changeMessageVisibilityBatchRequest.toBuilder().entries(entries).build()); } /** *

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

    + * + *

    + * When you use the PurgeQueue action, you can't retrieve any messages deleted from a queue. *

    *

    - * IMPORTANT:When you use the PurgeQueue API, the deleted messages in - * the queue cannot be retrieved. + * The message deletion process takes up to 60 seconds. We recommend waiting for 60 seconds regardless of your + * queue's size. *

    + *
    *

    - * IMPORTANT: This does not delete the message payloads from Amazon S3. + * Messages sent to the queue before you call PurgeQueue might be received but are deleted + * within the next minute. *

    *

    - * 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. + * Messages sent to the queue after you call PurgeQueue might be deleted while the queue is + * being purged. *

    * * @param purgeQueueRequest - * Container for the necessary parameters to execute the - * PurgeQueue service method on AmazonSQS. - * @return The response from the PurgeQueue 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. + * @return Result of the PurgeQueue operation returned by the service. + * @throws QueueDoesNotExistException + * The specified queue doesn't exist. + * @throws PurgeQueueInProgressException + * Indicates that the specified queue previously received a PurgeQueue request within the last + * 60 seconds (the time it can take to delete the messages in the queue). + * @throws SdkException + * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for + * catch all scenarios. + * @throws SdkClientException + * If any client side error occurs such as an IO related failure, failure to get credentials, etc. + * @throws SqsException + * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. + * @sample SqsClient.PurgeQueue + * @see AWS API + * Documentation */ - public PurgeQueueResult purgeQueue(PurgeQueueRequest purgeQueueRequest) - throws AmazonServiceException, AmazonClientException { + public PurgeQueueResponse purgeQueue(PurgeQueueRequest purgeQueueRequest) + throws AwsServiceException, SdkClientException { 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); + throw SdkClientException.create(errorMessage); } - purgeQueueRequest.getRequestClientOptions().appendUserAgent(USER_AGENT_HEADER); + PurgeQueueRequest.Builder purgeQueueRequestBuilder = purgeQueueRequest.toBuilder(); + appendUserAgent(purgeQueueRequestBuilder); - return super.purgeQueue(purgeQueueRequest); + return super.purgeQueue(purgeQueueRequestBuilder.build()); } private void checkMessageAttributes(Map messageAttributes) { @@ -1127,7 +838,7 @@ private void checkMessageAttributes(Map messageAt + " 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); + throw SdkClientException.create(errorMessage); } int messageAttributesNum = messageAttributes.size(); @@ -1136,7 +847,7 @@ private void checkMessageAttributes(Map messageAt + "] exceeds the maximum allowed for large-payload messages [" + SQSExtendedClientConstants.MAX_ALLOWED_ATTRIBUTES + "]."; LOG.error(errorMessage); - throw new AmazonClientException(errorMessage); + throw SdkClientException.create(errorMessage); } Optional largePayloadAttributeName = getReservedAttributeNameIfPresent(messageAttributes); @@ -1144,7 +855,7 @@ private void checkMessageAttributes(Map messageAt String errorMessage = "Message attribute name " + largePayloadAttributeName.get() + " is reserved for use by SQS extended client."; LOG.error(errorMessage); - throw new AmazonClientException(errorMessage); + throw SdkClientException.create(errorMessage); } } @@ -1189,15 +900,15 @@ private String getMessagePointerFromModifiedReceiptHandle(String receiptHandle) } private boolean isLarge(SendMessageRequest sendMessageRequest) { - int msgAttributesSize = getMsgAttributesSize(sendMessageRequest.getMessageAttributes()); - long msgBodySize = Util.getStringSizeInBytes(sendMessageRequest.getMessageBody()); + int msgAttributesSize = getMsgAttributesSize(sendMessageRequest.messageAttributes()); + long msgBodySize = Util.getStringSizeInBytes(sendMessageRequest.messageBody()); long totalMsgSize = msgAttributesSize + msgBodySize; return (totalMsgSize > clientConfiguration.getPayloadSizeThreshold()); } private boolean isLarge(SendMessageBatchRequestEntry batchEntry) { - int msgAttributesSize = getMsgAttributesSize(batchEntry.getMessageAttributes()); - long msgBodySize = Util.getStringSizeInBytes(batchEntry.getMessageBody()); + int msgAttributesSize = getMsgAttributesSize(batchEntry.messageAttributes()); + long msgBodySize = Util.getStringSizeInBytes(batchEntry.messageBody()); long totalMsgSize = msgAttributesSize + msgBodySize; return (totalMsgSize > clientConfiguration.getPayloadSizeThreshold()); } @@ -1214,22 +925,22 @@ private Optional getReservedAttributeNameIfPresent(Map msgAttributes) { int totalMsgAttributesSize = 0; - for (Entry entry : msgAttributes.entrySet()) { + for (Map.Entry entry : msgAttributes.entrySet()) { totalMsgAttributesSize += Util.getStringSizeInBytes(entry.getKey()); MessageAttributeValue entryVal = entry.getValue(); - if (entryVal.getDataType() != null) { - totalMsgAttributesSize += Util.getStringSizeInBytes(entryVal.getDataType()); + if (entryVal.dataType() != null) { + totalMsgAttributesSize += Util.getStringSizeInBytes(entryVal.dataType()); } - String stringVal = entryVal.getStringValue(); + String stringVal = entryVal.stringValue(); if (stringVal != null) { - totalMsgAttributesSize += Util.getStringSizeInBytes(entryVal.getStringValue()); + totalMsgAttributesSize += Util.getStringSizeInBytes(entryVal.stringValue()); } - ByteBuffer binaryVal = entryVal.getBinaryValue(); + SdkBytes binaryVal = entryVal.binaryValue(); if (binaryVal != null) { - totalMsgAttributesSize += binaryVal.array().length; + totalMsgAttributesSize += binaryVal.asByteArray().length; } } return totalMsgAttributesSize; @@ -1238,57 +949,66 @@ private int getMsgAttributesSize(Map msgAttribute private SendMessageBatchRequestEntry storeMessageInS3(SendMessageBatchRequestEntry batchEntry) { // Read the content of the message from message body - String messageContentStr = batchEntry.getMessageBody(); + String messageContentStr = batchEntry.messageBody(); Long messageContentSize = Util.getStringSizeInBytes(messageContentStr); - // Add a new message attribute as a flag - MessageAttributeValue messageAttributeValue = new MessageAttributeValue(); - messageAttributeValue.setDataType("Number"); - messageAttributeValue.setStringValue(messageContentSize.toString()); + SendMessageBatchRequestEntry.Builder batchEntryBuilder = batchEntry.toBuilder(); - if (!clientConfiguration.usesLegacyReservedAttributeName()) { - batchEntry.addMessageAttributesEntry(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME, - messageAttributeValue); - } else { - batchEntry.addMessageAttributesEntry(LEGACY_RESERVED_ATTRIBUTE_NAME, - messageAttributeValue); - } + batchEntryBuilder.messageAttributes( + updateMessageAttributePayloadSize(batchEntry.messageAttributes(), messageContentSize)); // Store the message content in S3. - String largeMessagePointer = payloadStore.storeOriginalPayload(messageContentStr, - messageContentSize); - batchEntry.setMessageBody(largeMessagePointer); + String largeMessagePointer = payloadStore.storeOriginalPayload(messageContentStr); + batchEntryBuilder.messageBody(largeMessagePointer); - return batchEntry; + return batchEntryBuilder.build(); } private SendMessageRequest storeMessageInS3(SendMessageRequest sendMessageRequest) { // Read the content of the message from message body - String messageContentStr = sendMessageRequest.getMessageBody(); + String messageContentStr = sendMessageRequest.messageBody(); Long messageContentSize = Util.getStringSizeInBytes(messageContentStr); + SendMessageRequest.Builder sendMessageRequestBuilder = sendMessageRequest.toBuilder(); + + sendMessageRequestBuilder.messageAttributes( + updateMessageAttributePayloadSize(sendMessageRequest.messageAttributes(), messageContentSize)); + + // Store the message content in S3. + String largeMessagePointer = payloadStore.storeOriginalPayload(messageContentStr); + sendMessageRequestBuilder.messageBody(largeMessagePointer); + + return sendMessageRequestBuilder.build(); + } + + private Map updateMessageAttributePayloadSize( + Map messageAttributes, Long messageContentSize) { + Map updatedMessageAttributes = new HashMap<>(messageAttributes); + // Add a new message attribute as a flag - MessageAttributeValue messageAttributeValue = new MessageAttributeValue(); - messageAttributeValue.setDataType("Number"); - messageAttributeValue.setStringValue(messageContentSize.toString()); + MessageAttributeValue.Builder messageAttributeValueBuilder = MessageAttributeValue.builder(); + messageAttributeValueBuilder.dataType("Number"); + messageAttributeValueBuilder.stringValue(messageContentSize.toString()); + MessageAttributeValue messageAttributeValue = messageAttributeValueBuilder.build(); if (!clientConfiguration.usesLegacyReservedAttributeName()) { - sendMessageRequest.addMessageAttributesEntry(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME, - messageAttributeValue); + updatedMessageAttributes.put(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME, messageAttributeValue); } else { - sendMessageRequest.addMessageAttributesEntry(LEGACY_RESERVED_ATTRIBUTE_NAME, - messageAttributeValue); + updatedMessageAttributes.put(LEGACY_RESERVED_ATTRIBUTE_NAME, messageAttributeValue); } - - // Store the message content in S3. - String largeMessagePointer = payloadStore.storeOriginalPayload(messageContentStr, - messageContentSize); - sendMessageRequest.setMessageBody(largeMessagePointer); - - return sendMessageRequest; + return updatedMessageAttributes; } + @SuppressWarnings("unchecked") + private static T appendUserAgent(final T builder) { + return (T) builder + .overrideConfiguration( + AwsRequestOverrideConfiguration.builder() + .addApiName(ApiName.builder().name(USER_AGENT_NAME) + .version(USER_AGENT_VERSION).build()) + .build()); + } } diff --git a/src/main/java/com/amazon/sqs/javamessaging/AmazonSQSExtendedClientBase.java b/src/main/java/com/amazon/sqs/javamessaging/AmazonSQSExtendedClientBase.java index 70edbae..73c9567 100644 --- a/src/main/java/com/amazon/sqs/javamessaging/AmazonSQSExtendedClientBase.java +++ b/src/main/java/com/amazon/sqs/javamessaging/AmazonSQSExtendedClientBase.java @@ -15,881 +15,684 @@ package com.amazon.sqs.javamessaging; -import com.amazonaws.AmazonClientException; -import com.amazonaws.AmazonServiceException; -import com.amazonaws.AmazonWebServiceRequest; -import com.amazonaws.ClientConfiguration; -import com.amazonaws.ResponseMetadata; -import com.amazonaws.auth.AWSCredentialsProvider; -import com.amazonaws.regions.Region; -import com.amazonaws.services.sqs.AmazonSQS; -import com.amazonaws.services.sqs.model.AddPermissionRequest; -import com.amazonaws.services.sqs.model.AddPermissionResult; -import com.amazonaws.services.sqs.model.BatchEntryIdsNotDistinctException; -import com.amazonaws.services.sqs.model.BatchRequestTooLongException; -import com.amazonaws.services.sqs.model.ChangeMessageVisibilityBatchRequest; -import com.amazonaws.services.sqs.model.ChangeMessageVisibilityBatchRequestEntry; -import com.amazonaws.services.sqs.model.ChangeMessageVisibilityBatchResult; -import com.amazonaws.services.sqs.model.ChangeMessageVisibilityRequest; -import com.amazonaws.services.sqs.model.ChangeMessageVisibilityResult; -import com.amazonaws.services.sqs.model.CreateQueueRequest; -import com.amazonaws.services.sqs.model.CreateQueueResult; -import com.amazonaws.services.sqs.model.DeleteMessageBatchRequest; -import com.amazonaws.services.sqs.model.DeleteMessageBatchRequestEntry; -import com.amazonaws.services.sqs.model.DeleteMessageBatchResult; -import com.amazonaws.services.sqs.model.DeleteMessageRequest; -import com.amazonaws.services.sqs.model.DeleteMessageResult; -import com.amazonaws.services.sqs.model.DeleteQueueRequest; -import com.amazonaws.services.sqs.model.DeleteQueueResult; -import com.amazonaws.services.sqs.model.EmptyBatchRequestException; -import com.amazonaws.services.sqs.model.GetQueueAttributesRequest; -import com.amazonaws.services.sqs.model.GetQueueAttributesResult; -import com.amazonaws.services.sqs.model.GetQueueUrlRequest; -import com.amazonaws.services.sqs.model.GetQueueUrlResult; -import com.amazonaws.services.sqs.model.InvalidAttributeNameException; -import com.amazonaws.services.sqs.model.InvalidBatchEntryIdException; -import com.amazonaws.services.sqs.model.InvalidIdFormatException; -import com.amazonaws.services.sqs.model.InvalidMessageContentsException; -import com.amazonaws.services.sqs.model.ListDeadLetterSourceQueuesRequest; -import com.amazonaws.services.sqs.model.ListDeadLetterSourceQueuesResult; -import com.amazonaws.services.sqs.model.ListQueueTagsRequest; -import com.amazonaws.services.sqs.model.ListQueueTagsResult; -import com.amazonaws.services.sqs.model.ListQueuesRequest; -import com.amazonaws.services.sqs.model.ListQueuesResult; -import com.amazonaws.services.sqs.model.MessageNotInflightException; -import com.amazonaws.services.sqs.model.OverLimitException; -import com.amazonaws.services.sqs.model.PurgeQueueInProgressException; -import com.amazonaws.services.sqs.model.PurgeQueueRequest; -import com.amazonaws.services.sqs.model.PurgeQueueResult; -import com.amazonaws.services.sqs.model.QueueDeletedRecentlyException; -import com.amazonaws.services.sqs.model.QueueDoesNotExistException; -import com.amazonaws.services.sqs.model.QueueNameExistsException; -import com.amazonaws.services.sqs.model.ReceiptHandleIsInvalidException; -import com.amazonaws.services.sqs.model.ReceiveMessageRequest; -import com.amazonaws.services.sqs.model.ReceiveMessageResult; -import com.amazonaws.services.sqs.model.RemovePermissionRequest; -import com.amazonaws.services.sqs.model.RemovePermissionResult; -import com.amazonaws.services.sqs.model.SendMessageBatchRequest; -import com.amazonaws.services.sqs.model.SendMessageBatchRequestEntry; -import com.amazonaws.services.sqs.model.SendMessageBatchResult; -import com.amazonaws.services.sqs.model.SendMessageRequest; -import com.amazonaws.services.sqs.model.SendMessageResult; -import com.amazonaws.services.sqs.model.SetQueueAttributesRequest; -import com.amazonaws.services.sqs.model.SetQueueAttributesResult; -import com.amazonaws.services.sqs.model.TagQueueRequest; -import com.amazonaws.services.sqs.model.TagQueueResult; -import com.amazonaws.services.sqs.model.TooManyEntriesInBatchRequestException; -import com.amazonaws.services.sqs.model.UntagQueueRequest; -import com.amazonaws.services.sqs.model.UntagQueueResult; - -import java.util.List; -import java.util.Map; - -abstract class AmazonSQSExtendedClientBase implements AmazonSQS { - AmazonSQS amazonSqsToBeExtended; - - public AmazonSQSExtendedClientBase(AmazonSQS sqsClient) { +import java.lang.UnsupportedOperationException; + +import software.amazon.awssdk.awscore.exception.AwsServiceException; +import software.amazon.awssdk.core.exception.SdkClientException; +import software.amazon.awssdk.core.exception.SdkException; +import software.amazon.awssdk.services.sqs.SqsClient; +import software.amazon.awssdk.services.sqs.model.AddPermissionRequest; +import software.amazon.awssdk.services.sqs.model.AddPermissionResponse; +import software.amazon.awssdk.services.sqs.model.BatchEntryIdsNotDistinctException; +import software.amazon.awssdk.services.sqs.model.BatchRequestTooLongException; +import software.amazon.awssdk.services.sqs.model.ChangeMessageVisibilityBatchRequest; +import software.amazon.awssdk.services.sqs.model.ChangeMessageVisibilityBatchResponse; +import software.amazon.awssdk.services.sqs.model.ChangeMessageVisibilityRequest; +import software.amazon.awssdk.services.sqs.model.ChangeMessageVisibilityResponse; +import software.amazon.awssdk.services.sqs.model.CreateQueueRequest; +import software.amazon.awssdk.services.sqs.model.CreateQueueResponse; +import software.amazon.awssdk.services.sqs.model.DeleteMessageBatchRequest; +import software.amazon.awssdk.services.sqs.model.DeleteMessageBatchResponse; +import software.amazon.awssdk.services.sqs.model.DeleteMessageRequest; +import software.amazon.awssdk.services.sqs.model.DeleteMessageResponse; +import software.amazon.awssdk.services.sqs.model.DeleteQueueRequest; +import software.amazon.awssdk.services.sqs.model.DeleteQueueResponse; +import software.amazon.awssdk.services.sqs.model.EmptyBatchRequestException; +import software.amazon.awssdk.services.sqs.model.GetQueueAttributesRequest; +import software.amazon.awssdk.services.sqs.model.GetQueueAttributesResponse; +import software.amazon.awssdk.services.sqs.model.GetQueueUrlRequest; +import software.amazon.awssdk.services.sqs.model.GetQueueUrlResponse; +import software.amazon.awssdk.services.sqs.model.InvalidAttributeNameException; +import software.amazon.awssdk.services.sqs.model.InvalidBatchEntryIdException; +import software.amazon.awssdk.services.sqs.model.InvalidIdFormatException; +import software.amazon.awssdk.services.sqs.model.InvalidMessageContentsException; +import software.amazon.awssdk.services.sqs.model.ListDeadLetterSourceQueuesRequest; +import software.amazon.awssdk.services.sqs.model.ListDeadLetterSourceQueuesResponse; +import software.amazon.awssdk.services.sqs.model.ListQueueTagsRequest; +import software.amazon.awssdk.services.sqs.model.ListQueueTagsResponse; +import software.amazon.awssdk.services.sqs.model.ListQueuesRequest; +import software.amazon.awssdk.services.sqs.model.ListQueuesResponse; +import software.amazon.awssdk.services.sqs.model.MessageNotInflightException; +import software.amazon.awssdk.services.sqs.model.OverLimitException; +import software.amazon.awssdk.services.sqs.model.PurgeQueueInProgressException; +import software.amazon.awssdk.services.sqs.model.PurgeQueueRequest; +import software.amazon.awssdk.services.sqs.model.PurgeQueueResponse; +import software.amazon.awssdk.services.sqs.model.QueueDeletedRecentlyException; +import software.amazon.awssdk.services.sqs.model.QueueDoesNotExistException; +import software.amazon.awssdk.services.sqs.model.QueueNameExistsException; +import software.amazon.awssdk.services.sqs.model.ReceiptHandleIsInvalidException; +import software.amazon.awssdk.services.sqs.model.ReceiveMessageRequest; +import software.amazon.awssdk.services.sqs.model.ReceiveMessageResponse; +import software.amazon.awssdk.services.sqs.model.RemovePermissionRequest; +import software.amazon.awssdk.services.sqs.model.RemovePermissionResponse; +import software.amazon.awssdk.services.sqs.model.SendMessageBatchRequest; +import software.amazon.awssdk.services.sqs.model.SendMessageBatchResponse; +import software.amazon.awssdk.services.sqs.model.SendMessageRequest; +import software.amazon.awssdk.services.sqs.model.SendMessageResponse; +import software.amazon.awssdk.services.sqs.model.SetQueueAttributesRequest; +import software.amazon.awssdk.services.sqs.model.SetQueueAttributesResponse; +import software.amazon.awssdk.services.sqs.model.SqsException; +import software.amazon.awssdk.services.sqs.model.TagQueueRequest; +import software.amazon.awssdk.services.sqs.model.TagQueueResponse; +import software.amazon.awssdk.services.sqs.model.TooManyEntriesInBatchRequestException; +import software.amazon.awssdk.services.sqs.model.UntagQueueRequest; +import software.amazon.awssdk.services.sqs.model.UntagQueueResponse; + +abstract class AmazonSQSExtendedClientBase implements SqsClient { + SqsClient amazonSqsToBeExtended; + + public AmazonSQSExtendedClientBase(SqsClient sqsClient) { amazonSqsToBeExtended = sqsClient; } /** *

    - * 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 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) { - 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 - * 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) { - return amazonSqsToBeExtended.receiveMessage(receiveMessageRequest); - } - - /** - *

    - * 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. + * Delivers a message to the specified queue. *

    + * *

    - * 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. + * A message can include only XML, JSON, and unformatted text. The following Unicode characters are allowed: *

    - * - * @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) { - 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. + * #x9 | #xA | #xD | #x20 to #xD7FF | + * #xE000 to #xFFFD | #x10000 to #x10FFFF *

    *

    - * 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] + * Any characters not included in this list will be rejected. For more information, see the W3C specification for characters. *

    + *
    * - * @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. - * + * @param sendMessageRequest + * @return Result of the SendMessage operation returned by the service. * @throws InvalidMessageContentsException + * The message contains characters outside the allowed set. * @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. + * Error code 400. Unsupported operation. + * @throws SdkException + * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for + * catch all scenarios. + * @throws SdkClientException + * If any client side error occurs such as an IO related failure, failure to get credentials, etc. + * @throws SqsException + * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. + * @sample SqsClient.SendMessage + * @see AWS API + * Documentation */ - public SendMessageResult sendMessage(String queueUrl, String messageBody) throws AmazonServiceException, - AmazonClientException { - - return amazonSqsToBeExtended.sendMessage(queueUrl, messageBody); + public SendMessageResponse sendMessage(SendMessageRequest sendMessageRequest) throws + InvalidMessageContentsException, UnsupportedOperationException, SdkException, SdkClientException, SqsException { + 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 - * WaitTimeSeconds parameter. For more information, see Amazon SQS Long Poll in the Amazon SQS Developer Guide . + * Retrieves one or more messages (up to 10), from the specified queue. Using the WaitTimeSeconds + * parameter enables long-poll support. For more information, see Amazon + * SQS Long Polling in the Amazon Simple Queue Service 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. + * Short poll is the default behavior where a weighted random set of machines is sampled on a + * ReceiveMessage call. Thus, only the messages on the sampled machines are returned. If the number of + * messages in the queue is small (fewer than 1,000), you most likely 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. If this happens, repeat the request. *

    *

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

    - * *
      *
    • *

      - * Message body + * The message body. *

      *
    • *
    • *

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

      *
    • *
    • *

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

      *
    • *
    • *

      - * Receipt handle. + * The receipt handle. *

      *
    • *
    • *

      - * Message attributes. + * The message attributes. *

      *
    • *
    • *

      - * MD5 digest of the message attributes. + * An 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 . + * The receipt handle is the identifier you must provide when deleting the message. For more information, see Queue and Message Identifiers in the Amazon Simple Queue Service 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 . + * You can provide the VisibilityTimeout parameter in your request. The parameter is applied to the + * messages that Amazon SQS returns in the response. If you don't 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 Simple Queue Service 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. + * A message that isn't deleted or a message whose visibility isn't extended before the visibility timeout expires + * counts as a failed receive. Depending on the configuration of the queue, the message might be sent to the + * dead-letter queue. *

    + * + *

    + * In the future, new attributes might be added. If you write 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. - * + * @param receiveMessageRequest + * @return Result of the ReceiveMessage operation returned by the service. * @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. + * The specified action violates a limit. For example, ReceiveMessage returns this error if the + * maximum number of inflight messages is reached and AddPermission returns this error if the + * maximum number of permissions for the queue is reached. + * @throws SdkException + * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for + * catch all scenarios. + * @throws SdkClientException + * If any client side error occurs such as an IO related failure, failure to get credentials, etc. + * @throws SqsException + * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. + * @sample SqsClient.ReceiveMessage + * @see AWS API + * Documentation */ - public ReceiveMessageResult receiveMessage(String queueUrl) throws AmazonServiceException, AmazonClientException { - - return amazonSqsToBeExtended.receiveMessage(queueUrl); + public ReceiveMessageResponse receiveMessage(ReceiveMessageRequest receiveMessageRequest) { + return amazonSqsToBeExtended.receiveMessage(receiveMessageRequest); } /** *

    - * 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. + * Deletes the specified message from the specified queue. To select the message to delete, use the + * ReceiptHandle of the message (not the MessageId which you receive when you send + * the message). Amazon SQS can delete a message from a queue even if a visibility timeout setting causes the + * message to be locked by another consumer. Amazon SQS automatically deletes messages left in a queue longer than + * the retention period configured for the queue. *

    + * *

    - * 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. + * The ReceiptHandle is associated with a specific instance of receiving a message. If you + * receive a message more than once, the ReceiptHandle is different each time you receive a message. + * When you use the DeleteMessage action, you must provide the most recently received + * ReceiptHandle for the message (otherwise, the request succeeds, 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. + * For standard queues, it is possible to receive a message even after you delete it. This might happen on rare + * occasions if one of the servers which stores a copy of the message is unavailable when you send the request to + * delete the message. The copy remains on the server and might be returned to you during a subsequent receive + * request. You should ensure that your application is idempotent, so that receiving a message more than once does + * not cause issues. *

    + *
    * - * @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 + * @param deleteMessageRequest + * @return Result of the DeleteMessage operation returned by the service. * @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. + * The specified receipt handle isn't valid for the current version. + * @throws ReceiptHandleIsInvalidException + * The specified receipt handle isn't valid. + * @throws SdkException + * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for + * catch all scenarios. + * @throws SdkClientException + * If any client side error occurs such as an IO related failure, failure to get credentials, etc. + * @throws SqsException + * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. + * @sample SqsClient.DeleteMessage + * @see AWS API + * Documentation */ - public DeleteMessageResult deleteMessage(String queueUrl, String receiptHandle) - throws AmazonServiceException, AmazonClientException { - - return amazonSqsToBeExtended.deleteMessage(queueUrl, receiptHandle); + public DeleteMessageResponse deleteMessage(DeleteMessageRequest deleteMessageRequest) throws + InvalidIdFormatException, ReceiptHandleIsInvalidException, SdkException, SdkClientException, SqsException { + return amazonSqsToBeExtended.deleteMessage(deleteMessageRequest); } /** *

    - * 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 + * 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 Amazon SQS system. Changes made to the * MessageRetentionPeriod attribute can take up to 15 minutes. *

    + * + *
      + *
    • + *

      + * In the future, new attributes might be added. If you write code that calls this action, we recommend that you + * structure your code so that it can handle new attributes gracefully. + *

      + *
    • + *
    • + *

      + * Cross-account permissions don't apply to this action. For more information, see Grant Cross-Account Permissions to a Role and a User Name in the Amazon Simple Queue Service 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. + * To remove the ability to change queue permissions, you must deny permission to the AddPermission, + * RemovePermission, and SetQueueAttributes actions in your IAM policy. *

      + *
    • + *
    + *
    * * @param setQueueAttributesRequest - * Container for the necessary parameters to execute the - * SetQueueAttributes service method on AmazonSQS. - * - * + * @return Result of the SetQueueAttributes operation returned by the service. * @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. + * The specified attribute doesn't exist. + * @throws SdkException + * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for + * catch all scenarios. + * @throws SdkClientException + * If any client side error occurs such as an IO related failure, failure to get credentials, etc. + * @throws SqsException + * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. + * @sample SqsClient.SetQueueAttributes + * @see AWS API + * Documentation */ - public SetQueueAttributesResult setQueueAttributes(SetQueueAttributesRequest setQueueAttributesRequest) - throws AmazonServiceException, AmazonClientException { + public SetQueueAttributesResponse setQueueAttributes(SetQueueAttributesRequest setQueueAttributesRequest) + throws InvalidAttributeNameException, AwsServiceException, SdkClientException, SqsException { 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 + * 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. + * 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: + * Some 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 + * &AttributeName.1=first *

    *

    - * &Attribute.2=that + * &AttributeName.2=second *

    * * @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 + * @return Result of the ChangeMessageVisibilityBatch operation returned by the service. * @throws TooManyEntriesInBatchRequestException - * @throws InvalidBatchEntryIdException + * The batch request contains more entries than permissible. * @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. + * The batch request doesn't contain any entries. + * @throws BatchEntryIdsNotDistinctException + * Two or more batch entries in the request have the same Id. + * @throws InvalidBatchEntryIdException + * The Id of a batch entry in a batch request doesn't abide by the specification. + * @throws SdkException + * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for + * catch all scenarios. + * @throws SdkClientException + * If any client side error occurs such as an IO related failure, failure to get credentials, etc. + * @throws SqsException + * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. + * @sample SqsClient.ChangeMessageVisibilityBatch + * @see AWS API Documentation */ - public ChangeMessageVisibilityBatchResult changeMessageVisibilityBatch( - ChangeMessageVisibilityBatchRequest changeMessageVisibilityBatchRequest) throws AmazonServiceException, - AmazonClientException { + public ChangeMessageVisibilityBatchResponse changeMessageVisibilityBatch( + ChangeMessageVisibilityBatchRequest changeMessageVisibilityBatchRequest) throws AwsServiceException, + SdkClientException { 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 .) + * Changes the visibility timeout of a specified message in a queue to a new value. The default visibility timeout + * for a message is 30 seconds. The minimum is 0 seconds. The maximum is 12 hours. For more information, see + * Visibility Timeout in the Amazon Simple Queue Service Developer Guide. + *

    + *

    + * For example, you have a message with a visibility timeout of 5 minutes. After 3 minutes, you call + * ChangeMessageVisibility with a timeout of 10 minutes. You can continue to call + * ChangeMessageVisibility to extend the visibility timeout to the maximum allowed time. If you try to + * extend the visibility timeout beyond the maximum, your request is rejected. + *

    + *

    + * An Amazon SQS message has three basic states: + *

    + *
      + *
    1. + *

      + * Sent to a queue by a producer. + *

      + *
    2. + *
    3. + *

      + * Received from the queue by a consumer. + *

      + *
    4. + *
    5. + *

      + * Deleted from the queue. + *

      + *
    6. + *
    + *

    + * A message is considered to be stored after it is sent to a queue by a producer, but not yet received from + * the queue by a consumer (that is, between states 1 and 2). There is no limit to the number of stored messages. A + * message is considered to be in flight after it is received from a queue by a consumer, but not yet deleted + * from the queue (that is, between states 2 and 3). There is a limit to the number of inflight messages. *

    *

    - * 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. + * Limits that apply to inflight messages are unrelated to the unlimited number of stored messages. *

    *

    - * 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. + * For most standard queues (depending on queue traffic and message backlog), there can be a maximum of + * approximately 120,000 inflight messages (received from a queue by a consumer, but not yet deleted from the + * queue). If you reach this limit, Amazon SQS returns the OverLimit error message. To avoid reaching + * the limit, you should delete messages from the queue after they're processed. You can also increase the number of + * queues you use to process your messages. To request a limit increase, file a support request. *

    *

    - * 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. + * For FIFO queues, there can be a maximum of 20,000 inflight messages (received from a queue by a consumer, but not + * yet deleted from the queue). If you reach this limit, Amazon SQS returns no error messages. *

    + * *

    - * 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. + * If you attempt to set the VisibilityTimeout to a value greater than the maximum time left, Amazon + * SQS returns an error. Amazon SQS doesn't automatically recalculate and increase the timeout to the maximum + * remaining time. *

    + *

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

    + *
    * * @param changeMessageVisibilityRequest - * Container for the necessary parameters to execute the - * ChangeMessageVisibility service method on AmazonSQS. - * - * - * @throws ReceiptHandleIsInvalidException + * @return Result of the ChangeMessageVisibility operation returned by the service. * @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. + * The specified message isn't in flight. + * @throws ReceiptHandleIsInvalidException + * The specified receipt handle isn't valid. + * @throws SdkException + * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for + * catch all scenarios. + * @throws SdkClientException + * If any client side error occurs such as an IO related failure, failure to get credentials, etc. + * @throws SqsException + * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. + * @sample SqsClient.ChangeMessageVisibility + * @see AWS + * API Documentation */ - public ChangeMessageVisibilityResult changeMessageVisibility(ChangeMessageVisibilityRequest changeMessageVisibilityRequest) - throws AmazonServiceException, AmazonClientException { + public ChangeMessageVisibilityResponse changeMessageVisibility(ChangeMessageVisibilityRequest changeMessageVisibilityRequest) + throws AwsServiceException, SdkClientException { 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. + * Returns the URL of an existing 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 . + * 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 see Allow Developers to Write Messages to a Shared Queue in the Amazon Simple Queue Service 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. - * + * @return Result of the GetQueueUrl operation returned by the service. * @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. + * The specified queue doesn't exist. + * @throws SdkException + * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for + * catch all scenarios. + * @throws SdkClientException + * If any client side error occurs such as an IO related failure, failure to get credentials, etc. + * @throws SqsException + * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. + * @sample SqsClient.GetQueueUrl + * @see AWS API + * Documentation */ - public GetQueueUrlResult getQueueUrl(GetQueueUrlRequest getQueueUrlRequest) throws AmazonServiceException, - AmazonClientException { + public GetQueueUrlResponse getQueueUrl(GetQueueUrlRequest getQueueUrlRequest) throws AwsServiceException, + SdkClientException { 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. + * Revokes any permissions in the queue policy that matches the specified Label parameter. + *

    + * + *
      + *
    • + *

      + * Only the owner of a queue can remove permissions from it. + *

      + *
    • + *
    • + *

      + * Cross-account permissions don't apply to this action. For more information, see Grant Cross-Account Permissions to a Role and a User Name in the Amazon Simple Queue Service Developer + * Guide. + *

      + *
    • + *
    • + *

      + * To remove the ability to change queue permissions, you must deny permission to the AddPermission, + * RemovePermission, and SetQueueAttributes actions in your IAM policy. *

      + *
    • + *
    + *
    * * @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. + * @return Result of the RemovePermission operation returned by the service. + * @throws SdkException + * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for + * catch all scenarios. + * @throws SdkClientException + * If any client side error occurs such as an IO related failure, failure to get credentials, etc. + * @throws SqsException + * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. + * @sample SqsClient.RemovePermission + * @see AWS API + * Documentation */ - public RemovePermissionResult removePermission(RemovePermissionRequest removePermissionRequest) - throws AmazonServiceException, AmazonClientException { + public RemovePermissionResponse removePermission(RemovePermissionRequest removePermissionRequest) + throws AwsServiceException, SdkClientException { 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: + * Gets attributes for the specified queue. *

    + * *

    - * &Attribute.1=this - *

    - *

    - * &Attribute.2=that + * To determine whether a queue is FIFO, you + * can check whether QueueName ends with the .fifo suffix. *

    + *
    * * @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. - * + * @return Result of the GetQueueAttributes operation returned by the service. * @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. + * The specified attribute doesn't exist. + * @throws SdkException + * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for + * catch all scenarios. + * @throws SdkClientException + * If any client side error occurs such as an IO related failure, failure to get credentials, etc. + * @throws SqsException + * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. + * @sample SqsClient.GetQueueAttributes + * @see AWS API + * Documentation */ - public GetQueueAttributesResult getQueueAttributes(GetQueueAttributesRequest getQueueAttributesRequest) - throws AmazonServiceException, AmazonClientException { + public GetQueueAttributesResponse getQueueAttributes(GetQueueAttributesRequest getQueueAttributesRequest) + throws AwsServiceException, SdkClientException { 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). + * Delivers up to ten messages to the specified queue. This is a batch version of SendMessage. + * For a FIFO queue, multiple messages within a single batch are enqueued in the order they are sent. + *

    + *

    + * The result of sending each message is reported individually in the response. 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. + *

    + *

    + * The maximum allowed individual message size and the maximum total payload size (the sum of the individual lengths + * of all of the batched messages) are both 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). + * A message can include only XML, JSON, and unformatted text. The following Unicode characters are allowed: *

    *

    - * If the DelaySeconds parameter is not specified for an entry, - * the default for the queue is used. + * #x9 | #xA | #xD | #x20 to #xD7FF | + * #xE000 to #xFFFD | #x10000 to #x10FFFF *

    *

    - * 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] + * Any characters not included in this list will be rejected. For more information, see the W3C specification for characters. *

    + *
    *

    - * 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. + * If you don't specify the DelaySeconds parameter for an entry, Amazon SQS uses the default value for + * the queue. *

    *

    - * 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: + * Some 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 + * &AttributeName.1=first *

    *

    - * &Attribute.2=that + * &AttributeName.2=second *

    * * @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 + * @return Result of the SendMessageBatch operation returned by the service. * @throws TooManyEntriesInBatchRequestException + * The batch request contains more entries than permissible. + * @throws EmptyBatchRequestException + * The batch request doesn't contain any entries. + * @throws BatchEntryIdsNotDistinctException + * Two or more batch entries in the request have the same Id. * @throws BatchRequestTooLongException - * @throws UnsupportedOperationException + * The length of all the messages put together is more than the limit. * @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. + * The Id of a batch entry in a batch request doesn't abide by the specification. + * @throws UnsupportedOperationException + * Error code 400. Unsupported operation. + * @throws SdkException + * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for + * catch all scenarios. + * @throws SdkClientException + * If any client side error occurs such as an IO related failure, failure to get credentials, etc. + * @throws SqsException + * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. + * @sample SqsClient.SendMessageBatch + * @see AWS API + * Documentation */ - public SendMessageBatchResult sendMessageBatch(SendMessageBatchRequest sendMessageBatchRequest) - throws AmazonServiceException, AmazonClientException { + public SendMessageBatchResponse sendMessageBatch(SendMessageBatchRequest sendMessageBatchRequest) + throws AwsServiceException, SdkClientException { return amazonSqsToBeExtended.sendMessageBatch(sendMessageBatchRequest); } /** *

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

    + * + *

    + * When you use the PurgeQueue action, you can't retrieve any messages deleted from a queue. *

    *

    - * IMPORTANT:When you use the PurgeQueue API, the deleted messages in - * the queue cannot be retrieved. + * The message deletion process takes up to 60 seconds. We recommend waiting for 60 seconds regardless of your + * queue's size. *

    + *
    *

    - * 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. + * Messages sent to the queue before you call PurgeQueue might be received but are deleted + * within the next minute. + *

    + *

    + * Messages sent to the queue after you call PurgeQueue might be deleted while the queue is + * being purged. *

    * * @param purgeQueueRequest - * Container for the necessary parameters to execute the - * PurgeQueue service method on AmazonSQS. - * - * - * @throws PurgeQueueInProgressException + * @return Result of the PurgeQueue operation returned by the service. * @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. + * The specified queue doesn't exist. + * @throws PurgeQueueInProgressException + * Indicates that the specified queue previously received a PurgeQueue request within the last + * 60 seconds (the time it can take to delete the messages in the queue). + * @throws SdkException + * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for + * catch all scenarios. + * @throws SdkClientException + * If any client side error occurs such as an IO related failure, failure to get credentials, etc. + * @throws SqsException + * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. + * @sample SqsClient.PurgeQueue + * @see AWS API + * Documentation */ - public PurgeQueueResult purgeQueue(PurgeQueueRequest purgeQueueRequest) - throws AmazonServiceException, AmazonClientException { + public PurgeQueueResponse purgeQueue(PurgeQueueRequest purgeQueueRequest) + throws AwsServiceException, SdkClientException { return amazonSqsToBeExtended.purgeQueue(purgeQueueRequest); @@ -897,229 +700,280 @@ public PurgeQueueResult purgeQueue(PurgeQueueRequest purgeQueueRequest) /** *

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

    + *

    + * The ListDeadLetterSourceQueues methods supports pagination. Set parameter MaxResults in + * the request to specify the maximum number of results to be returned in the response. If you do not set + * MaxResults, the response includes a maximum of 1,000 results. If you set MaxResults and + * there are additional results to display, the response includes a value for NextToken. Use + * NextToken as a parameter in your next request to ListDeadLetterSourceQueues to receive + * the next page of results. *

    *

    - * For more information about using dead letter queues, see Using Amazon SQS Dead Letter Queues . + * For more information about using dead-letter queues, see Using Amazon SQS Dead-Letter Queues in the Amazon Simple Queue Service Developer Guide. *

    * * @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. - * + * @return Result of the ListDeadLetterSourceQueues operation returned by the service. * @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. + * The specified queue doesn't exist. + * @throws SdkException + * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for + * catch all scenarios. + * @throws SdkClientException + * If any client side error occurs such as an IO related failure, failure to get credentials, etc. + * @throws SqsException + * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. + * @sample SqsClient.ListDeadLetterSourceQueues + * @see AWS + * API Documentation */ - public ListDeadLetterSourceQueuesResult listDeadLetterSourceQueues( - ListDeadLetterSourceQueuesRequest listDeadLetterSourceQueuesRequest) throws AmazonServiceException, - AmazonClientException { + public ListDeadLetterSourceQueuesResponse listDeadLetterSourceQueues( + ListDeadLetterSourceQueuesRequest listDeadLetterSourceQueuesRequest) throws AwsServiceException, + SdkClientException { 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. + * Deletes the queue specified by the QueueUrl, regardless of the queue's contents. *

    + * *

    - * IMPORTANT: Use DeleteQueue with care; once you delete your queue, - * any messages in the queue are no longer available. + * Be careful with the DeleteQueue action: When you delete a 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. + * 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 60 seconds the queue and the message you sent no longer exist. *

    *

    - * 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 . + * When you delete a queue, you must wait at least 60 seconds before creating a queue with the same name. *

    + * + *

    + * Cross-account permissions don't apply to this action. For more information, see Grant Cross-Account Permissions to a Role and a User Name in the Amazon Simple Queue Service 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. + * @return Result of the DeleteQueue operation returned by the service. + * @throws SdkException + * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for + * catch all scenarios. + * @throws SdkClientException + * If any client side error occurs such as an IO related failure, failure to get credentials, etc. + * @throws SqsException + * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. + * @sample SqsClient.DeleteQueue + * @see AWS API + * Documentation */ - public DeleteQueueResult deleteQueue(DeleteQueueRequest deleteQueueRequest) - throws AmazonServiceException, AmazonClientException { + public DeleteQueueResponse deleteQueue(DeleteQueueRequest deleteQueueRequest) + throws AwsServiceException, SdkClientException { 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. + * Returns a list of your queues in the current region. The response includes a maximum of 1,000 results. If you + * specify a value for the optional QueueNamePrefix parameter, only queues with a name that begins with + * the specified value are returned. + *

    + *

    + * The listQueues methods supports pagination. Set parameter MaxResults in the request to + * specify the maximum number of results to be returned in the response. If you do not set MaxResults, + * the response includes a maximum of 1,000 results. If you set MaxResults and there are additional + * results to display, the response includes a value for NextToken. Use NextToken as a + * parameter in your next request to listQueues to receive the next page of results. + *

    + * + *

    + * Cross-account permissions don't apply to this action. For more information, see Grant Cross-Account Permissions to a Role and a User Name in the Amazon Simple Queue Service Developer + * Guide. *

    + *
    * * @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. + * @return Result of the ListQueues operation returned by the service. + * @throws SdkException + * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for + * catch all scenarios. + * @throws SdkClientException + * If any client side error occurs such as an IO related failure, failure to get credentials, etc. + * @throws SqsException + * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. + * @sample SqsClient.ListQueues + * @see AWS API + * Documentation */ - public ListQueuesResult listQueues(ListQueuesRequest listQueuesRequest) throws AmazonServiceException, - AmazonClientException { + public ListQueuesResponse listQueues(ListQueuesRequest listQueuesRequest) throws AwsServiceException, + SdkClientException { 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. + * Deletes up to ten messages from the specified queue. This is a batch version of + * DeleteMessage. The result of the 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. + * 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: + * Some 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 + * &AttributeName.1=first *

    *

    - * &Attribute.2=that + * &AttributeName.2=second *

    * * @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 + * @return Result of the DeleteMessageBatch operation returned by the service. * @throws TooManyEntriesInBatchRequestException - * @throws InvalidBatchEntryIdException + * The batch request contains more entries than permissible. * @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. + * The batch request doesn't contain any entries. + * @throws BatchEntryIdsNotDistinctException + * Two or more batch entries in the request have the same Id. + * @throws InvalidBatchEntryIdException + * The Id of a batch entry in a batch request doesn't abide by the specification. + * @throws SdkException + * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for + * catch all scenarios. + * @throws SdkClientException + * If any client side error occurs such as an IO related failure, failure to get credentials, etc. + * @throws SqsException + * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. + * @sample SqsClient.DeleteMessageBatch + * @see AWS API + * Documentation */ - public DeleteMessageBatchResult deleteMessageBatch(DeleteMessageBatchRequest deleteMessageBatchRequest) - throws AmazonServiceException, AmazonClientException { + public DeleteMessageBatchResponse deleteMessageBatch(DeleteMessageBatchRequest deleteMessageBatchRequest) + throws AwsServiceException, SdkClientException { 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. + * Creates a new standard or FIFO queue. You can pass one or more attributes in the request. Keep the following in + * mind: + *

    + *
      + *
    • + *

      + * If you don't specify the FifoQueue attribute, Amazon SQS creates a standard queue. + *

      + * + *

      + * You can't change the queue type after you create it and you can't convert an existing standard queue into a FIFO + * queue. You must either create a new FIFO queue for your application or delete your existing standard queue and + * recreate it as a FIFO queue. For more information, see Moving From a Standard Queue to a FIFO Queue in the Amazon Simple Queue Service Developer Guide. + *

      + *
    • + *
    • + *

      + * If you don't provide a value for an attribute, the queue is created with the default value for the attribute. + *

      + *
    • + *
    • + *

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

      + *
    • + *
    + *

    + * To successfully create a new queue, you must provide a queue name that adheres to the limits + * related to queues and is unique within the scope of your queues. + *

    + * *

    - * NOTE: If you delete a queue, you must wait at least 60 seconds - * before creating a queue with the same name. + * After you create a queue, you must wait at least one second after the queue is created to be able to use the + * queue. *

    + *
    + *

    + * To get the queue URL, use the GetQueueUrl action. GetQueueUrl + * requires only the QueueName parameter. be aware of existing queue names: + *

    + *
      + *
    • *

      - * 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. + * 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. *

      + *
    • + *
    • *

      - * NOTE: Use GetQueueUrl to get a queue's URL. GetQueueUrl requires - * only the QueueName parameter. + * If the queue name, attribute names, or attribute values don't match an existing queue, CreateQueue + * returns an error. *

      + *
    • + *
    *

    - * 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. + * Some 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: *

    *

    - * 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: + * &AttributeName.1=first *

    *

    - * &Attribute.1=this + * &AttributeName.2=second *

    + * *

    - * &Attribute.2=that + * Cross-account permissions don't apply to this action. For more information, see Grant Cross-Account Permissions to a Role and a User Name in the Amazon Simple Queue Service Developer + * Guide. *

    + *
    * * @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 + * @return Result of the CreateQueue operation returned by the service. * @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. + * You must wait 60 seconds after deleting a queue before you can create another queue with the same name. + * @throws QueueNameExistsException + * A queue with this name already exists. Amazon SQS returns this error only if the request includes + * attributes whose values differ from those of the existing queue. + * @throws SdkException + * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for + * catch all scenarios. + * @throws SdkClientException + * If any client side error occurs such as an IO related failure, failure to get credentials, etc. + * @throws SqsException + * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. + * @sample SqsClient.CreateQueue + * @see AWS API + * Documentation */ - public CreateQueueResult createQueue(CreateQueueRequest createQueueRequest) throws AmazonServiceException, - AmazonClientException { + public CreateQueueResponse createQueue(CreateQueueRequest createQueueRequest) + throws AwsServiceException, SdkClientException { return amazonSqsToBeExtended.createQueue(createQueueRequest); } @@ -1127,928 +981,144 @@ public CreateQueueResult createQueue(CreateQueueRequest createQueueRequest) thro /** *

    * Adds a permission to a queue for a specific - * principal . This allows for sharing access to the queue. + * href="https://docs.aws.amazon.com/general/latest/gr/glos-chap.html#P">principal. This allows 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 . + * When you create a queue, you have full control access rights for the queue. Only you, the owner of the queue, can + * grant or deny permissions to the queue. For more information about these permissions, see Allow Developers to Write Messages to a Shared Queue in the Amazon Simple Queue Service 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. + * AddPermission generates a policy for you. You can use SetQueueAttributes to + * upload your policy. For more information, see Using Custom Policies with the Amazon SQS Access Policy Language in the Amazon Simple Queue Service + * 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: + * An Amazon SQS policy can have a maximum of 7 actions. *

      + *
    • + *
    • *

      - * &Attribute.1=this + * To remove the ability to change queue permissions, you must deny permission to the AddPermission, + * RemovePermission, and SetQueueAttributes actions in your IAM policy. *

      - *

      - * &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. + * Some 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: *

      *

      - * 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: + * &AttributeName.1=first *

      *

      - * &Attribute.1=this + * &AttributeName.2=second *

      + * *

      - * &Attribute.2=that + * Cross-account permissions don't apply to this action. For more information, see Grant Cross-Account Permissions to a Role and a User Name in the Amazon Simple Queue Service Developer + * Guide. *

      + *
      * - * @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. - * + * @param addPermissionRequest + * @return Result of the AddPermission operation returned by the service. * @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. + * The specified action violates a limit. For example, ReceiveMessage returns this error if the + * maximum number of inflight messages is reached and AddPermission returns this error if the + * maximum number of permissions for the queue is reached. + * @throws SdkException + * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for + * catch all scenarios. + * @throws SdkClientException + * If any client side error occurs such as an IO related failure, failure to get credentials, etc. + * @throws SqsException + * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. + * @sample SqsClient.AddPermission + * @see AWS API + * Documentation */ - 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); + public AddPermissionResponse addPermission(AddPermissionRequest addPermissionRequest) + throws AwsServiceException, SdkClientException, OverLimitException { + return amazonSqsToBeExtended.addPermission(addPermissionRequest); } /** - * 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. + *

      + * Returns a list of your queues in the current region. The response includes a maximum of 1,000 results. If you + * specify a value for the optional QueueNamePrefix parameter, only queues with a name that begins with + * the specified value are returned. + *

      + *

      + * The listQueues methods supports pagination. Set parameter MaxResults in the request to + * specify the maximum number of results to be returned in the response. If you do not set MaxResults, + * the response includes a maximum of 1,000 results. If you set MaxResults and there are additional + * results to display, the response includes a value for NextToken. Use NextToken as a + * parameter in your next request to listQueues to receive the next page of results. + *

      + * + *

      + * Cross-account permissions don't apply to this action. For more information, see Grant Cross-Account Permissions to a Role and a User Name in the Amazon Simple Queue Service Developer + * Guide. + *

      + *
      + * + * @return Result of the ListQueues operation returned by the service. + * @throws SdkException + * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for + * catch all scenarios. + * @throws SdkClientException + * If any client side error occurs such as an IO related failure, failure to get credentials, etc. + * @throws SqsException + * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. + * @sample SqsClient.ListQueues + * @see #listQueues(ListQueuesRequest) + * @see AWS API + * Documentation */ - public void shutdown() { + public ListQueuesResponse listQueues() throws AwsServiceException, SdkClientException { - amazonSqsToBeExtended.shutdown(); + return amazonSqsToBeExtended.listQueues(); } /** {@inheritDoc} */ - @Override public ListQueueTagsResult listQueueTags(final ListQueueTagsRequest listQueueTagsRequest) { + @Override public ListQueueTagsResponse 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) { + @Override public TagQueueResponse 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) { + @Override public UntagQueueResponse untagQueue(final UntagQueueRequest untagQueueRequest) { return amazonSqsToBeExtended.untagQueue(untagQueueRequest); } - /** {@inheritDoc} */ - @Override public UntagQueueResult untagQueue(final String queueUrl, final List tagKeys) { - return amazonSqsToBeExtended.untagQueue(queueUrl, tagKeys); + @Override + public String serviceName() { + return amazonSqsToBeExtended.serviceName(); } + @Override + public void close() { + amazonSqsToBeExtended.close(); + } } diff --git a/src/main/java/com/amazon/sqs/javamessaging/ExtendedClientConfiguration.java b/src/main/java/com/amazon/sqs/javamessaging/ExtendedClientConfiguration.java index a20f561..039ca06 100644 --- a/src/main/java/com/amazon/sqs/javamessaging/ExtendedClientConfiguration.java +++ b/src/main/java/com/amazon/sqs/javamessaging/ExtendedClientConfiguration.java @@ -15,11 +15,11 @@ package com.amazon.sqs.javamessaging; -import com.amazonaws.services.s3.AmazonS3; -import com.amazonaws.services.s3.model.CannedAccessControlList; -import com.amazonaws.services.s3.model.SSEAwsKeyManagementParams; -import com.amazonaws.annotation.NotThreadSafe; +import software.amazon.awssdk.annotations.NotThreadSafe; +import software.amazon.awssdk.services.s3.S3Client; +import software.amazon.awssdk.services.s3.model.ObjectCannedACL; import software.amazon.payloadoffloading.PayloadStorageConfiguration; +import software.amazon.payloadoffloading.ServerSideEncryptionStrategy; /** @@ -61,7 +61,7 @@ public ExtendedClientConfiguration(ExtendedClientConfiguration other) { * objects its the responsibility to the message producer to handle * the clean up appropriately. */ - public void setPayloadSupportEnabled(AmazonS3 s3, String s3BucketName, boolean cleanupS3Payload) { + public void setPayloadSupportEnabled(S3Client s3, String s3BucketName, boolean cleanupS3Payload) { setPayloadSupportEnabled(s3, s3BucketName); this.cleanupS3Payload = cleanupS3Payload; } @@ -82,7 +82,7 @@ public void setPayloadSupportEnabled(AmazonS3 s3, String s3BucketName, boolean c * objects its the responsibility to the message producer to handle * the clean up appropriately. */ - public ExtendedClientConfiguration withPayloadSupportEnabled(AmazonS3 s3, String s3BucketName, boolean cleanupS3Payload) { + public ExtendedClientConfiguration withPayloadSupportEnabled(S3Client s3, String s3BucketName, boolean cleanupS3Payload) { setPayloadSupportEnabled(s3, s3BucketName, cleanupS3Payload); return this; } @@ -167,14 +167,14 @@ public ExtendedClientConfiguration withAlwaysThroughS3(boolean alwaysThroughS3) } @Override - public ExtendedClientConfiguration withPayloadSupportEnabled(AmazonS3 s3, String s3BucketName) { + public ExtendedClientConfiguration withPayloadSupportEnabled(S3Client s3, String s3BucketName) { this.setPayloadSupportEnabled(s3, s3BucketName); return this; } @Override - public ExtendedClientConfiguration withSSEAwsKeyManagementParams(SSEAwsKeyManagementParams sseAwsKeyManagementParams) { - this.setSSEAwsKeyManagementParams(sseAwsKeyManagementParams); + public ExtendedClientConfiguration withObjectCannedACL(ObjectCannedACL objectCannedACL) { + this.setObjectCannedACL(objectCannedACL); return this; } @@ -191,8 +191,8 @@ public ExtendedClientConfiguration withPayloadSupportDisabled() { } @Override - public ExtendedClientConfiguration withCannedAccessControlList(CannedAccessControlList cannedAccessControlList) { - this.setCannedAccessControlList(cannedAccessControlList); + public ExtendedClientConfiguration withServerSideEncryption(ServerSideEncryptionStrategy serverSideEncryption) { + this.setServerSideEncryptionStrategy(serverSideEncryption); return this; } @@ -207,10 +207,10 @@ public ExtendedClientConfiguration withCannedAccessControlList(CannedAccessContr * large-payload messages. The bucket must be already created and * configured in s3. * - * @deprecated Instead use {@link #setPayloadSupportEnabled(AmazonS3, String, boolean)} + * @deprecated Instead use {@link #setPayloadSupportEnabled(S3Client, String, boolean)} */ @Deprecated - public void setLargePayloadSupportEnabled(AmazonS3 s3, String s3BucketName) { + public void setLargePayloadSupportEnabled(S3Client s3, String s3BucketName) { this.setPayloadSupportEnabled(s3, s3BucketName); } @@ -226,10 +226,10 @@ public void setLargePayloadSupportEnabled(AmazonS3 s3, String s3BucketName) { * configured in s3. * @return the updated ExtendedClientConfiguration object. * - * @deprecated Instead use {@link #withPayloadSupportEnabled(AmazonS3, String)} + * @deprecated Instead use {@link #withPayloadSupportEnabled(S3Client, String)} */ @Deprecated - public ExtendedClientConfiguration withLargePayloadSupportEnabled(AmazonS3 s3, String s3BucketName) { + public ExtendedClientConfiguration withLargePayloadSupportEnabled(S3Client s3, String s3BucketName) { setLargePayloadSupportEnabled(s3, s3BucketName); return this; } diff --git a/src/test/java/com/amazon/sqs/javamessaging/AmazonSQSExtendedClientTest.java b/src/test/java/com/amazon/sqs/javamessaging/AmazonSQSExtendedClientTest.java index 0975183..c2f5451 100644 --- a/src/test/java/com/amazon/sqs/javamessaging/AmazonSQSExtendedClientTest.java +++ b/src/test/java/com/amazon/sqs/javamessaging/AmazonSQSExtendedClientTest.java @@ -15,24 +15,51 @@ package com.amazon.sqs.javamessaging; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.UUID; import java.util.stream.Collectors; import java.util.stream.IntStream; -import com.amazonaws.AmazonServiceException; -import com.amazonaws.services.s3.AmazonS3; -import com.amazonaws.services.s3.model.*; -import com.amazonaws.services.sqs.AmazonSQS; -import com.amazonaws.services.sqs.AmazonSQSClient; -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.awssdk.awscore.AwsRequestOverrideConfiguration; +import software.amazon.awssdk.core.ApiName; +import software.amazon.awssdk.core.ResponseInputStream; +import software.amazon.awssdk.core.sync.RequestBody; +import software.amazon.awssdk.http.AbortableInputStream; +import software.amazon.awssdk.services.s3.S3Client; +import software.amazon.awssdk.services.s3.model.DeleteObjectRequest; +import software.amazon.awssdk.services.s3.model.GetObjectRequest; +import software.amazon.awssdk.services.s3.model.GetObjectResponse; +import software.amazon.awssdk.services.s3.model.ObjectCannedACL; +import software.amazon.awssdk.services.s3.model.PutObjectRequest; +import software.amazon.awssdk.services.sqs.SqsClient; +import software.amazon.awssdk.services.sqs.model.DeleteMessageBatchRequest; +import software.amazon.awssdk.services.sqs.model.DeleteMessageBatchRequestEntry; +import software.amazon.awssdk.services.sqs.model.DeleteMessageRequest; +import software.amazon.awssdk.services.sqs.model.Message; +import software.amazon.awssdk.services.sqs.model.MessageAttributeValue; +import software.amazon.awssdk.services.sqs.model.ReceiveMessageRequest; +import software.amazon.awssdk.services.sqs.model.ReceiveMessageResponse; +import software.amazon.awssdk.services.sqs.model.SendMessageBatchRequest; +import software.amazon.awssdk.services.sqs.model.SendMessageBatchRequestEntry; +import software.amazon.awssdk.services.sqs.model.SendMessageRequest; +import software.amazon.awssdk.utils.ImmutableMap; +import software.amazon.awssdk.utils.StringInputStream; import software.amazon.payloadoffloading.PayloadS3Pointer; +import software.amazon.payloadoffloading.ServerSideEncryptionFactory; +import software.amazon.payloadoffloading.ServerSideEncryptionStrategy; +import static com.amazon.sqs.javamessaging.AmazonSQSExtendedClient.USER_AGENT_NAME; +import static com.amazon.sqs.javamessaging.AmazonSQSExtendedClient.USER_AGENT_VERSION; +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; @@ -43,21 +70,19 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.times; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.anyString; /** * Tests the AmazonSQSExtendedClient class. */ public class AmazonSQSExtendedClientTest { - private AmazonSQS extendedSqsWithDefaultConfig; - private AmazonSQS extendedSqsWithCustomKMS; - private AmazonSQS extendedSqsWithDefaultKMS; - private AmazonSQS extendedSqsWithGenericReservedAttributeName; - private AmazonSQS extendedSqsWithDeprecatedMethods; - private AmazonSQS mockSqsBackend; - private AmazonS3 mockS3; + private SqsClient extendedSqsWithDefaultConfig; + private SqsClient extendedSqsWithCustomKMS; + private SqsClient extendedSqsWithDefaultKMS; + private SqsClient extendedSqsWithGenericReservedAttributeName; + private SqsClient extendedSqsWithDeprecatedMethods; + private SqsClient mockSqsBackend; + private S3Client 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"; @@ -65,26 +90,28 @@ public class AmazonSQSExtendedClientTest { 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; + private static final ServerSideEncryptionStrategy SERVER_SIDE_ENCRYPTION_CUSTOM_STRATEGY = ServerSideEncryptionFactory.customerKey(S3_SERVER_SIDE_ENCRYPTION_KMS_KEY_ID); + private static final ServerSideEncryptionStrategy SERVER_SIDE_ENCRYPTION_DEFAULT_STRATEGY = ServerSideEncryptionFactory.awsManagedCmk(); // should be > 1 and << SQS_SIZE_LIMIT private static final int ARBITRARY_SMALLER_THRESHOLD = 500; @Before public void setupClients() { - mockS3 = mock(AmazonS3.class); - mockSqsBackend = mock(AmazonSQS.class); - when(mockS3.putObject(isA(PutObjectRequest.class))).thenReturn(null); + mockS3 = mock(S3Client.class); + mockSqsBackend = mock(SqsClient.class); + when(mockS3.putObject(isA(PutObjectRequest.class), isA(RequestBody.class))).thenReturn(null); ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration() .withPayloadSupportEnabled(mockS3, S3_BUCKET_NAME); ExtendedClientConfiguration extendedClientConfigurationWithCustomKMS = new ExtendedClientConfiguration() .withPayloadSupportEnabled(mockS3, S3_BUCKET_NAME) - .withSSEAwsKeyManagementParams(new SSEAwsKeyManagementParams(S3_SERVER_SIDE_ENCRYPTION_KMS_KEY_ID)); + .withServerSideEncryption(SERVER_SIDE_ENCRYPTION_CUSTOM_STRATEGY); ExtendedClientConfiguration extendedClientConfigurationWithDefaultKMS = new ExtendedClientConfiguration() .withPayloadSupportEnabled(mockS3, S3_BUCKET_NAME) - .withSSEAwsKeyManagementParams(new SSEAwsKeyManagementParams()); + .withServerSideEncryption(SERVER_SIDE_ENCRYPTION_DEFAULT_STRATEGY); ExtendedClientConfiguration extendedClientConfigurationWithGenericReservedAttributeName = new ExtendedClientConfiguration() .withPayloadSupportEnabled(mockS3, S3_BUCKET_NAME).withLegacyReservedAttributeNameDisabled(); @@ -105,13 +132,26 @@ public void testWhenSendMessageWithLargePayloadSupportDisabledThenS3IsNotUsedAnd String messageBody = generateStringWithLength(messageLength); ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration() .withLargePayloadSupportDisabled(); - AmazonSQS sqsExtended = spy(new AmazonSQSExtendedClient(mockSqsBackend, extendedClientConfiguration)); - - SendMessageRequest messageRequest = new SendMessageRequest(SQS_QUEUE_URL, messageBody); + SqsClient sqsExtended = spy(new AmazonSQSExtendedClient(mockSqsBackend, extendedClientConfiguration)); + + SendMessageRequest messageRequest = SendMessageRequest.builder() + .queueUrl(SQS_QUEUE_URL) + .messageBody(messageBody) + .overrideConfiguration( + AwsRequestOverrideConfiguration.builder() + .addApiName(ApiName.builder().name(USER_AGENT_NAME).version(USER_AGENT_VERSION).build()) + .build()) + .build(); sqsExtended.sendMessage(messageRequest); - verify(mockS3, never()).putObject(isA(PutObjectRequest.class)); - verify(mockSqsBackend).sendMessage(eq(messageRequest)); + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(SendMessageRequest.class); + + verify(mockS3, never()).putObject(isA(PutObjectRequest.class), isA(RequestBody.class)); + verify(mockSqsBackend).sendMessage(argumentCaptor.capture()); + assertEquals(messageRequest.queueUrl(), argumentCaptor.getValue().queueUrl()); + assertEquals(messageRequest.messageBody(), argumentCaptor.getValue().messageBody()); + assertEquals(messageRequest.overrideConfiguration().get().apiNames().get(0).name(), argumentCaptor.getValue().overrideConfiguration().get().apiNames().get(0).name()); + assertEquals(messageRequest.overrideConfiguration().get().apiNames().get(0).version(), argumentCaptor.getValue().overrideConfiguration().get().apiNames().get(0).version()); } @Test @@ -120,12 +160,12 @@ public void testWhenSendMessageWithAlwaysThroughS3AndMessageIsSmallThenItIsStill String messageBody = generateStringWithLength(messageLength); ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration() .withLargePayloadSupportEnabled(mockS3, S3_BUCKET_NAME).withAlwaysThroughS3(true); - AmazonSQS sqsExtended = spy(new AmazonSQSExtendedClient(mock(AmazonSQSClient.class), extendedClientConfiguration)); + SqsClient sqsExtended = spy(new AmazonSQSExtendedClient(mock(SqsClient.class), extendedClientConfiguration)); - SendMessageRequest messageRequest = new SendMessageRequest(SQS_QUEUE_URL, messageBody); + SendMessageRequest messageRequest = SendMessageRequest.builder().queueUrl(SQS_QUEUE_URL).messageBody(messageBody).build(); sqsExtended.sendMessage(messageRequest); - verify(mockS3, times(1)).putObject(isA(PutObjectRequest.class)); + verify(mockS3, times(1)).putObject(isA(PutObjectRequest.class), isA(RequestBody.class)); } @Test @@ -135,154 +175,163 @@ public void testWhenSendMessageWithSetMessageSizeThresholdThenThresholdIsHonored ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration() .withLargePayloadSupportEnabled(mockS3, S3_BUCKET_NAME).withMessageSizeThreshold(ARBITRARY_SMALLER_THRESHOLD); - AmazonSQS sqsExtended = spy(new AmazonSQSExtendedClient(mock(AmazonSQSClient.class), extendedClientConfiguration)); + SqsClient sqsExtended = spy(new AmazonSQSExtendedClient(mock(SqsClient.class), extendedClientConfiguration)); - SendMessageRequest messageRequest = new SendMessageRequest(SQS_QUEUE_URL, messageBody); + SendMessageRequest messageRequest = SendMessageRequest.builder().queueUrl(SQS_QUEUE_URL).messageBody(messageBody).build(); sqsExtended.sendMessage(messageRequest); - verify(mockS3, times(1)).putObject(isA(PutObjectRequest.class)); + verify(mockS3, times(1)).putObject(isA(PutObjectRequest.class), isA(RequestBody.class)); } @Test public void testReceiveMessageMultipleTimesDoesNotAdditionallyAlterReceiveMessageRequestWithDeprecatedMethod() { 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()); + SqsClient sqsExtended = spy(new AmazonSQSExtendedClient(mockSqsBackend, extendedClientConfiguration)); + when(mockSqsBackend.receiveMessage(isA(ReceiveMessageRequest.class))).thenReturn(ReceiveMessageResponse.builder().build()); - ReceiveMessageRequest messageRequest = new ReceiveMessageRequest(); - ReceiveMessageRequest expectedRequest = new ReceiveMessageRequest() - .withMessageAttributeNames(AmazonSQSExtendedClient.LEGACY_RESERVED_ATTRIBUTE_NAME, SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME); + ReceiveMessageRequest messageRequest = ReceiveMessageRequest.builder().build(); + ReceiveMessageRequest expectedRequest = ReceiveMessageRequest.builder().build(); sqsExtended.receiveMessage(messageRequest); - Assert.assertEquals(expectedRequest, messageRequest); + assertEquals(expectedRequest, messageRequest); sqsExtended.receiveMessage(messageRequest); - Assert.assertEquals(expectedRequest, messageRequest); + assertEquals(expectedRequest, messageRequest); } @Test public void testWhenSendLargeMessageThenPayloadIsStoredInS3() { String messageBody = generateStringWithLength(MORE_THAN_SQS_SIZE_LIMIT); - SendMessageRequest messageRequest = new SendMessageRequest(SQS_QUEUE_URL, messageBody); + SendMessageRequest messageRequest = SendMessageRequest.builder().queueUrl(SQS_QUEUE_URL).messageBody(messageBody).build(); extendedSqsWithDefaultConfig.sendMessage(messageRequest); - verify(mockS3, times(1)).putObject(isA(PutObjectRequest.class)); + verify(mockS3, times(1)).putObject(isA(PutObjectRequest.class), isA(RequestBody.class)); } @Test public void testWhenSendLargeMessage_WithoutKMS_ThenPayloadIsStoredInS3AndKMSKeyIdIsNotUsed() { String messageBody = generateStringWithLength(MORE_THAN_SQS_SIZE_LIMIT); - SendMessageRequest messageRequest = new SendMessageRequest(SQS_QUEUE_URL, messageBody); + SendMessageRequest messageRequest = SendMessageRequest.builder().queueUrl(SQS_QUEUE_URL).messageBody(messageBody).build(); extendedSqsWithDefaultConfig.sendMessage(messageRequest); ArgumentCaptor putObjectRequestArgumentCaptor = ArgumentCaptor.forClass(PutObjectRequest.class); - verify(mockS3, times(1)).putObject(putObjectRequestArgumentCaptor.capture()); + ArgumentCaptor requestBodyArgumentCaptor = ArgumentCaptor.forClass(RequestBody.class); + verify(mockS3, times(1)).putObject(putObjectRequestArgumentCaptor.capture(), requestBodyArgumentCaptor.capture()); - Assert.assertNull(putObjectRequestArgumentCaptor.getValue().getSSEAwsKeyManagementParams()); - Assert.assertEquals(putObjectRequestArgumentCaptor.getValue().getBucketName(), S3_BUCKET_NAME); + Assert.assertNull(putObjectRequestArgumentCaptor.getValue().serverSideEncryption()); + assertEquals(putObjectRequestArgumentCaptor.getValue().bucket(), 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); + SendMessageRequest messageRequest = SendMessageRequest.builder().queueUrl(SQS_QUEUE_URL).messageBody(messageBody).build(); extendedSqsWithCustomKMS.sendMessage(messageRequest); ArgumentCaptor putObjectRequestArgumentCaptor = ArgumentCaptor.forClass(PutObjectRequest.class); - verify(mockS3, times(1)).putObject(putObjectRequestArgumentCaptor.capture()); + ArgumentCaptor requestBodyArgumentCaptor = ArgumentCaptor.forClass(RequestBody.class); + verify(mockS3, times(1)).putObject(putObjectRequestArgumentCaptor.capture(), requestBodyArgumentCaptor.capture()); - Assert.assertEquals(putObjectRequestArgumentCaptor.getValue().getSSEAwsKeyManagementParams() - .getAwsKmsKeyId(), S3_SERVER_SIDE_ENCRYPTION_KMS_KEY_ID); - Assert.assertEquals(putObjectRequestArgumentCaptor.getValue().getBucketName(), S3_BUCKET_NAME); + assertEquals(putObjectRequestArgumentCaptor.getValue().ssekmsKeyId(), S3_SERVER_SIDE_ENCRYPTION_KMS_KEY_ID); + assertEquals(putObjectRequestArgumentCaptor.getValue().bucket(), 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); + SendMessageRequest messageRequest = SendMessageRequest.builder().queueUrl(SQS_QUEUE_URL).messageBody(messageBody).build(); extendedSqsWithDefaultKMS.sendMessage(messageRequest); ArgumentCaptor putObjectRequestArgumentCaptor = ArgumentCaptor.forClass(PutObjectRequest.class); - verify(mockS3, times(1)).putObject(putObjectRequestArgumentCaptor.capture()); + ArgumentCaptor requestBodyArgumentCaptor = ArgumentCaptor.forClass(RequestBody.class); + verify(mockS3, times(1)).putObject(putObjectRequestArgumentCaptor.capture(), requestBodyArgumentCaptor.capture()); - Assert.assertTrue(putObjectRequestArgumentCaptor.getValue().getSSEAwsKeyManagementParams() != null && - putObjectRequestArgumentCaptor.getValue().getSSEAwsKeyManagementParams().getAwsKmsKeyId() == null); - Assert.assertEquals(putObjectRequestArgumentCaptor.getValue().getBucketName(), S3_BUCKET_NAME); + Assert.assertTrue(putObjectRequestArgumentCaptor.getValue().serverSideEncryption() != null && + putObjectRequestArgumentCaptor.getValue().ssekmsKeyId() == null); + assertEquals(putObjectRequestArgumentCaptor.getValue().bucket(), 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); + String messageBody = generateStringWithLength(MORE_THAN_SQS_SIZE_LIMIT); + SendMessageRequest messageRequest = SendMessageRequest.builder().queueUrl(SQS_QUEUE_URL).messageBody(messageBody).build(); 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)); + Map attributes = sendMessageRequestCaptor.getValue().messageAttributes(); + Assert.assertTrue(attributes.containsKey(AmazonSQSExtendedClient.LEGACY_RESERVED_ATTRIBUTE_NAME)); + Assert.assertFalse(attributes.containsKey(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); + String messageBody = generateStringWithLength(MORE_THAN_SQS_SIZE_LIMIT); + SendMessageRequest messageRequest = SendMessageRequest.builder().queueUrl(SQS_QUEUE_URL).messageBody(messageBody).build(); 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)); + Map attributes = sendMessageRequestCaptor.getValue().messageAttributes(); + Assert.assertTrue(attributes.containsKey(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME)); + Assert.assertFalse(attributes.containsKey(AmazonSQSExtendedClient.LEGACY_RESERVED_ATTRIBUTE_NAME)); } @Test public void testWhenSendSmallMessageThenS3IsNotUsed() { - int messageLength = SQS_SIZE_LIMIT; - String messageBody = generateStringWithLength(messageLength); + String messageBody = generateStringWithLength(SQS_SIZE_LIMIT); - SendMessageRequest messageRequest = new SendMessageRequest(SQS_QUEUE_URL, messageBody); + SendMessageRequest messageRequest = SendMessageRequest.builder().queueUrl(SQS_QUEUE_URL).messageBody(messageBody).build(); extendedSqsWithDefaultConfig.sendMessage(messageRequest); - verify(mockS3, never()).putObject(isA(PutObjectRequest.class)); + verify(mockS3, never()).putObject(isA(PutObjectRequest.class), isA(RequestBody.class)); } @Test public void testWhenSendMessageWithLargePayloadSupportDisabledThenS3IsNotUsedAndSqsBackendIsResponsibleToFailIt() { - int messageLength = MORE_THAN_SQS_SIZE_LIMIT; - String messageBody = generateStringWithLength(messageLength); + String messageBody = generateStringWithLength(MORE_THAN_SQS_SIZE_LIMIT); ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration() .withPayloadSupportDisabled(); - AmazonSQS sqsExtended = spy(new AmazonSQSExtendedClient(mockSqsBackend, extendedClientConfiguration)); - - SendMessageRequest messageRequest = new SendMessageRequest(SQS_QUEUE_URL, messageBody); + SqsClient sqsExtended = spy(new AmazonSQSExtendedClient(mockSqsBackend, extendedClientConfiguration)); + + SendMessageRequest messageRequest = SendMessageRequest.builder() + .queueUrl(SQS_QUEUE_URL) + .messageBody(messageBody) + .overrideConfiguration( + AwsRequestOverrideConfiguration.builder() + .addApiName(ApiName.builder().name(USER_AGENT_NAME).version(USER_AGENT_VERSION).build()) + .build()) + .build(); sqsExtended.sendMessage(messageRequest); - verify(mockS3, never()).putObject(isA(PutObjectRequest.class)); - verify(mockSqsBackend).sendMessage(eq(messageRequest)); + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(SendMessageRequest.class); + + verify(mockS3, never()).putObject(isA(PutObjectRequest.class), isA(RequestBody.class)); + verify(mockSqsBackend).sendMessage(argumentCaptor.capture()); + assertEquals(messageRequest.queueUrl(), argumentCaptor.getValue().queueUrl()); + assertEquals(messageRequest.messageBody(), argumentCaptor.getValue().messageBody()); + assertEquals(messageRequest.overrideConfiguration().get().apiNames().get(0).name(), argumentCaptor.getValue().overrideConfiguration().get().apiNames().get(0).name()); + assertEquals(messageRequest.overrideConfiguration().get().apiNames().get(0).version(), argumentCaptor.getValue().overrideConfiguration().get().apiNames().get(0).version()); } @Test public void testWhenSendMessageWithAlwaysThroughS3AndMessageIsSmallThenItIsStillStoredInS3() { - int messageLength = LESS_THAN_SQS_SIZE_LIMIT; - String messageBody = generateStringWithLength(messageLength); + String messageBody = generateStringWithLength(LESS_THAN_SQS_SIZE_LIMIT); ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration() .withPayloadSupportEnabled(mockS3, S3_BUCKET_NAME).withAlwaysThroughS3(true); - AmazonSQS sqsExtended = spy(new AmazonSQSExtendedClient(mock(AmazonSQSClient.class), extendedClientConfiguration)); + SqsClient sqsExtended = spy(new AmazonSQSExtendedClient(mock(SqsClient.class), extendedClientConfiguration)); - SendMessageRequest messageRequest = new SendMessageRequest(SQS_QUEUE_URL, messageBody); + SendMessageRequest messageRequest = SendMessageRequest.builder().queueUrl(SQS_QUEUE_URL).messageBody(messageBody).build(); sqsExtended.sendMessage(messageRequest); - verify(mockS3, times(1)).putObject(isA(PutObjectRequest.class)); + verify(mockS3, times(1)).putObject(isA(PutObjectRequest.class), isA(RequestBody.class)); } @Test @@ -292,27 +341,26 @@ public void testWhenSendMessageWithSetMessageSizeThresholdThenThresholdIsHonored ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration() .withPayloadSupportEnabled(mockS3, S3_BUCKET_NAME).withPayloadSizeThreshold(ARBITRARY_SMALLER_THRESHOLD); - AmazonSQS sqsExtended = spy(new AmazonSQSExtendedClient(mock(AmazonSQSClient.class), extendedClientConfiguration)); + SqsClient sqsExtended = spy(new AmazonSQSExtendedClient(mock(SqsClient.class), extendedClientConfiguration)); - SendMessageRequest messageRequest = new SendMessageRequest(SQS_QUEUE_URL, messageBody); + SendMessageRequest messageRequest = SendMessageRequest.builder().queueUrl(SQS_QUEUE_URL).messageBody(messageBody).build(); sqsExtended.sendMessage(messageRequest); - verify(mockS3, times(1)).putObject(isA(PutObjectRequest.class)); + verify(mockS3, times(1)).putObject(isA(PutObjectRequest.class), isA(RequestBody.class)); } @Test public void testReceiveMessageMultipleTimesDoesNotAdditionallyAlterReceiveMessageRequest() { - when(mockSqsBackend.receiveMessage(isA(ReceiveMessageRequest.class))).thenReturn(new ReceiveMessageResult()); + when(mockSqsBackend.receiveMessage(isA(ReceiveMessageRequest.class))).thenReturn(ReceiveMessageResponse.builder().build()); - ReceiveMessageRequest messageRequest = new ReceiveMessageRequest(); + ReceiveMessageRequest messageRequest = ReceiveMessageRequest.builder().build(); - ReceiveMessageRequest expectedRequest = new ReceiveMessageRequest() - .withMessageAttributeNames(AmazonSQSExtendedClient.RESERVED_ATTRIBUTE_NAMES); + ReceiveMessageRequest expectedRequest = ReceiveMessageRequest.builder().build(); extendedSqsWithDefaultConfig.receiveMessage(messageRequest); - Assert.assertEquals(expectedRequest, messageRequest); + assertEquals(expectedRequest, messageRequest); extendedSqsWithDefaultConfig.receiveMessage(messageRequest); - Assert.assertEquals(expectedRequest, messageRequest); + assertEquals(expectedRequest, messageRequest); } @Test @@ -329,17 +377,19 @@ public void testReceiveMessage_when_MessageIsLarge_ReservedAttributeUsed() throw 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)); + Message message = Message.builder() + .messageAttributes(ImmutableMap.of(expectedMessageAttributeName, MessageAttributeValue.builder().build())) + .body(expectedMessage) + .build(); + when(mockSqsBackend.receiveMessage(isA(ReceiveMessageRequest.class))).thenReturn(ReceiveMessageResponse.builder().messages(message).build()); + + ReceiveMessageRequest messageRequest = ReceiveMessageRequest.builder().build(); + ReceiveMessageResponse actualReceiveMessageResponse = extendedSqsWithDefaultConfig.receiveMessage(messageRequest); + Message actualMessage = actualReceiveMessageResponse.messages().get(0); + + assertEquals(expectedMessage, actualMessage.body()); + Assert.assertTrue(actualMessage.messageAttributes().containsKey(expectedMessageAttributeName)); + Assert.assertFalse(actualMessage.messageAttributes().keySet().containsAll(AmazonSQSExtendedClient.RESERVED_ATTRIBUTE_NAMES)); verifyZeroInteractions(mockS3); } @@ -363,33 +413,33 @@ public void testWhenMessageBatchIsSentThenOnlyMessagesLargerThanThresholdAreStor List batchEntries = new ArrayList(); for (int i = 0; i < 10; i++) { - SendMessageBatchRequestEntry entry = new SendMessageBatchRequestEntry(); int messageLength = messageLengthForCounter[i]; String messageBody = generateStringWithLength(messageLength); - entry.setMessageBody(messageBody); - entry.setId("entry_" + i); + SendMessageBatchRequestEntry entry = SendMessageBatchRequestEntry.builder() + .id("entry_" + i) + .messageBody(messageBody) + .build(); batchEntries.add(entry); } - SendMessageBatchRequest batchRequest = new SendMessageBatchRequest(SQS_QUEUE_URL, batchEntries); + SendMessageBatchRequest batchRequest = SendMessageBatchRequest.builder().queueUrl(SQS_QUEUE_URL).entries(batchEntries).build(); extendedSqsWithDefaultConfig.sendMessageBatch(batchRequest); // There should be 8 puts for the 8 messages above the threshold - verify(mockS3, times(8)).putObject(isA(PutObjectRequest.class)); + verify(mockS3, times(8)).putObject(isA(PutObjectRequest.class), isA(RequestBody.class)); } @Test public void testWhenSmallMessageIsSentThenNoAttributeIsAdded() { - int messageLength = LESS_THAN_SQS_SIZE_LIMIT; - String messageBody = generateStringWithLength(messageLength); + String messageBody = generateStringWithLength(LESS_THAN_SQS_SIZE_LIMIT); - SendMessageRequest messageRequest = new SendMessageRequest(SQS_QUEUE_URL, messageBody); + SendMessageRequest messageRequest = SendMessageRequest.builder().queueUrl(SQS_QUEUE_URL).messageBody(messageBody).build(); extendedSqsWithDefaultConfig.sendMessage(messageRequest); ArgumentCaptor sendMessageRequestCaptor = ArgumentCaptor.forClass(SendMessageRequest.class); verify(mockSqsBackend).sendMessage(sendMessageRequestCaptor.capture()); - Map attributes = sendMessageRequestCaptor.getValue().getMessageAttributes(); + Map attributes = sendMessageRequestCaptor.getValue().messageAttributes(); Assert.assertTrue(attributes.isEmpty()); } @@ -398,71 +448,22 @@ public void testWhenLargeMessageIsSentThenAttributeWithPayloadSizeIsAdded() { int messageLength = MORE_THAN_SQS_SIZE_LIMIT; String messageBody = generateStringWithLength(messageLength); - SendMessageRequest messageRequest = new SendMessageRequest(SQS_QUEUE_URL, messageBody); + SendMessageRequest messageRequest = SendMessageRequest.builder().queueUrl(SQS_QUEUE_URL).messageBody(messageBody).build(); extendedSqsWithDefaultConfig.sendMessage(messageRequest); ArgumentCaptor sendMessageRequestCaptor = ArgumentCaptor.forClass(SendMessageRequest.class); verify(mockSqsBackend).sendMessage(sendMessageRequestCaptor.capture()); - Map attributes = sendMessageRequestCaptor.getValue().getMessageAttributes(); - 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 testWhenIgnorePayloadNotFoundIsSentThenNotFoundKeysInS3AreDeletedInSQS() { - ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration() - .withPayloadSupportEnabled(mockS3, S3_BUCKET_NAME).withIgnorePayloadNotFound(true); - - AmazonServiceException mockException = mock(AmazonServiceException.class); - when(mockException.getErrorCode()).thenReturn("NoSuchKey"); - - Message message = new Message().addMessageAttributesEntry(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME, mock(MessageAttributeValue.class)); - String pointer = new PayloadS3Pointer(S3_BUCKET_NAME, "S3Key").toJson(); - message.setBody(pointer); - message.setReceiptHandle("receipt-handle"); - - when(mockSqsBackend.receiveMessage(isA(ReceiveMessageRequest.class))).thenReturn(new ReceiveMessageResult().withMessages(message)); - doThrow(mockException).when(mockS3).getObject(any(GetObjectRequest.class)); - - AmazonSQS sqsExtended = spy(new AmazonSQSExtendedClient(mockSqsBackend, extendedClientConfiguration)); - ReceiveMessageRequest messageRequest = new ReceiveMessageRequest().withQueueUrl(SQS_QUEUE_URL); - ReceiveMessageResult actualReceiveMessageResult = sqsExtended.receiveMessage(messageRequest); - Assert.assertTrue(actualReceiveMessageResult.getMessages().isEmpty()); - - ArgumentCaptor deleteMessageRequestArgumentCaptor = ArgumentCaptor.forClass(DeleteMessageRequest.class); - verify(mockSqsBackend).deleteMessage(deleteMessageRequestArgumentCaptor.capture()); - Assert.assertEquals(SQS_QUEUE_URL, deleteMessageRequestArgumentCaptor.getValue().getQueueUrl()); - Assert.assertEquals("receipt-handle", deleteMessageRequestArgumentCaptor.getValue().getReceiptHandle()); - } - - @Test - public void testWhenIgnorePayloadNotFoundIsNotSentThenNotFoundKeysInS3AreNotDeletedInSQS() { - AmazonServiceException mockException = mock(AmazonServiceException.class); - when(mockException.getErrorCode()).thenReturn("NoSuchKey"); - - Message message = new Message().addMessageAttributesEntry(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME, mock(MessageAttributeValue.class)); - String pointer = new PayloadS3Pointer(S3_BUCKET_NAME, "S3Key").toJson(); - message.setBody(pointer); - - when(mockSqsBackend.receiveMessage(isA(ReceiveMessageRequest.class))).thenReturn(new ReceiveMessageResult().withMessages(message)); - - doThrow(mockException).when(mockS3).getObject(any(GetObjectRequest.class)); - ReceiveMessageRequest messageRequest = new ReceiveMessageRequest(); - - try { - extendedSqsWithDefaultConfig.receiveMessage(messageRequest); - Assert.fail("exception should have been thrown"); - } catch (AmazonServiceException e) { - verify(mockSqsBackend, never()).deleteMessage(any(DeleteMessageRequest.class)); - } + Map attributes = sendMessageRequestCaptor.getValue().messageAttributes(); + assertEquals("Number", attributes.get(AmazonSQSExtendedClient.LEGACY_RESERVED_ATTRIBUTE_NAME).dataType()); + assertEquals(messageLength, (int) Integer.parseInt(attributes.get(AmazonSQSExtendedClient.LEGACY_RESERVED_ATTRIBUTE_NAME).stringValue())); } @Test public void testDefaultExtendedClientDeletesSmallMessage() { // given String receiptHandle = UUID.randomUUID().toString(); - DeleteMessageRequest deleteRequest = new DeleteMessageRequest(SQS_QUEUE_URL, receiptHandle); + DeleteMessageRequest deleteRequest = DeleteMessageRequest.builder().queueUrl(SQS_QUEUE_URL).receiptHandle(receiptHandle).build(); // when extendedSqsWithDefaultConfig.deleteMessage(deleteRequest); @@ -470,7 +471,7 @@ public void testDefaultExtendedClientDeletesSmallMessage() { // then ArgumentCaptor deleteRequestCaptor = ArgumentCaptor.forClass(DeleteMessageRequest.class); verify(mockSqsBackend).deleteMessage(deleteRequestCaptor.capture()); - Assert.assertEquals(receiptHandle, deleteRequestCaptor.getValue().getReceiptHandle()); + assertEquals(receiptHandle, deleteRequestCaptor.getValue().receiptHandle()); verifyZeroInteractions(mockS3); } @@ -480,7 +481,7 @@ public void testDefaultExtendedClientDeletesObjectS3UponMessageDelete() { String randomS3Key = UUID.randomUUID().toString(); String originalReceiptHandle = UUID.randomUUID().toString(); String largeMessageReceiptHandle = getLargeReceiptHandle(randomS3Key, originalReceiptHandle); - DeleteMessageRequest deleteRequest = new DeleteMessageRequest(SQS_QUEUE_URL, largeMessageReceiptHandle); + DeleteMessageRequest deleteRequest = DeleteMessageRequest.builder().queueUrl(SQS_QUEUE_URL).receiptHandle(largeMessageReceiptHandle).build(); // when extendedSqsWithDefaultConfig.deleteMessage(deleteRequest); @@ -488,8 +489,9 @@ public void testDefaultExtendedClientDeletesObjectS3UponMessageDelete() { // 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)); + assertEquals(originalReceiptHandle, deleteRequestCaptor.getValue().receiptHandle()); + DeleteObjectRequest deleteObjectRequest = DeleteObjectRequest.builder().bucket(S3_BUCKET_NAME).key(randomS3Key).build(); + verify(mockS3).deleteObject(eq(deleteObjectRequest)); } @Test @@ -498,12 +500,12 @@ public void testExtendedClientConfiguredDoesNotDeleteObjectFromS3UponDelete() { String randomS3Key = UUID.randomUUID().toString(); String originalReceiptHandle = UUID.randomUUID().toString(); String largeMessageReceiptHandle = getLargeReceiptHandle(randomS3Key, originalReceiptHandle); - DeleteMessageRequest deleteRequest = new DeleteMessageRequest(SQS_QUEUE_URL, largeMessageReceiptHandle); + DeleteMessageRequest deleteRequest = DeleteMessageRequest.builder().queueUrl(SQS_QUEUE_URL).receiptHandle(largeMessageReceiptHandle).build(); ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration() .withPayloadSupportEnabled(mockS3, S3_BUCKET_NAME, false); - AmazonSQS extendedSqs = spy(new AmazonSQSExtendedClient(mockSqsBackend, extendedClientConfiguration)); + SqsClient extendedSqs = spy(new AmazonSQSExtendedClient(mockSqsBackend, extendedClientConfiguration)); // when extendedSqs.deleteMessage(deleteRequest); @@ -511,7 +513,7 @@ public void testExtendedClientConfiguredDoesNotDeleteObjectFromS3UponDelete() { // then ArgumentCaptor deleteRequestCaptor = ArgumentCaptor.forClass(DeleteMessageRequest.class); verify(mockSqsBackend).deleteMessage(deleteRequestCaptor.capture()); - Assert.assertEquals(originalReceiptHandle, deleteRequestCaptor.getValue().getReceiptHandle()); + assertEquals(originalReceiptHandle, deleteRequestCaptor.getValue().receiptHandle()); verifyZeroInteractions(mockS3); } @@ -519,16 +521,25 @@ public void testExtendedClientConfiguredDoesNotDeleteObjectFromS3UponDelete() { public void testExtendedClientConfiguredDoesNotDeletesObjectsFromS3UponDeleteBatch() { // given int batchSize = 10; - DeleteMessageBatchRequest deleteBatchRequest = generateLargeDeleteBatchRequest(batchSize); + List originalReceiptHandles = IntStream.range(0, batchSize) + .mapToObj(i -> UUID.randomUUID().toString()) + .collect(Collectors.toList()); + DeleteMessageBatchRequest deleteBatchRequest = generateLargeDeleteBatchRequest(originalReceiptHandles); ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration() .withPayloadSupportEnabled(mockS3, S3_BUCKET_NAME, false); - AmazonSQS extendedSqs = spy(new AmazonSQSExtendedClient(mockSqsBackend, extendedClientConfiguration)); + SqsClient extendedSqs = spy(new AmazonSQSExtendedClient(mockSqsBackend, extendedClientConfiguration)); // when extendedSqs.deleteMessageBatch(deleteBatchRequest); // then - verify(mockSqsBackend, times(1)).deleteMessageBatch(any(DeleteMessageBatchRequest.class)); + ArgumentCaptor deleteBatchRequestCaptor = ArgumentCaptor.forClass(DeleteMessageBatchRequest.class); + verify(mockSqsBackend, times(1)).deleteMessageBatch(deleteBatchRequestCaptor.capture()); + DeleteMessageBatchRequest request = deleteBatchRequestCaptor.getValue(); + assertEquals(originalReceiptHandles.size(), request.entries().size()); + IntStream.range(0, originalReceiptHandles.size()).forEach(i -> assertEquals( + originalReceiptHandles.get(i), + request.entries().get(i).receiptHandle())); verifyZeroInteractions(mockS3); } @@ -536,59 +547,80 @@ public void testExtendedClientConfiguredDoesNotDeletesObjectsFromS3UponDeleteBat public void testDefaultExtendedClientDeletesObjectsFromS3UponDeleteBatch() { // given int batchSize = 10; - DeleteMessageBatchRequest deleteBatchRequest = generateLargeDeleteBatchRequest(batchSize); + List originalReceiptHandles = IntStream.range(0, batchSize) + .mapToObj(i -> UUID.randomUUID().toString()) + .collect(Collectors.toList()); + DeleteMessageBatchRequest deleteBatchRequest = generateLargeDeleteBatchRequest(originalReceiptHandles); // when extendedSqsWithDefaultConfig.deleteMessageBatch(deleteBatchRequest); // then - verify(mockSqsBackend, times(1)).deleteMessageBatch(any(DeleteMessageBatchRequest.class)); - verify(mockS3, times(batchSize)).deleteObject(eq(S3_BUCKET_NAME), anyString()); + ArgumentCaptor deleteBatchRequestCaptor = ArgumentCaptor.forClass(DeleteMessageBatchRequest.class); + verify(mockSqsBackend, times(1)).deleteMessageBatch(deleteBatchRequestCaptor.capture()); + DeleteMessageBatchRequest request = deleteBatchRequestCaptor.getValue(); + assertEquals(originalReceiptHandles.size(), request.entries().size()); + IntStream.range(0, originalReceiptHandles.size()).forEach(i -> assertEquals( + originalReceiptHandles.get(i), + request.entries().get(i).receiptHandle())); + verify(mockS3, times(batchSize)).deleteObject(any(DeleteObjectRequest.class)); } @Test public void testWhenSendMessageWIthCannedAccessControlListDefined() { - CannedAccessControlList expected = CannedAccessControlList.BucketOwnerFullControl; + ObjectCannedACL expected = ObjectCannedACL.BUCKET_OWNER_FULL_CONTROL; String messageBody = generateStringWithLength(MORE_THAN_SQS_SIZE_LIMIT); ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration() - .withPayloadSupportEnabled(mockS3, S3_BUCKET_NAME).withCannedAccessControlList(expected); - AmazonSQS sqsExtended = spy(new AmazonSQSExtendedClient(mockSqsBackend, extendedClientConfiguration)); + .withPayloadSupportEnabled(mockS3, S3_BUCKET_NAME).withObjectCannedACL(expected); + SqsClient sqsExtended = spy(new AmazonSQSExtendedClient(mockSqsBackend, extendedClientConfiguration)); - SendMessageRequest messageRequest = new SendMessageRequest(SQS_QUEUE_URL, messageBody); + SendMessageRequest messageRequest = SendMessageRequest.builder().queueUrl(SQS_QUEUE_URL).messageBody(messageBody).build(); sqsExtended.sendMessage(messageRequest); ArgumentCaptor captor = ArgumentCaptor.forClass(PutObjectRequest.class); - verify(mockS3).putObject(captor.capture()); + verify(mockS3).putObject(captor.capture(), any(RequestBody.class)); - Assert.assertEquals(expected, captor.getValue().getCannedAcl()); + assertEquals(expected, captor.getValue().acl()); } 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); + Message message = Message.builder() + .messageAttributes(ImmutableMap.of(reservedAttributeName, MessageAttributeValue.builder().build())) + .body(pointer) + .build(); String expectedMessage = "LargeMessage"; - S3Object s3Object = new S3Object(); - s3Object.setObjectContent(new StringInputStream(expectedMessage)); - when(mockSqsBackend.receiveMessage(isA(ReceiveMessageRequest.class))).thenReturn(new ReceiveMessageResult().withMessages(message)); + GetObjectRequest getObjectRequest = GetObjectRequest.builder() + .bucket(S3_BUCKET_NAME) + .key("S3Key") + .build(); + + ResponseInputStream s3Object = new ResponseInputStream(GetObjectResponse.builder().build(), AbortableInputStream.create(new StringInputStream(expectedMessage))); +// S3Object s3Object = S3Object.builder().build(); +// s3Object.setObjectContent(new StringInputStream(expectedMessage)); + when(mockSqsBackend.receiveMessage(isA(ReceiveMessageRequest.class))).thenReturn( + ReceiveMessageResponse.builder().messages(message).build()); when(mockS3.getObject(isA(GetObjectRequest.class))).thenReturn(s3Object); - ReceiveMessageRequest messageRequest = new ReceiveMessageRequest(); - ReceiveMessageResult actualReceiveMessageResult = extendedSqsWithDefaultConfig.receiveMessage(messageRequest); - Message actualMessage = actualReceiveMessageResult.getMessages().get(0); + ReceiveMessageRequest messageRequest = ReceiveMessageRequest.builder().build(); + ReceiveMessageResponse actualReceiveMessageResponse = extendedSqsWithDefaultConfig.receiveMessage(messageRequest); + Message actualMessage = actualReceiveMessageResponse.messages().get(0); - Assert.assertEquals(expectedMessage, actualMessage.getBody()); - Assert.assertFalse(actualMessage.getMessageAttributes().keySet().containsAll(AmazonSQSExtendedClient.RESERVED_ATTRIBUTE_NAMES)); + assertEquals(expectedMessage, actualMessage.body()); + Assert.assertFalse(actualMessage.messageAttributes().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())) + private DeleteMessageBatchRequest generateLargeDeleteBatchRequest(List originalReceiptHandles) { + List deleteEntries = IntStream.range(0, originalReceiptHandles.size()) + .mapToObj(i -> DeleteMessageBatchRequestEntry.builder() + .id(Integer.toString(i)) + .receiptHandle(getSampleLargeReceiptHandle(originalReceiptHandles.get(i))) + .build()) .collect(Collectors.toList()); - return new DeleteMessageBatchRequest(SQS_QUEUE_URL, deleteEntries); + return DeleteMessageBatchRequest.builder().queueUrl(SQS_QUEUE_URL).entries(deleteEntries).build(); } private String getLargeReceiptHandle(String s3Key, String originalReceiptHandle) { @@ -597,8 +629,8 @@ private String getLargeReceiptHandle(String s3Key, String originalReceiptHandle) + s3Key + SQSExtendedClientConstants.S3_KEY_MARKER + originalReceiptHandle; } - private String getSampleLargeReceiptHandle() { - return getLargeReceiptHandle(UUID.randomUUID().toString(), UUID.randomUUID().toString()); + private String getSampleLargeReceiptHandle(String originalReceiptHandle) { + return getLargeReceiptHandle(UUID.randomUUID().toString(), originalReceiptHandle); } 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 1ff48be..df5e0c5 100644 --- a/src/test/java/com/amazon/sqs/javamessaging/ExtendedClientConfigurationTest.java +++ b/src/test/java/com/amazon/sqs/javamessaging/ExtendedClientConfigurationTest.java @@ -15,13 +15,13 @@ package com.amazon.sqs.javamessaging; -import com.amazonaws.services.s3.AmazonS3; -import com.amazonaws.services.s3.model.PutObjectRequest; -import com.amazonaws.services.s3.model.SSEAwsKeyManagementParams; - import org.junit.Assert; -import org.junit.Before; import org.junit.Test; +import software.amazon.awssdk.services.s3.S3Client; +import software.amazon.awssdk.services.s3.model.PutObjectRequest; +import software.amazon.payloadoffloading.ServerSideEncryptionFactory; +import software.amazon.payloadoffloading.ServerSideEncryptionStrategy; + import static org.mockito.Mockito.*; /** @@ -31,10 +31,11 @@ public class ExtendedClientConfigurationTest { private static String s3BucketName = "test-bucket-name"; private static String s3ServerSideEncryptionKMSKeyId = "test-customer-managed-kms-key-id"; + private static ServerSideEncryptionStrategy serverSideEncryptionStrategy = ServerSideEncryptionFactory.customerKey(s3ServerSideEncryptionKMSKeyId); @Test public void testCopyConstructor() { - AmazonS3 s3 = mock(AmazonS3.class); + S3Client s3 = mock(S3Client.class); boolean alwaysThroughS3 = true; int messageSizeThreshold = 500; @@ -44,13 +45,13 @@ public void testCopyConstructor() { extendedClientConfig.withPayloadSupportEnabled(s3, s3BucketName, doesCleanupS3Payload) .withAlwaysThroughS3(alwaysThroughS3).withPayloadSizeThreshold(messageSizeThreshold) - .withSSEAwsKeyManagementParams(new SSEAwsKeyManagementParams(s3ServerSideEncryptionKMSKeyId)); + .withServerSideEncryption(serverSideEncryptionStrategy); ExtendedClientConfiguration newExtendedClientConfig = new ExtendedClientConfiguration(extendedClientConfig); - Assert.assertEquals(s3, newExtendedClientConfig.getAmazonS3Client()); + Assert.assertEquals(s3, newExtendedClientConfig.getS3Client()); Assert.assertEquals(s3BucketName, newExtendedClientConfig.getS3BucketName()); - Assert.assertEquals(s3ServerSideEncryptionKMSKeyId, newExtendedClientConfig.getSSEAwsKeyManagementParams().getAwsKmsKeyId()); + Assert.assertEquals(serverSideEncryptionStrategy, newExtendedClientConfig.getServerSideEncryptionStrategy()); Assert.assertTrue(newExtendedClientConfig.isPayloadSupportEnabled()); Assert.assertEquals(doesCleanupS3Payload, newExtendedClientConfig.doesCleanupS3Payload()); Assert.assertEquals(alwaysThroughS3, newExtendedClientConfig.isAlwaysThroughS3()); @@ -61,13 +62,13 @@ public void testCopyConstructor() { @Test public void testLargePayloadSupportEnabledWithDefaultDeleteFromS3Config() { - AmazonS3 s3 = mock(AmazonS3.class); + S3Client s3 = mock(S3Client.class); ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration(); extendedClientConfiguration.setPayloadSupportEnabled(s3, s3BucketName); Assert.assertTrue(extendedClientConfiguration.isPayloadSupportEnabled()); Assert.assertTrue(extendedClientConfiguration.doesCleanupS3Payload()); - Assert.assertNotNull(extendedClientConfiguration.getAmazonS3Client()); + Assert.assertNotNull(extendedClientConfiguration.getS3Client()); Assert.assertEquals(s3BucketName, extendedClientConfiguration.getS3BucketName()); } @@ -75,33 +76,33 @@ public void testLargePayloadSupportEnabledWithDefaultDeleteFromS3Config() { @Test public void testLargePayloadSupportEnabledWithDeleteFromS3Enabled() { - AmazonS3 s3 = mock(AmazonS3.class); + S3Client s3 = mock(S3Client.class); ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration(); extendedClientConfiguration.setPayloadSupportEnabled(s3, s3BucketName, true); Assert.assertTrue(extendedClientConfiguration.isPayloadSupportEnabled()); Assert.assertTrue(extendedClientConfiguration.doesCleanupS3Payload()); - Assert.assertNotNull(extendedClientConfiguration.getAmazonS3Client()); + Assert.assertNotNull(extendedClientConfiguration.getS3Client()); Assert.assertEquals(s3BucketName, extendedClientConfiguration.getS3BucketName()); } @Test public void testLargePayloadSupportEnabledWithDeleteFromS3Disabled() { - AmazonS3 s3 = mock(AmazonS3.class); + S3Client s3 = mock(S3Client.class); ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration(); extendedClientConfiguration.setPayloadSupportEnabled(s3, s3BucketName, false); Assert.assertTrue(extendedClientConfiguration.isPayloadSupportEnabled()); Assert.assertFalse(extendedClientConfiguration.doesCleanupS3Payload()); - Assert.assertNotNull(extendedClientConfiguration.getAmazonS3Client()); + Assert.assertNotNull(extendedClientConfiguration.getS3Client()); Assert.assertEquals(s3BucketName, extendedClientConfiguration.getS3BucketName()); } @Test public void testCopyConstructorDeprecated() { - AmazonS3 s3 = mock(AmazonS3.class); - when(s3.putObject(isA(PutObjectRequest.class))).thenReturn(null); + S3Client s3 = mock(S3Client.class); +// when(s3.putObject(isA(PutObjectRequest.class))).thenReturn(null); boolean alwaysThroughS3 = true; int messageSizeThreshold = 500; @@ -113,7 +114,7 @@ public void testCopyConstructorDeprecated() { ExtendedClientConfiguration newExtendedClientConfig = new ExtendedClientConfiguration(extendedClientConfig); - Assert.assertEquals(s3, newExtendedClientConfig.getAmazonS3Client()); + Assert.assertEquals(s3, newExtendedClientConfig.getS3Client()); Assert.assertEquals(s3BucketName, newExtendedClientConfig.getS3BucketName()); Assert.assertTrue(newExtendedClientConfig.isLargePayloadSupportEnabled()); Assert.assertEquals(alwaysThroughS3, newExtendedClientConfig.isAlwaysThroughS3()); @@ -125,14 +126,14 @@ public void testCopyConstructorDeprecated() { @Test public void testLargePayloadSupportEnabled() { - AmazonS3 s3 = mock(AmazonS3.class); - when(s3.putObject(isA(PutObjectRequest.class))).thenReturn(null); + S3Client s3 = mock(S3Client.class); +// when(s3.putObject(isA(PutObjectRequest.class))).thenReturn(null); ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration(); extendedClientConfiguration.setLargePayloadSupportEnabled(s3, s3BucketName); Assert.assertTrue(extendedClientConfiguration.isLargePayloadSupportEnabled()); - Assert.assertNotNull(extendedClientConfiguration.getAmazonS3Client()); + Assert.assertNotNull(extendedClientConfiguration.getS3Client()); Assert.assertEquals(s3BucketName, extendedClientConfiguration.getS3BucketName()); } @@ -140,16 +141,16 @@ public void testLargePayloadSupportEnabled() { @Test public void testDisableLargePayloadSupport() { - AmazonS3 s3 = mock(AmazonS3.class); - when(s3.putObject(isA(PutObjectRequest.class))).thenReturn(null); + S3Client s3 = mock(S3Client.class); +// when(s3.putObject(isA(PutObjectRequest.class))).thenReturn(null); ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration(); extendedClientConfiguration.setLargePayloadSupportDisabled(); - Assert.assertNull(extendedClientConfiguration.getAmazonS3Client()); + Assert.assertNull(extendedClientConfiguration.getS3Client()); Assert.assertNull(extendedClientConfiguration.getS3BucketName()); - verify(s3, never()).putObject(isA(PutObjectRequest.class)); +// verify(s3, never()).putObject(isA(PutObjectRequest.class)); } @Test