Skip to content

Commit dde1d7a

Browse files
Upgrade to SDK v2
1 parent 4399143 commit dde1d7a

File tree

8 files changed

+74
-77
lines changed

8 files changed

+74
-77
lines changed

pom.xml

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,38 +33,35 @@
3333
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3434
</properties>
3535

36-
<dependencyManagement>
37-
<dependencies>
38-
<dependency>
39-
<groupId>software.amazon.awssdk</groupId>
40-
<artifactId>bom</artifactId>
41-
<version>${aws-java-sdk.version}</version>
42-
<type>pom</type>
43-
<scope>import</scope>
44-
</dependency>
45-
</dependencies>
46-
</dependencyManagement>
47-
4836
<dependencies>
4937
<dependency>
5038
<groupId>software.amazon.awssdk</groupId>
5139
<artifactId>sqs</artifactId>
40+
<version>${aws-java-sdk.version}</version>
5241
</dependency>
5342
<dependency>
5443
<groupId>software.amazon.awssdk</groupId>
5544
<artifactId>auth</artifactId>
45+
<version>${aws-java-sdk.version}</version>
5646
</dependency>
5747
<dependency>
5848
<groupId>software.amazon.awssdk</groupId>
5949
<artifactId>utils</artifactId>
50+
<version>${aws-java-sdk.version}</version>
6051
</dependency>
6152

6253
<dependency>
6354
<groupId>org.slf4j</groupId>
6455
<artifactId>slf4j-api</artifactId>
6556
<version>1.7.30</version>
6657
</dependency>
67-
58+
59+
<dependency>
60+
<groupId>joda-time</groupId>
61+
<artifactId>joda-time</artifactId>
62+
<version>2.10.13</version>
63+
</dependency>
64+
6865
<dependency>
6966
<groupId>org.apache.geronimo.specs</groupId>
7067
<artifactId>geronimo-jms_1.1_spec</artifactId>

src/main/java/com/amazon/sqs/javamessaging/AmazonSQSMessagingClientWrapper.java

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949

5050

5151
/**
52-
* This is a JMS Wrapper of <code>AmazonSQSClient</code>. This class changes all
53-
* <code>AmazonServiceException</code> and <code>AmazonClientException</code> into
52+
* This is a JMS Wrapper of <code>SqsClient</code>. This class changes all
53+
* <code>AwsServiceException</code> and <code>SdkException</code> into
5454
* JMSException/JMSSecurityException.
5555
*/
5656
public class AmazonSQSMessagingClientWrapper {
@@ -61,7 +61,7 @@ public class AmazonSQSMessagingClientWrapper {
6161
/**
6262
* List of exceptions that can classified as security. These exceptions
6363
* are not thrown during connection-set-up rather after the service
64-
* calls of the <code>AmazonSQSClient</code>.
64+
* calls of the <code>SqsClient</code>.
6565
*/
6666
SECURITY_EXCEPTION_ERROR_CODES = new HashSet<String>();
6767
SECURITY_EXCEPTION_ERROR_CODES.add("MissingClientTokenId");
@@ -108,12 +108,12 @@ public SqsClient getAmazonSQSClient() {
108108
}
109109

110110
/**
111-
* Calls <code>deleteMessage</code> and wraps <code>AmazonClientException</code>. This is used to
111+
* Calls <code>deleteMessage</code> and wraps <code>SdkException</code>. This is used to
112112
* acknowledge single messages, so that they can be deleted from SQS queue.
113113
*
114114
* @param deleteMessageRequest
115115
* Container for the necessary parameters to execute the
116-
* deleteMessage service method on AmazonSQS.
116+
* deleteMessage service method on SqsClient.
117117
* @throws JMSException
118118
*/
119119
public void deleteMessage(DeleteMessageRequest deleteMessageRequest) throws JMSException {
@@ -127,16 +127,16 @@ public void deleteMessage(DeleteMessageRequest deleteMessageRequest) throws JMSE
127127

128128
/**
129129
* Calls <code>deleteMessageBatch</code> and wraps
130-
* <code>AmazonClientException</code>. This is used to acknowledge multiple
130+
* <code>SdkException</code>. This is used to acknowledge multiple
131131
* messages on client_acknowledge mode, so that they can be deleted from SQS
132132
* queue.
133133
*
134134
* @param deleteMessageBatchRequest
135135
* Container for the necessary parameters to execute the
136-
* deleteMessageBatch service method on AmazonSQS. This is the
136+
* deleteMessageBatch service method on SqsClient. This is the
137137
* batch version of deleteMessage. Max batch size is 10.
138138
* @return The response from the deleteMessageBatch service method, as
139-
* returned by AmazonSQS
139+
* returned by SqsClient
140140
* @throws JMSException
141141
*/
142142
public DeleteMessageBatchResponse deleteMessageBatch(DeleteMessageBatchRequest deleteMessageBatchRequest) throws JMSException {
@@ -154,9 +154,9 @@ public DeleteMessageBatchResponse deleteMessageBatch(DeleteMessageBatchRequest d
154154
*
155155
* @param sendMessageRequest
156156
* Container for the necessary parameters to execute the
157-
* sendMessage service method on AmazonSQS.
157+
* sendMessage service method on SqsClient.
158158
* @return The response from the sendMessage service method, as returned by
159-
* AmazonSQS
159+
* SqsClient
160160
* @throws JMSException
161161
*/
162162
public SendMessageResponse sendMessage(SendMessageRequest sendMessageRequest) throws JMSException {
@@ -225,7 +225,7 @@ public boolean queueExists(String queueName, String queueOwnerAccountId) throws
225225
*
226226
* @param queueName
227227
* @return The response from the GetQueueUrl service method, as returned by
228-
* AmazonSQS, which will include queue`s URL
228+
* SqsClient, which will include queue`s URL
229229
* @throws JMSException
230230
*/
231231
public GetQueueUrlResponse getQueueUrl(String queueName) throws JMSException {
@@ -241,7 +241,7 @@ public GetQueueUrlResponse getQueueUrl(String queueName) throws JMSException {
241241
* @param queueName
242242
* @param queueOwnerAccountId The AWS accountId of the account that created the queue
243243
* @return The response from the GetQueueUrl service method, as returned by
244-
* AmazonSQS, which will include queue`s URL
244+
* SqsClient, which will include queue`s URL
245245
* @throws JMSException
246246
*/
247247
public GetQueueUrlResponse getQueueUrl(String queueName, String queueOwnerAccountId) throws JMSException {
@@ -253,13 +253,13 @@ public GetQueueUrlResponse getQueueUrl(String queueName, String queueOwnerAccoun
253253
}
254254

255255
/**
256-
* Calls <code>getQueueUrl</code> and wraps <code>AmazonClientException</code>
256+
* Calls <code>getQueueUrl</code> and wraps <code>SdkException</code>
257257
*
258258
* @param getQueueUrlRequest
259259
* Container for the necessary parameters to execute the
260-
* getQueueUrl service method on AmazonSQS.
260+
* getQueueUrl service method on SqsClient.
261261
* @return The response from the GetQueueUrl service method, as returned by
262-
* AmazonSQS, which will include queue`s URL
262+
* SqsClient, which will include queue`s URL
263263
* @throws JMSException
264264
*/
265265
public GetQueueUrlResponse getQueueUrl(GetQueueUrlRequest getQueueUrlRequest) throws JMSException {
@@ -273,11 +273,11 @@ public GetQueueUrlResponse getQueueUrl(GetQueueUrlRequest getQueueUrlRequest) th
273273

274274
/**
275275
* Calls <code>createQueue</code> to create the queue with the default queue attributes,
276-
* and wraps <code>AmazonClientException</code>
276+
* and wraps <code>SdkException</code>
277277
*
278278
* @param queueName
279279
* @return The response from the createQueue service method, as returned by
280-
* AmazonSQS. This call creates a new queue, or returns the URL of
280+
* SqsClient. This call creates a new queue, or returns the URL of
281281
* an existing one.
282282
* @throws JMSException
283283
*/
@@ -287,13 +287,13 @@ public CreateQueueResponse createQueue(String queueName) throws JMSException {
287287

288288
/**
289289
* Calls <code>createQueue</code> to create the queue with the provided queue attributes
290-
* if any, and wraps <code>AmazonClientException</code>
290+
* if any, and wraps <code>SdkException</code>
291291
*
292292
* @param createQueueRequest
293293
* Container for the necessary parameters to execute the
294-
* createQueue service method on AmazonSQS.
294+
* createQueue service method on SqsClient.
295295
* @return The response from the createQueue service method, as returned by
296-
* AmazonSQS. This call creates a new queue, or returns the URL of
296+
* SqsClient. This call creates a new queue, or returns the URL of
297297
* an existing one.
298298
* @throws JMSException
299299
*/
@@ -307,16 +307,16 @@ public CreateQueueResponse createQueue(CreateQueueRequest createQueueRequest) th
307307
}
308308

309309
/**
310-
* Calls <code>receiveMessage</code> and wraps <code>AmazonClientException</code>. Used by
310+
* Calls <code>receiveMessage</code> and wraps <code>SdkException</code>. Used by
311311
* {@link SQSMessageConsumerPrefetch} to receive up to minimum of
312312
* (<code>numberOfMessagesToPrefetch</code>,10) messages from SQS queue into consumer
313313
* prefetch buffers.
314314
*
315315
* @param receiveMessageRequest
316316
* Container for the necessary parameters to execute the
317-
* receiveMessage service method on AmazonSQS.
317+
* receiveMessage service method on SqsClient.
318318
* @return The response from the ReceiveMessage service method, as returned
319-
* by AmazonSQS.
319+
* by SqsClient.
320320
* @throws JMSException
321321
*/
322322
public ReceiveMessageResponse receiveMessage(ReceiveMessageRequest receiveMessageRequest) throws JMSException {
@@ -329,12 +329,12 @@ public ReceiveMessageResponse receiveMessage(ReceiveMessageRequest receiveMessag
329329
}
330330

331331
/**
332-
* Calls <code>changeMessageVisibility</code> and wraps <code>AmazonClientException</code>. This is
332+
* Calls <code>changeMessageVisibility</code> and wraps <code>SdkException</code>. This is
333333
* used to for negative acknowledge of a single message, so that messages can be received again without any delay.
334334
*
335335
* @param changeMessageVisibilityRequest
336336
* Container for the necessary parameters to execute the
337-
* changeMessageVisibility service method on AmazonSQS.
337+
* changeMessageVisibility service method on SqsClient.
338338
* @throws JMSException
339339
*/
340340
public void changeMessageVisibility(ChangeMessageVisibilityRequest changeMessageVisibilityRequest) throws JMSException {
@@ -347,15 +347,15 @@ public void changeMessageVisibility(ChangeMessageVisibilityRequest changeMessage
347347
}
348348

349349
/**
350-
* Calls <code>changeMessageVisibilityBatch</code> and wraps <code>AmazonClientException</code>. This is
350+
* Calls <code>changeMessageVisibilityBatch</code> and wraps <code>SdkException</code>. This is
351351
* used to for negative acknowledge of messages in batch, so that messages
352352
* can be received again without any delay.
353353
*
354354
* @param changeMessageVisibilityBatchRequest
355355
* Container for the necessary parameters to execute the
356-
* changeMessageVisibilityBatch service method on AmazonSQS.
356+
* changeMessageVisibilityBatch service method on SqsClient.
357357
* @return The response from the changeMessageVisibilityBatch service
358-
* method, as returned by AmazonSQS.
358+
* method, as returned by SqsClient.
359359
* @throws JMSException
360360
*/
361361
public ChangeMessageVisibilityBatchResponse changeMessageVisibilityBatch(ChangeMessageVisibilityBatchRequest changeMessageVisibilityBatchRequest)
@@ -369,7 +369,7 @@ public ChangeMessageVisibilityBatchResponse changeMessageVisibilityBatch(ChangeM
369369
}
370370

371371
/**
372-
* Create generic error message for <code>AmazonServiceException</code>. Message include
372+
* Create generic error message for <code>AwsServiceException</code>. Message include
373373
* Action, RequestId, HTTPStatusCode, and AmazonErrorCode.
374374
*/
375375
private String logAndGetAmazonServiceException(AwsServiceException ase, String action) {
@@ -380,7 +380,7 @@ private String logAndGetAmazonServiceException(AwsServiceException ase, String a
380380
}
381381

382382
/**
383-
* Create generic error message for <code>AmazonClientException</code>. Message include
383+
* Create generic error message for <code>SdkException</code>. Message include
384384
* Action.
385385
*/
386386
private String logAndGetAmazonClientException(SdkException ace, String action) {
@@ -412,8 +412,7 @@ private JMSException handleException(SdkException e, String operationName) throw
412412
return jmsException;
413413
}
414414

415-
private static String errorCode(AwsServiceException e)
416-
{
415+
private static String errorCode(AwsServiceException e) {
417416
return e.awsErrorDetails() != null ? e.awsErrorDetails().errorCode() : "";
418417
}
419418

@@ -423,9 +422,7 @@ private static boolean isJMSSecurityException(AwsServiceException e) {
423422
}
424423

425424
private void prepareRequest(AwsRequest request) {
426-
427-
if(credentialsProvider != null)
428-
{
425+
if(credentialsProvider != null) {
429426
request = request.toBuilder().overrideConfiguration(AwsRequestOverrideConfiguration
430427
.builder()
431428
.credentialsProvider(credentialsProvider)

src/main/java/com/amazon/sqs/javamessaging/SQSConnectionFactory.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
/**
3232
* A ConnectionFactory object encapsulates a set of connection configuration
33-
* parameters for <code>AmazonSQSClient</code> as well as setting
33+
* parameters for <code>SqsClient</code> as well as setting
3434
* <code>numberOfMessagesToPrefetch</code>.
3535
* <P>
3636
* The <code>numberOfMessagesToPrefetch</code> parameter is used to size of the
@@ -40,7 +40,7 @@
4040
* <P>
4141
* If more physical connections than the default maximum value (that is 50 as of
4242
* today) are needed on the connection pool,
43-
* {@link com.amazonaws.ClientConfiguration} needs to be configured.
43+
* {@link software.amazon.awssdk.core.client.config.ClientOverrideConfiguration} needs to be configured.
4444
* <P>
4545
* None of the <code>createConnection</code> methods set-up the physical
4646
* connection to SQS, so validity of credentials are not checked with those
@@ -54,16 +54,16 @@ public class SQSConnectionFactory implements ConnectionFactory, QueueConnectionF
5454
/*
5555
5656
/*
57-
* Creates a SQSConnectionFactory that uses AmazonSQSClientBuilder.standard() for creating AmazonSQS client connections.
58-
* Every SQSConnection will have its own copy of AmazonSQS client.
57+
* Creates a SQSConnectionFactory that uses SqsClientBuilder.standard() for creating SqsClient connections.
58+
* Every SQSConnection will have its own copy of SqsClient.
5959
*/
6060
public SQSConnectionFactory(ProviderConfiguration providerConfiguration) {
6161
this(providerConfiguration, SqsClient.create());
6262
}
6363

6464
/*
65-
* Creates a SQSConnectionFactory that uses the provided AmazonSQS client connection.
66-
* Every SQSConnection will use the same provided AmazonSQS client.
65+
* Creates a SQSConnectionFactory that uses the provided SqsClient connection.
66+
* Every SQSConnection will use the same provided SqsClient.
6767
*/
6868
public SQSConnectionFactory(ProviderConfiguration providerConfiguration, final SqsClient client) {
6969
if (providerConfiguration == null) {
@@ -82,7 +82,7 @@ public SqsClient get() {
8282
}
8383

8484
/*
85-
* Creates a SQSConnectionFactory that uses the provided AmazonSQSClientBuilder for creating AmazonSQS client connections.
85+
* Creates a SQSConnectionFactory that uses the provided SqsClientBuilder for creating AmazonSQS client connections.
8686
* Every SQSConnection will have its own copy of AmazonSQS client created through the provided builder.
8787
*/
8888
public SQSConnectionFactory(ProviderConfiguration providerConfiguration, final SqsClientBuilder clientBuilder) {

src/main/java/com/amazon/sqs/javamessaging/SQSMessageConsumerPrefetch.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
* <P>
5757
* Uses SQS <code>receiveMessage</code> with long-poll wait time of 20 seconds.
5858
* <P>
59-
* Add re-tries on top of <code>AmazonSQSClient</code> re-tries on SQS calls.
59+
* Add re-tries on top of <code>SqsClient</code> re-tries on SQS calls.
6060
*/
6161
public class SQSMessageConsumerPrefetch implements Runnable, PrefetchManager {
6262

src/test/java/com/amazon/sqs/javamessaging/AcknowledgerCommon.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
*/
1515
package com.amazon.sqs.javamessaging;
1616

17-
import static org.mockito.Mockito.mock;
18-
import static org.mockito.Mockito.when;
17+
import static org.junit.Assert.assertEquals;
1918

2019
import java.util.ArrayList;
2120
import java.util.HashMap;
@@ -72,6 +71,6 @@ public void populateMessage(int populateMessageSize) throws JMSException {
7271
populatedMessages.add(message);
7372
acknowledger.notifyMessageReceived(message);
7473
}
75-
org.junit.Assert.assertEquals(populateMessageSize, acknowledger.getUnAckMessages().size());
74+
assertEquals(populateMessageSize, acknowledger.getUnAckMessages().size());
7675
}
7776
}

src/test/java/com/amazon/sqs/javamessaging/MessageListenerConcurrentOperationTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,6 @@ public void verify() {
288288

289289
public void testConcurrentExecution(final MessageListener msgListener, final ConcurrentOperation operation) throws JMSException, InterruptedException {
290290

291-
//long start = System.currentTimeMillis();
292-
293291
// Start the session
294292
operation.setup();
295293

src/test/java/com/amazon/sqs/javamessaging/SQSMessageConsumerPrefetchFifoTest.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,27 @@ public boolean matches(Object argument) {
195195
for (SQSMessageConsumerPrefetch.MessageManager messageManager : consumerPrefetch.messageQueue) {
196196
Message mockedMessage = messages.get(index);
197197
SQSMessage sqsMessage = (SQSMessage)messageManager.getMessage();
198-
assertEquals("Receipt handle is the same", mockedMessage.receiptHandle(), sqsMessage.getReceiptHandle());
199-
assertEquals("Group id is the same", mockedMessage.attributes().get(MessageSystemAttributeName.fromValue(SQSMessagingClientConstants.MESSAGE_GROUP_ID)), sqsMessage.getStringProperty(SQSMessagingClientConstants.JMSX_GROUP_ID));
200-
assertEquals("Sequence number is the same", mockedMessage.attributes().get(MessageSystemAttributeName.fromValue(SQSMessagingClientConstants.SEQUENCE_NUMBER)), sqsMessage.getStringProperty(SQSMessagingClientConstants.JMS_SQS_SEQUENCE_NUMBER));
201-
assertEquals("Deduplication id is the same", mockedMessage.attributes().get(MessageSystemAttributeName.fromValue(SQSMessagingClientConstants.MESSAGE_DEDUPLICATION_ID)), sqsMessage.getStringProperty(SQSMessagingClientConstants.JMS_SQS_DEDUPLICATION_ID));
198+
assertEquals(
199+
"Receipt handle is the same",
200+
mockedMessage.receiptHandle(), sqsMessage.getReceiptHandle());
201+
assertEquals(
202+
"Group id is the same",
203+
mockedMessage
204+
.attributes()
205+
.get(MessageSystemAttributeName.fromValue(SQSMessagingClientConstants.MESSAGE_GROUP_ID)),
206+
sqsMessage.getStringProperty(SQSMessagingClientConstants.JMSX_GROUP_ID));
207+
assertEquals(
208+
"Sequence number is the same",
209+
mockedMessage
210+
.attributes()
211+
.get(MessageSystemAttributeName.fromValue(SQSMessagingClientConstants.SEQUENCE_NUMBER)),
212+
sqsMessage.getStringProperty(SQSMessagingClientConstants.JMS_SQS_SEQUENCE_NUMBER));
213+
assertEquals(
214+
"Deduplication id is the same",
215+
mockedMessage
216+
.attributes()
217+
.get(MessageSystemAttributeName.fromValue(SQSMessagingClientConstants.MESSAGE_DEDUPLICATION_ID)),
218+
sqsMessage.getStringProperty(SQSMessagingClientConstants.JMS_SQS_DEDUPLICATION_ID));
202219

203220
index++;
204221
}

0 commit comments

Comments
 (0)