Skip to content

Commit bec50bd

Browse files
committed
updating fork with master repo
1 parent ec1b383 commit bec50bd

File tree

55 files changed

+2205
-391
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2205
-391
lines changed

NOTICE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Amazon SQS Java Messaging Library
2-
Copyright 2010-2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33

44
This product includes software developed by
55
Amazon Technologies, Inc (http://www.amazon.com/).

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,22 @@ for communicating with Amazon Simple Queue Service. This project builds on top o
66
* You can download release builds through the [releases section of this](https://github.com/awslabs/amazon-sqs-java-messaging-lib) project.
77
* For more information on using the amazon-sqs-java-messaging-lib, see our getting started guide to SQS [here](http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/jmsclient.html).
88

9-
##Getting Started
9+
## Getting Started
1010

1111
* **Sign up for AWS** — Before you begin, you need an AWS account. For more information about creating an AWS account and retrieving your AWS credentials, see [AWS Account and Credentials](http://docs.aws.amazon.com/AWSSdkDocsJava/latest/DeveloperGuide/java-dg-setup.html) in the AWS SDK for Java Developer Guide.
12-
* **Sign up for Amazon SQS** — Go to the Amazon [SQS console](https://console.aws.amazon.com/sqs/home?region=us-east-1) to sign up for the service.
13-
* **Minimum requirements** — To use the sample application, you'll need Java 1.7+ and [Maven 3](http://maven.apache.org/). For more information about the requirements, see the [Getting Started](http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/jmsclient.html) section of the Amazon SQS Developer Guide.
14-
* **Download** — Download the [latest preview release](https://github.com/awslabs/amazon-sqs-java-messaging-lib/releases) or pick it up from Maven:
12+
* **Minimum requirements** — To use the sample application, you'll need Java 7 (or later) and [Maven 3](http://maven.apache.org/). For more information about the requirements, see the [Getting Started](http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/jmsclient.html) section of the Amazon SQS Developer Guide.
13+
* **Download** — Download the [latest release](https://github.com/awslabs/amazon-sqs-java-messaging-lib/releases) or pick it up from Maven:
1514
```xml
1615
<dependency>
1716
<groupId>com.amazonaws</groupId>
1817
<artifactId>amazon-sqs-java-messaging-lib</artifactId>
19-
<version>1.0.0</version>
18+
<version>1.0.4</version>
2019
<type>jar</type>
2120
</dependency>
2221
```
2322
* **Further information** - Read the [API documentation](http://aws.amazon.com/documentation/sqs/).
2423

25-
##Feedback
24+
## Feedback
2625
* Give us feedback [here](https://github.com/awslabs/amazon-sqs-java-messaging-lib/issues).
2726
* If you'd like to contribute a new feature or bug fix, we'd love to see Github pull requests from you.
2827

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.amazonaws</groupId>
88
<artifactId>amazon-sqs-java-messaging-lib</artifactId>
9-
<version>1.0.1</version>
9+
<version>1.0.4</version>
1010
<packaging>jar</packaging>
1111
<name>Amazon SQS Java Messaging Library</name>
1212
<description>The Amazon SQS Java Messaging Library holds the Java Message Service compatible classes, that are used
@@ -38,7 +38,7 @@
3838
</developers>
3939

4040
<properties>
41-
<aws-java-sdk.version>1.11.18</aws-java-sdk.version>
41+
<aws-java-sdk.version>1.11.106</aws-java-sdk.version>
4242
</properties>
4343

4444
<dependencies>

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

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.
@@ -26,6 +26,8 @@
2626

2727
import com.amazonaws.AmazonClientException;
2828
import com.amazonaws.AmazonServiceException;
29+
import com.amazonaws.AmazonWebServiceRequest;
30+
import com.amazonaws.auth.AWSCredentialsProvider;
2931
import com.amazonaws.regions.Region;
3032
import com.amazonaws.services.sqs.AmazonSQS;
3133
import com.amazonaws.services.sqs.model.ChangeMessageVisibilityBatchRequest;
@@ -67,6 +69,7 @@ public class AmazonSQSMessagingClientWrapper {
6769
}
6870

6971
private final AmazonSQS amazonSQSClient;
72+
private final AWSCredentialsProvider credentialsProvider;
7073

7174
/**
7275
* @param amazonSQSClient
@@ -75,10 +78,21 @@ public class AmazonSQSMessagingClientWrapper {
7578
* if the client is null
7679
*/
7780
public AmazonSQSMessagingClientWrapper(AmazonSQS amazonSQSClient) throws JMSException {
81+
this(amazonSQSClient, null);
82+
}
83+
84+
/**
85+
* @param amazonSQSClient
86+
* The AWS SDK Client for SQS.
87+
* @throws JMSException
88+
* if the client is null
89+
*/
90+
public AmazonSQSMessagingClientWrapper(AmazonSQS amazonSQSClient, AWSCredentialsProvider credentialsProvider) throws JMSException {
7891
if (amazonSQSClient == null) {
7992
throw new JMSException("Amazon SQS client cannot be null");
8093
}
8194
this.amazonSQSClient = amazonSQSClient;
95+
this.credentialsProvider = credentialsProvider;
8296
}
8397

8498
/**
@@ -92,13 +106,15 @@ public AmazonSQS getAmazonSQSClient() {
92106
}
93107

94108
/**
95-
* Sets SQS endpoint and wraps IllegalArgumentException.
109+
* Sets SQS endpoint and wraps IllegalArgumentException.
110+
* Deprecated. Instead of manipulating settings of existing AmazonSQS client, provide correct configuration when creating it through SQSConnectionFactory constructors.
96111
*
97112
* @param endpoint
98113
* The endpoint (ex: "sqs.us-east-1.amazonaws.com") of the region
99114
* specific AWS endpoint this client will communicate with.
100115
* @throws JMSException
101116
*/
117+
@Deprecated
102118
public void setEndpoint(String endpoint) throws JMSException {
103119
try {
104120
amazonSQSClient.setEndpoint(endpoint);
@@ -109,15 +125,16 @@ public void setEndpoint(String endpoint) throws JMSException {
109125
}
110126

111127
/**
112-
* Sets SQS region and wraps <code>IllegalArgumentException</code>. This is the recommend
113-
* way to set-up the SQS end-points.
128+
* Sets SQS region and wraps <code>IllegalArgumentException</code>.
129+
* Deprecated. Instead of manipulating settings of existing AmazonSQS client, provide correct configuration when creating it through SQSConnectionFactory constructors.
114130
*
115131
* @param region
116132
* The region this client will communicate with. See
117133
* {@link Region#getRegion(com.amazonaws.regions.Regions)} for
118134
* accessing a given region.
119135
* @throws JMSException
120136
*/
137+
@Deprecated
121138
public void setRegion(Region region) throws JMSException {
122139
try {
123140
amazonSQSClient.setRegion(region);
@@ -138,6 +155,7 @@ public void setRegion(Region region) throws JMSException {
138155
*/
139156
public void deleteMessage(DeleteMessageRequest deleteMessageRequest) throws JMSException {
140157
try {
158+
prepareRequest(deleteMessageRequest);
141159
amazonSQSClient.deleteMessage(deleteMessageRequest);
142160
} catch (AmazonClientException e) {
143161
throw handleException(e, "deleteMessage");
@@ -160,6 +178,7 @@ public void deleteMessage(DeleteMessageRequest deleteMessageRequest) throws JMSE
160178
*/
161179
public DeleteMessageBatchResult deleteMessageBatch(DeleteMessageBatchRequest deleteMessageBatchRequest) throws JMSException {
162180
try {
181+
prepareRequest(deleteMessageBatchRequest);
163182
return amazonSQSClient.deleteMessageBatch(deleteMessageBatchRequest);
164183
} catch (AmazonClientException e) {
165184
throw handleException(e, "deleteMessageBatch");
@@ -179,6 +198,7 @@ public DeleteMessageBatchResult deleteMessageBatch(DeleteMessageBatchRequest del
179198
*/
180199
public SendMessageResult sendMessage(SendMessageRequest sendMessageRequest) throws JMSException {
181200
try {
201+
prepareRequest(sendMessageRequest);
182202
return amazonSQSClient.sendMessage(sendMessageRequest);
183203
} catch (AmazonClientException e) {
184204
throw handleException(e, "sendMessage");
@@ -197,7 +217,7 @@ public SendMessageResult sendMessage(SendMessageRequest sendMessageRequest) thro
197217
*/
198218
public boolean queueExists(String queueName) throws JMSException {
199219
try {
200-
amazonSQSClient.getQueueUrl(new GetQueueUrlRequest(queueName));
220+
amazonSQSClient.getQueueUrl(prepareRequest(new GetQueueUrlRequest(queueName)));
201221
return true;
202222
} catch (QueueDoesNotExistException e) {
203223
return false;
@@ -223,6 +243,7 @@ public boolean queueExists(String queueName, String queueOwnerAccountId) throws
223243
try {
224244
GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest(queueName);
225245
getQueueUrlRequest.setQueueOwnerAWSAccountId(queueOwnerAccountId);
246+
prepareRequest(getQueueUrlRequest);
226247
amazonSQSClient.getQueueUrl(getQueueUrlRequest);
227248
return true;
228249
} catch (QueueDoesNotExistException e) {
@@ -254,9 +275,7 @@ public GetQueueUrlResult getQueueUrl(String queueName) throws JMSException {
254275
* @throws JMSException
255276
*/
256277
public GetQueueUrlResult getQueueUrl(String queueName, String queueOwnerAccountId) throws JMSException {
257-
GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest(queueName);
258-
getQueueUrlRequest.setQueueOwnerAWSAccountId(queueOwnerAccountId);
259-
return getQueueUrl(getQueueUrlRequest);
278+
return getQueueUrl(new GetQueueUrlRequest(queueName).withQueueOwnerAWSAccountId(queueOwnerAccountId));
260279
}
261280

262281
/**
@@ -271,6 +290,7 @@ public GetQueueUrlResult getQueueUrl(String queueName, String queueOwnerAccountI
271290
*/
272291
public GetQueueUrlResult getQueueUrl(GetQueueUrlRequest getQueueUrlRequest) throws JMSException {
273292
try {
293+
prepareRequest(getQueueUrlRequest);
274294
return amazonSQSClient.getQueueUrl(getQueueUrlRequest);
275295
} catch (AmazonClientException e) {
276296
throw handleException(e, "getQueueUrl");
@@ -288,11 +308,7 @@ public GetQueueUrlResult getQueueUrl(GetQueueUrlRequest getQueueUrlRequest) thro
288308
* @throws JMSException
289309
*/
290310
public CreateQueueResult createQueue(String queueName) throws JMSException {
291-
try {
292-
return amazonSQSClient.createQueue(queueName);
293-
} catch (AmazonClientException e) {
294-
throw handleException(e, "createQueue");
295-
}
311+
return createQueue(new CreateQueueRequest(queueName));
296312
}
297313

298314
/**
@@ -309,6 +325,7 @@ public CreateQueueResult createQueue(String queueName) throws JMSException {
309325
*/
310326
public CreateQueueResult createQueue(CreateQueueRequest createQueueRequest) throws JMSException {
311327
try {
328+
prepareRequest(createQueueRequest);
312329
return amazonSQSClient.createQueue(createQueueRequest);
313330
} catch (AmazonClientException e) {
314331
throw handleException(e, "createQueue");
@@ -330,6 +347,7 @@ public CreateQueueResult createQueue(CreateQueueRequest createQueueRequest) thro
330347
*/
331348
public ReceiveMessageResult receiveMessage(ReceiveMessageRequest receiveMessageRequest) throws JMSException {
332349
try {
350+
prepareRequest(receiveMessageRequest);
333351
return amazonSQSClient.receiveMessage(receiveMessageRequest);
334352
} catch (AmazonClientException e) {
335353
throw handleException(e, "receiveMessage");
@@ -347,6 +365,7 @@ public ReceiveMessageResult receiveMessage(ReceiveMessageRequest receiveMessageR
347365
*/
348366
public void changeMessageVisibility(ChangeMessageVisibilityRequest changeMessageVisibilityRequest) throws JMSException {
349367
try {
368+
prepareRequest(changeMessageVisibilityRequest);
350369
amazonSQSClient.changeMessageVisibility(changeMessageVisibilityRequest);
351370
} catch (AmazonClientException e) {
352371
throw handleException(e, "changeMessageVisibility");
@@ -368,6 +387,7 @@ public void changeMessageVisibility(ChangeMessageVisibilityRequest changeMessage
368387
public ChangeMessageVisibilityBatchResult changeMessageVisibilityBatch(ChangeMessageVisibilityBatchRequest changeMessageVisibilityBatchRequest)
369388
throws JMSException {
370389
try {
390+
prepareRequest(changeMessageVisibilityBatchRequest);
371391
return amazonSQSClient.changeMessageVisibilityBatch(changeMessageVisibilityBatchRequest);
372392
} catch (AmazonClientException e) {
373393
throw handleException(e, "changeMessageVisibilityBatch");
@@ -422,4 +442,13 @@ private JMSException handleException(AmazonClientException e, String operationNa
422442
private boolean isJMSSecurityException(AmazonServiceException e) {
423443
return SECURITY_EXCEPTION_ERROR_CODES.contains(e.getErrorCode()) ;
424444
}
445+
446+
private <T extends AmazonWebServiceRequest> T prepareRequest(T request) {
447+
request.getRequestClientOptions().appendUserAgent(SQSMessagingClientConstants.APPENDED_USER_AGENT_HEADER_VERSION);
448+
if (credentialsProvider != null) {
449+
request.setRequestCredentialsProvider(credentialsProvider);
450+
}
451+
return request;
452+
}
453+
425454
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.
@@ -27,6 +27,12 @@ public interface PrefetchManager {
2727
*/
2828
public void messageDispatched();
2929

30+
/**
31+
* Notify the prefetchThread that the message listener has finished with any
32+
* previous message and is ready to accept another.
33+
*/
34+
public void messageListenerReady();
35+
3036
/**
3137
* This is used to determine the state of the consumer, when the message
3238
* listener scheduler is processing the messages.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
package com.amazon.sqs.javamessaging;
16+
17+
public class ProviderConfiguration {
18+
private int numberOfMessagesToPrefetch;
19+
20+
public ProviderConfiguration() {
21+
// Set default numberOfMessagesToPrefetch to MIN_BATCH.
22+
this.numberOfMessagesToPrefetch = SQSMessagingClientConstants.MIN_BATCH;
23+
}
24+
25+
public int getNumberOfMessagesToPrefetch() {
26+
return numberOfMessagesToPrefetch;
27+
}
28+
29+
public void setNumberOfMessagesToPrefetch(int numberOfMessagesToPrefetch) {
30+
if (numberOfMessagesToPrefetch < SQSMessagingClientConstants.MIN_PREFETCH) {
31+
throw new IllegalArgumentException(String.format("Invalid prefetch size. Provided value '%1$s' cannot be smaller than '%2$s'", numberOfMessagesToPrefetch, SQSMessagingClientConstants.MIN_PREFETCH));
32+
}
33+
this.numberOfMessagesToPrefetch = numberOfMessagesToPrefetch;
34+
}
35+
36+
public ProviderConfiguration withNumberOfMessagesToPrefetch(int numberOfMessagesToPrefetch) {
37+
setNumberOfMessagesToPrefetch(numberOfMessagesToPrefetch);
38+
return this;
39+
}
40+
41+
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.
@@ -18,11 +18,8 @@
1818
import java.util.Set;
1919
import java.util.concurrent.ConcurrentHashMap;
2020

21-
2221
import javax.jms.IllegalStateException;
23-
2422
import javax.jms.Connection;
25-
2623
import javax.jms.ConnectionConsumer;
2724
import javax.jms.ConnectionMetaData;
2825
import javax.jms.Destination;
@@ -93,7 +90,8 @@ public class SQSConnection implements Connection, QueueConnection {
9390

9491
/**
9592
* Configures the amount of messages that can be prefetched by a consumer. A
96-
* single consumer cannot prefetch more than 10 messages.
93+
* single consumer cannot prefetch more than 10 messages in a single call to SQS,
94+
* but it will make multiple calls as necessary.
9795
*/
9896
private final int numberOfMessagesToPrefetch;
9997
private volatile boolean closed = false;

0 commit comments

Comments
 (0)