forked from awslabs/amazon-sqs-java-extended-client-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAmazonSQSExtendedClient.java
1014 lines (921 loc) · 50.2 KB
/
AmazonSQSExtendedClient.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2010-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package com.amazon.sqs.javamessaging;
import java.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.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;
/**
* Amazon SQS Extended Client extends the functionality of Amazon SQS client.
* All service calls made using this client are blocking, and will not return
* until the service call completes.
*
* <p>
* The Amazon SQS extended client enables sending and receiving large messages
* via Amazon S3. You can use this library to:
* </p>
*
* <ul>
* <li>Specify whether messages are always stored in Amazon S3 or only when a
* message size exceeds 256 KB.</li>
* <li>Send a message that references a single message object stored in an
* Amazon S3 bucket.</li>
* <li>Get the corresponding message object from an Amazon S3 bucket.</li>
* <li>Delete the corresponding message object from an Amazon S3 bucket.</li>
* </ul>
*/
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);
static final String LEGACY_RESERVED_ATTRIBUTE_NAME = "SQSLargePayloadSize";
static final List<String> RESERVED_ATTRIBUTE_NAMES = Arrays.asList(LEGACY_RESERVED_ATTRIBUTE_NAME,
SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME);
private ExtendedClientConfiguration clientConfiguration;
private PayloadStore payloadStore;
/**
* Constructs a new Amazon SQS extended client to invoke service methods on
* Amazon SQS with extended functionality using the specified Amazon SQS
* client object.
*
* <p>
* All service calls made using this new client object are blocking, and
* will not return until the service call completes.
*
* @param sqsClient
* The Amazon SQS client to use to connect to Amazon SQS.
*/
public AmazonSQSExtendedClient(SqsClient sqsClient) {
this(sqsClient, new ExtendedClientConfiguration());
}
/**
* Constructs a new Amazon SQS extended client to invoke service methods on
* Amazon SQS with extended functionality using the specified Amazon SQS
* client object.
*
* <p>
* All service calls made using this new client object are blocking, and
* will not return until the service call completes.
*
* @param sqsClient
* The Amazon SQS client to use to connect to Amazon SQS.
* @param extendedClientConfig
* The extended client configuration options controlling the
* functionality of this client.
*/
public AmazonSQSExtendedClient(SqsClient sqsClient, ExtendedClientConfiguration extendedClientConfig) {
super(sqsClient);
this.clientConfiguration = new ExtendedClientConfiguration(extendedClientConfig);
S3Dao s3Dao = new S3Dao(clientConfiguration.getS3Client(),
clientConfiguration.getServerSideEncryptionStrategy(),
clientConfiguration.getObjectCannedACL());
this.payloadStore = new S3BackedPayloadStore(s3Dao, clientConfiguration.getS3BucketName());
}
/**
* <p>
* Delivers a message to the specified queue.
* </p>
* <important>
* <p>
* A message can include only XML, JSON, and unformatted text. The following Unicode characters are allowed:
* </p>
* <p>
* <code>#x9</code> | <code>#xA</code> | <code>#xD</code> | <code>#x20</code> to <code>#xD7FF</code> |
* <code>#xE000</code> to <code>#xFFFD</code> | <code>#x10000</code> to <code>#x10FFFF</code>
* </p>
* <p>
* Any characters not included in this list will be rejected. For more information, see the <a
* href="http://www.w3.org/TR/REC-xml/#charsets">W3C specification for characters</a>.
* </p>
* </important>
*
* @param sendMessageRequest
* @return Result of the SendMessage operation returned by the service.
* @throws InvalidMessageContentsException
* The message contains characters outside the allowed set.
* @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.SendMessage
* @see <a href="http://docs.aws.amazon.com/goto/WebAPI/sqs-2012-11-05/SendMessage" target="_top">AWS API
* Documentation</a>
*/
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 SdkClientException.create(errorMessage);
}
SendMessageRequest.Builder sendMessageRequestBuilder = sendMessageRequest.toBuilder();
sendMessageRequest = appendUserAgent(sendMessageRequestBuilder).build();
if (!clientConfiguration.isPayloadSupportEnabled()) {
return super.sendMessage(sendMessageRequest);
}
if (StringUtils.isEmpty(sendMessageRequest.messageBody())) {
String errorMessage = "messageBody cannot be null or empty.";
LOG.error(errorMessage);
throw SdkClientException.create(errorMessage);
}
//Check message attributes for ExtendedClient related constraints
checkMessageAttributes(sendMessageRequest.messageAttributes());
if (clientConfiguration.isAlwaysThroughS3() || isLarge(sendMessageRequest)) {
sendMessageRequest = storeMessageInS3(sendMessageRequest);
}
return super.sendMessage(sendMessageRequest);
}
/**
* <p>
* Retrieves one or more messages (up to 10), from the specified queue. Using the <code>WaitTimeSeconds</code>
* parameter enables long-poll support. For more information, see <a
* href="https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-long-polling.html">Amazon
* SQS Long Polling</a> in the <i>Amazon Simple Queue Service Developer Guide</i>.
* </p>
* <p>
* Short poll is the default behavior where a weighted random set of machines is sampled on a
* <code>ReceiveMessage</code> 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
* <code>ReceiveMessage</code> call. If the number of messages in the queue is extremely small, you might not
* receive any messages in a particular <code>ReceiveMessage</code> response. If this happens, repeat the request.
* </p>
* <p>
* For each message returned, the response includes the following:
* </p>
* <ul>
* <li>
* <p>
* The message body.
* </p>
* </li>
* <li>
* <p>
* An MD5 digest of the message body. For information about MD5, see <a
* href="https://www.ietf.org/rfc/rfc1321.txt">RFC1321</a>.
* </p>
* </li>
* <li>
* <p>
* The <code>MessageId</code> you received when you sent the message to the queue.
* </p>
* </li>
* <li>
* <p>
* The receipt handle.
* </p>
* </li>
* <li>
* <p>
* The message attributes.
* </p>
* </li>
* <li>
* <p>
* An MD5 digest of the message attributes.
* </p>
* </li>
* </ul>
* <p>
* The receipt handle is the identifier you must provide when deleting the message. For more information, see <a
* href
* ="https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-queue-message-identifiers.html"
* >Queue and Message Identifiers</a> in the <i>Amazon Simple Queue Service Developer Guide</i>.
* </p>
* <p>
* You can provide the <code>VisibilityTimeout</code> 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 <a
* href="https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-visibility-timeout.html"
* >Visibility Timeout</a> in the <i>Amazon Simple Queue Service Developer Guide</i>.
* </p>
* <p>
* 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.
* </p>
* <note>
* <p>
* 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.
* </p>
* </note>
*
* @param receiveMessageRequest
* @return Result of the ReceiveMessage operation returned by the service.
* @throws OverLimitException
* The specified action violates a limit. For example, <code>ReceiveMessage</code> returns this error if the
* maximum number of inflight messages is reached and <code>AddPermission</code> 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 <a href="http://docs.aws.amazon.com/goto/WebAPI/sqs-2012-11-05/ReceiveMessage" target="_top">AWS API
* Documentation</a>
*/
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 SdkClientException.create(errorMessage);
}
ReceiveMessageRequest.Builder receiveMessageRequestBuilder = receiveMessageRequest.toBuilder();
appendUserAgent(receiveMessageRequestBuilder);
if (!clientConfiguration.isPayloadSupportEnabled()) {
return super.receiveMessage(receiveMessageRequestBuilder.build());
}
//Remove before adding to avoid any duplicates
List<String> messageAttributeNames = new ArrayList<>(receiveMessageRequest.messageAttributeNames());
messageAttributeNames.removeAll(RESERVED_ATTRIBUTE_NAMES);
messageAttributeNames.addAll(RESERVED_ATTRIBUTE_NAMES);
receiveMessageRequestBuilder.attributeNamesWithStrings(messageAttributeNames);
receiveMessageRequest = receiveMessageRequestBuilder.build();
ReceiveMessageResponse receiveMessageResponse = super.receiveMessage(receiveMessageRequest);
ReceiveMessageResponse.Builder receiveMessageResponseBuilder = receiveMessageResponse.toBuilder();
List<Message> messages = receiveMessageResponse.messages();
List<Message> 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<String> largePayloadAttributeName = getReservedAttributeNameIfPresent(message.messageAttributes());
if (largePayloadAttributeName.isPresent()) {
String largeMessagePointer = message.body();
largeMessagePointer = largeMessagePointer.replace("com.amazon.sqs.javamessaging.MessageS3Pointer", "software.amazon.payloadoffloading.PayloadS3Pointer");
messageBuilder.body(payloadStore.getOriginalPayload(largeMessagePointer));
// remove the additional attribute before returning the message
// to user.
Map<String, MessageAttributeValue> 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.receiptHandle(),
largeMessagePointer);
messageBuilder.receiptHandle(modifiedReceiptHandle);
}
modifiedMessages.add(messageBuilder.build());
}
receiveMessageResponseBuilder.messages(modifiedMessages);
return receiveMessageResponseBuilder.build();
}
/**
* <p>
* Deletes the specified message from the specified queue. To select the message to delete, use the
* <code>ReceiptHandle</code> of the message (<i>not</i> the <code>MessageId</code> 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.
* </p>
* <note>
* <p>
* The <code>ReceiptHandle</code> is associated with a <i>specific instance</i> of receiving a message. If you
* receive a message more than once, the <code>ReceiptHandle</code> is different each time you receive a message.
* When you use the <code>DeleteMessage</code> action, you must provide the most recently received
* <code>ReceiptHandle</code> for the message (otherwise, the request succeeds, but the message might not be
* deleted).
* </p>
* <p>
* 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.
* </p>
* </note>
*
* @param deleteMessageRequest
* @return Result of the DeleteMessage operation returned by the service.
* @throws InvalidIdFormatException
* 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 <a href="http://docs.aws.amazon.com/goto/WebAPI/sqs-2012-11-05/DeleteMessage" target="_top">AWS API
* Documentation</a>
*/
public DeleteMessageResponse deleteMessage(DeleteMessageRequest deleteMessageRequest) {
if (deleteMessageRequest == null) {
String errorMessage = "deleteMessageRequest cannot be null.";
LOG.error(errorMessage);
throw SdkClientException.create(errorMessage);
}
DeleteMessageRequest.Builder deleteMessageRequestBuilder = deleteMessageRequest.toBuilder();
appendUserAgent(deleteMessageRequestBuilder);
if (!clientConfiguration.isPayloadSupportEnabled()) {
return super.deleteMessage(deleteMessageRequestBuilder.build());
}
String receiptHandle = deleteMessageRequest.receiptHandle();
String origReceiptHandle = receiptHandle;
// Update original receipt handle if needed
if (isS3ReceiptHandle(receiptHandle)) {
origReceiptHandle = getOrigReceiptHandle(receiptHandle);
// Delete pay load from S3 if needed
if (clientConfiguration.doesCleanupS3Payload()) {
String messagePointer = getMessagePointerFromModifiedReceiptHandle(receiptHandle);
payloadStore.deleteOriginalPayload(messagePointer);
}
}
deleteMessageRequestBuilder.receiptHandle(origReceiptHandle);
return super.deleteMessage(deleteMessageRequestBuilder.build());
}
/**
* <p>
* 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 <a
* href="https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-visibility-timeout.html">
* Visibility Timeout</a> in the <i>Amazon Simple Queue Service Developer Guide</i>.
* </p>
* <p>
* For example, you have a message with a visibility timeout of 5 minutes. After 3 minutes, you call
* <code>ChangeMessageVisibility</code> with a timeout of 10 minutes. You can continue to call
* <code>ChangeMessageVisibility</code> 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.
* </p>
* <p>
* An Amazon SQS message has three basic states:
* </p>
* <ol>
* <li>
* <p>
* Sent to a queue by a producer.
* </p>
* </li>
* <li>
* <p>
* Received from the queue by a consumer.
* </p>
* </li>
* <li>
* <p>
* Deleted from the queue.
* </p>
* </li>
* </ol>
* <p>
* A message is considered to be <i>stored</i> 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 <i>in flight</i> 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.
* </p>
* <p>
* Limits that apply to inflight messages are unrelated to the <i>unlimited</i> number of stored messages.
* </p>
* <p>
* 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 <code>OverLimit</code> 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, <a href=
* "https://console.aws.amazon.com/support/home#/case/create?issueType=service-limit-increase&limitType=service-code-sqs"
* >file a support request</a>.
* </p>
* <p>
* 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.
* </p>
* <important>
* <p>
* If you attempt to set the <code>VisibilityTimeout</code> 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.
* </p>
* <p>
* 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
* <code>ChangeMessageVisibility</code> action) the next time the message is received.
* </p>
* </important>
*
* @param changeMessageVisibilityRequest
* @return Result of the ChangeMessageVisibility operation returned by the service.
* @throws MessageNotInflightException
* 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 <a href="http://docs.aws.amazon.com/goto/WebAPI/sqs-2012-11-05/ChangeMessageVisibility" target="_top">AWS
* API Documentation</a>
*/
public ChangeMessageVisibilityResponse changeMessageVisibility(ChangeMessageVisibilityRequest changeMessageVisibilityRequest)
throws AwsServiceException, SdkClientException {
ChangeMessageVisibilityRequest.Builder changeMessageVisibilityRequestBuilder = changeMessageVisibilityRequest.toBuilder();
if (isS3ReceiptHandle(changeMessageVisibilityRequest.receiptHandle())) {
changeMessageVisibilityRequestBuilder.receiptHandle(
getOrigReceiptHandle(changeMessageVisibilityRequest.receiptHandle()));
}
return amazonSqsToBeExtended.changeMessageVisibility(changeMessageVisibilityRequestBuilder.build());
}
/**
* <p>
* Delivers up to ten messages to the specified queue. This is a batch version of <code> <a>SendMessage</a>.</code>
* For a FIFO queue, multiple messages within a single batch are enqueued in the order they are sent.
* </p>
* <p>
* 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 <code>200</code>.
* </p>
* <p>
* 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).
* </p>
* <important>
* <p>
* A message can include only XML, JSON, and unformatted text. The following Unicode characters are allowed:
* </p>
* <p>
* <code>#x9</code> | <code>#xA</code> | <code>#xD</code> | <code>#x20</code> to <code>#xD7FF</code> |
* <code>#xE000</code> to <code>#xFFFD</code> | <code>#x10000</code> to <code>#x10FFFF</code>
* </p>
* <p>
* Any characters not included in this list will be rejected. For more information, see the <a
* href="http://www.w3.org/TR/REC-xml/#charsets">W3C specification for characters</a>.
* </p>
* </important>
* <p>
* If you don't specify the <code>DelaySeconds</code> parameter for an entry, Amazon SQS uses the default value for
* the queue.
* </p>
* <p>
* Some actions take lists of parameters. These lists are specified using the <code>param.n</code> notation. Values
* of <code>n</code> are integers starting from 1. For example, a parameter list with two elements looks like this:
* </p>
* <p>
* <code>&AttributeName.1=first</code>
* </p>
* <p>
* <code>&AttributeName.2=second</code>
* </p>
*
* @param sendMessageBatchRequest
* @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 <code>Id</code>.
* @throws BatchRequestTooLongException
* The length of all the messages put together is more than the limit.
* @throws InvalidBatchEntryIdException
* The <code>Id</code> 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 <a href="http://docs.aws.amazon.com/goto/WebAPI/sqs-2012-11-05/SendMessageBatch" target="_top">AWS API
* Documentation</a>
*/
public SendMessageBatchResponse sendMessageBatch(SendMessageBatchRequest sendMessageBatchRequest) {
if (sendMessageBatchRequest == null) {
String errorMessage = "sendMessageBatchRequest cannot be null.";
LOG.error(errorMessage);
throw SdkClientException.create(errorMessage);
}
SendMessageBatchRequest.Builder sendMessageBatchRequestBuilder = sendMessageBatchRequest.toBuilder();
appendUserAgent(sendMessageBatchRequestBuilder);
sendMessageBatchRequest = sendMessageBatchRequestBuilder.build();
if (!clientConfiguration.isPayloadSupportEnabled()) {
return super.sendMessageBatch(sendMessageBatchRequest);
}
List<SendMessageBatchRequestEntry> batchEntries = new ArrayList<>(sendMessageBatchRequest.entries().size());
for (SendMessageBatchRequestEntry entry : sendMessageBatchRequest.entries()) {
//Check message attributes for ExtendedClient related constraints
checkMessageAttributes(entry.messageAttributes());
if (clientConfiguration.isAlwaysThroughS3() || isLarge(entry)) {
entry = storeMessageInS3(entry);
}
batchEntries.add(entry);
}
return super.sendMessageBatch(sendMessageBatchRequest);
}
/**
* <p>
* Deletes up to ten messages from the specified queue. This is a batch version of
* <code> <a>DeleteMessage</a>.</code> The result of the action on each message is reported individually in the
* response.
* </p>
* <important>
* <p>
* 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 <code>200</code>.
* </p>
* </important>
* <p>
* Some actions take lists of parameters. These lists are specified using the <code>param.n</code> notation. Values
* of <code>n</code> are integers starting from 1. For example, a parameter list with two elements looks like this:
* </p>
* <p>
* <code>&AttributeName.1=first</code>
* </p>
* <p>
* <code>&AttributeName.2=second</code>
* </p>
*
* @param deleteMessageBatchRequest
* @return Result of the DeleteMessageBatch 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 <code>Id</code>.
* @throws InvalidBatchEntryIdException
* The <code>Id</code> 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 <a href="http://docs.aws.amazon.com/goto/WebAPI/sqs-2012-11-05/DeleteMessageBatch" target="_top">AWS API
* Documentation</a>
*/
public DeleteMessageBatchResponse deleteMessageBatch(DeleteMessageBatchRequest deleteMessageBatchRequest) {
if (deleteMessageBatchRequest == null) {
String errorMessage = "deleteMessageBatchRequest cannot be null.";
LOG.error(errorMessage);
throw SdkClientException.create(errorMessage);
}
DeleteMessageBatchRequest.Builder deleteMessageBatchRequestBuilder = deleteMessageBatchRequest.toBuilder();
appendUserAgent(deleteMessageBatchRequestBuilder);
if (!clientConfiguration.isPayloadSupportEnabled()) {
return super.deleteMessageBatch(deleteMessageBatchRequest);
}
List<DeleteMessageBatchRequestEntry> 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
if (isS3ReceiptHandle(receiptHandle)) {
origReceiptHandle = getOrigReceiptHandle(receiptHandle);
// Delete s3 payload if needed
if (clientConfiguration.doesCleanupS3Payload()) {
String messagePointer = getMessagePointerFromModifiedReceiptHandle(receiptHandle);
payloadStore.deleteOriginalPayload(messagePointer);
}
}
entryBuilder.receiptHandle(origReceiptHandle);
entries.add(entryBuilder.build());
}
deleteMessageBatchRequestBuilder.entries(entries);
return super.deleteMessageBatch(deleteMessageBatchRequestBuilder.build());
}
/**
* <p>
* Changes the visibility timeout of multiple messages. This is a batch version of
* <code> <a>ChangeMessageVisibility</a>.</code> The result of the action on each message is reported individually
* in the response. You can send up to 10 <code> <a>ChangeMessageVisibility</a> </code> requests with each
* <code>ChangeMessageVisibilityBatch</code> action.
* </p>
* <important>
* <p>
* 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 <code>200</code>.
* </p>
* </important>
* <p>
* Some actions take lists of parameters. These lists are specified using the <code>param.n</code> notation. Values
* of <code>n</code> are integers starting from 1. For example, a parameter list with two elements looks like this:
* </p>
* <p>
* <code>&AttributeName.1=first</code>
* </p>
* <p>
* <code>&AttributeName.2=second</code>
* </p>
*
* @param changeMessageVisibilityBatchRequest
* @return Result of the ChangeMessageVisibilityBatch 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 <code>Id</code>.
* @throws InvalidBatchEntryIdException
* The <code>Id</code> 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 <a href="http://docs.aws.amazon.com/goto/WebAPI/sqs-2012-11-05/ChangeMessageVisibilityBatch"
* target="_top">AWS API Documentation</a>
*/
public ChangeMessageVisibilityBatchResponse changeMessageVisibilityBatch(
ChangeMessageVisibilityBatchRequest changeMessageVisibilityBatchRequest) throws AwsServiceException,
SdkClientException {
List<ChangeMessageVisibilityBatchRequestEntry> 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.toBuilder().entries(entries).build());
}
/**
* <p>
* Deletes the messages in a queue specified by the <code>QueueURL</code> parameter.
* </p>
* <important>
* <p>
* When you use the <code>PurgeQueue</code> action, you can't retrieve any messages deleted from a queue.
* </p>
* <p>
* The message deletion process takes up to 60 seconds. We recommend waiting for 60 seconds regardless of your
* queue's size.
* </p>
* </important>
* <p>
* Messages sent to the queue <i>before</i> you call <code>PurgeQueue</code> might be received but are deleted
* within the next minute.
* </p>
* <p>
* Messages sent to the queue <i>after</i> you call <code>PurgeQueue</code> might be deleted while the queue is
* being purged.
* </p>
*
* @param purgeQueueRequest
* @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 <code>PurgeQueue</code> 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 <a href="http://docs.aws.amazon.com/goto/WebAPI/sqs-2012-11-05/PurgeQueue" target="_top">AWS API
* Documentation</a>
*/
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 SdkClientException.create(errorMessage);
}
PurgeQueueRequest.Builder purgeQueueRequestBuilder = purgeQueueRequest.toBuilder();
appendUserAgent(purgeQueueRequestBuilder);
return super.purgeQueue(purgeQueueRequestBuilder.build());
}
private void checkMessageAttributes(Map<String, MessageAttributeValue> messageAttributes) {
int msgAttributesSize = getMsgAttributesSize(messageAttributes);
if (msgAttributesSize > clientConfiguration.getPayloadSizeThreshold()) {
String errorMessage = "Total size of Message attributes is " + msgAttributesSize
+ " bytes which is larger than the threshold of " + clientConfiguration.getPayloadSizeThreshold()
+ " Bytes. Consider including the payload in the message body instead of message attributes.";
LOG.error(errorMessage);
throw SdkClientException.create(errorMessage);
}
int messageAttributesNum = messageAttributes.size();
if (messageAttributesNum > SQSExtendedClientConstants.MAX_ALLOWED_ATTRIBUTES) {
String errorMessage = "Number of message attributes [" + messageAttributesNum
+ "] exceeds the maximum allowed for large-payload messages ["
+ SQSExtendedClientConstants.MAX_ALLOWED_ATTRIBUTES + "].";
LOG.error(errorMessage);
throw SdkClientException.create(errorMessage);
}
Optional<String> largePayloadAttributeName = getReservedAttributeNameIfPresent(messageAttributes);
if (largePayloadAttributeName.isPresent()) {
String errorMessage = "Message attribute name " + largePayloadAttributeName.get()
+ " is reserved for use by SQS extended client.";
LOG.error(errorMessage);
throw SdkClientException.create(errorMessage);
}
}
/**
* TODO: Wrap the message pointer as-is to the receiptHandle so that it can be generic
* and does not use any LargeMessageStore implementation specific details.
*/
private String embedS3PointerInReceiptHandle(String receiptHandle, String pointer) {
PayloadS3Pointer s3Pointer = PayloadS3Pointer.fromJson(pointer);
String s3MsgBucketName = s3Pointer.getS3BucketName();
String s3MsgKey = s3Pointer.getS3Key();
String modifiedReceiptHandle = SQSExtendedClientConstants.S3_BUCKET_NAME_MARKER + s3MsgBucketName
+ SQSExtendedClientConstants.S3_BUCKET_NAME_MARKER + SQSExtendedClientConstants.S3_KEY_MARKER
+ s3MsgKey + SQSExtendedClientConstants.S3_KEY_MARKER + receiptHandle;
return modifiedReceiptHandle;
}
private String getOrigReceiptHandle(String receiptHandle) {
int secondOccurence = receiptHandle.indexOf(SQSExtendedClientConstants.S3_KEY_MARKER,
receiptHandle.indexOf(SQSExtendedClientConstants.S3_KEY_MARKER) + 1);
return receiptHandle.substring(secondOccurence + SQSExtendedClientConstants.S3_KEY_MARKER.length());
}
private String getFromReceiptHandleByMarker(String receiptHandle, String marker) {
int firstOccurence = receiptHandle.indexOf(marker);
int secondOccurence = receiptHandle.indexOf(marker, firstOccurence + 1);
return receiptHandle.substring(firstOccurence + marker.length(), secondOccurence);
}
private boolean isS3ReceiptHandle(String receiptHandle) {
return receiptHandle.contains(SQSExtendedClientConstants.S3_BUCKET_NAME_MARKER)
&& receiptHandle.contains(SQSExtendedClientConstants.S3_KEY_MARKER);
}
private String getMessagePointerFromModifiedReceiptHandle(String receiptHandle) {
String s3MsgBucketName = getFromReceiptHandleByMarker(receiptHandle, SQSExtendedClientConstants.S3_BUCKET_NAME_MARKER);
String s3MsgKey = getFromReceiptHandleByMarker(receiptHandle, SQSExtendedClientConstants.S3_KEY_MARKER);
PayloadS3Pointer payloadS3Pointer = new PayloadS3Pointer(s3MsgBucketName, s3MsgKey);
return payloadS3Pointer.toJson();
}
private boolean isLarge(SendMessageRequest sendMessageRequest) {
int msgAttributesSize = getMsgAttributesSize(sendMessageRequest.messageAttributes());
long msgBodySize = Util.getStringSizeInBytes(sendMessageRequest.messageBody());
long totalMsgSize = msgAttributesSize + msgBodySize;
return (totalMsgSize > clientConfiguration.getPayloadSizeThreshold());
}
private boolean isLarge(SendMessageBatchRequestEntry batchEntry) {
int msgAttributesSize = getMsgAttributesSize(batchEntry.messageAttributes());
long msgBodySize = Util.getStringSizeInBytes(batchEntry.messageBody());
long totalMsgSize = msgAttributesSize + msgBodySize;
return (totalMsgSize > clientConfiguration.getPayloadSizeThreshold());
}
private Optional<String> getReservedAttributeNameIfPresent(Map<String, MessageAttributeValue> msgAttributes) {
String reservedAttributeName = null;
if (msgAttributes.containsKey(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME)) {
reservedAttributeName = SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME;
} else if (msgAttributes.containsKey(LEGACY_RESERVED_ATTRIBUTE_NAME)) {
reservedAttributeName = LEGACY_RESERVED_ATTRIBUTE_NAME;
}
return Optional.ofNullable(reservedAttributeName);
}
private int getMsgAttributesSize(Map<String, MessageAttributeValue> msgAttributes) {
int totalMsgAttributesSize = 0;
for (Map.Entry<String, MessageAttributeValue> entry : msgAttributes.entrySet()) {
totalMsgAttributesSize += Util.getStringSizeInBytes(entry.getKey());
MessageAttributeValue entryVal = entry.getValue();
if (entryVal.dataType() != null) {
totalMsgAttributesSize += Util.getStringSizeInBytes(entryVal.dataType());
}
String stringVal = entryVal.stringValue();
if (stringVal != null) {
totalMsgAttributesSize += Util.getStringSizeInBytes(entryVal.stringValue());
}
SdkBytes binaryVal = entryVal.binaryValue();
if (binaryVal != null) {
totalMsgAttributesSize += binaryVal.asByteArray().length;
}
}
return totalMsgAttributesSize;
}
private SendMessageBatchRequestEntry storeMessageInS3(SendMessageBatchRequestEntry batchEntry) {
// Read the content of the message from message body
String messageContentStr = batchEntry.messageBody();
Long messageContentSize = Util.getStringSizeInBytes(messageContentStr);
SendMessageBatchRequestEntry.Builder batchEntryBuilder = batchEntry.toBuilder();
batchEntryBuilder.messageAttributes(
updateMessageAttributePayloadSize(batchEntry.messageAttributes(), messageContentSize));
// Store the message content in S3.
String largeMessagePointer = payloadStore.storeOriginalPayload(messageContentStr);
batchEntryBuilder.messageBody(largeMessagePointer);
return batchEntryBuilder.build();
}
private SendMessageRequest storeMessageInS3(SendMessageRequest sendMessageRequest) {
// Read the content of the message from message body
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<String, MessageAttributeValue> updateMessageAttributePayloadSize(
Map<String, MessageAttributeValue> messageAttributes, Long messageContentSize) {
Map<String, MessageAttributeValue> updatedMessageAttributes = new HashMap<>(messageAttributes);
// Add a new message attribute as a flag
MessageAttributeValue.Builder messageAttributeValueBuilder = MessageAttributeValue.builder();
messageAttributeValueBuilder.dataType("Number");
messageAttributeValueBuilder.stringValue(messageContentSize.toString());
MessageAttributeValue messageAttributeValue = messageAttributeValueBuilder.build();
if (!clientConfiguration.usesLegacyReservedAttributeName()) {
updatedMessageAttributes.put(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME, messageAttributeValue);
} else {
updatedMessageAttributes.put(LEGACY_RESERVED_ATTRIBUTE_NAME, messageAttributeValue);