Skip to content

Commit 7020fb3

Browse files
author
Patel, Mihir
committed
'Version 1.0.0 of the Amazon SQS Java Messaging Library'
1 parent d855c84 commit 7020fb3

36 files changed

+3438
-779
lines changed

NOTICE.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ Amazon Technologies, Inc (http://www.amazon.com/).
88
THIRD PARTY COMPONENTS
99
**********************
1010
This software includes third party software subject to the following copyrights:
11-
- Apache ActiveMQ (see: org.apache.activemq.util.TypeConversionSupport, org.apache.activemq.command.ActiveMQStreamMessage). Copyright 2005-2013 Apache Software Foundation
11+
- Apache ActiveMQ (see: org.apache.activemq.util.TypeConversionSupport), Copyright 2005-2013 Apache Software Foundation.
1212

13-
The licenses for these third party components are included in LICENSE.txt
13+
The licenses for these third party components are included in LICENSE.txt

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Amazon SQS Java Messaging Library
22
========================================
33
The **Amazon SQS Java Messaging Library** holds the Java Message Service compatible classes, that are used
4-
for communicating with Amazon Simple Queue Service. This project builds on top of the AWS SDK for Java to use Amazon SQS as the JMS (as defined in 1.1 specification) provider for the messaging applications without running any additional software.
4+
for communicating with Amazon Simple Queue Service. This project builds on top of the AWS SDK for Java to use Amazon SQS as the JMS (as defined in 1.1 specification) provider for the messaging applications without running any additional software.
55

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/SQSGettingStartedGuide/Welcome.html).
@@ -11,7 +11,7 @@ for communicating with Amazon Simple Queue Service. This project builds on top o
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.
1212
* **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.
1313
* **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/SQSGettingStartedGuide/Welcome.html) section of the Amazon SQS Developer Guide.
14-
* **Download** — Download the [latest preview release or](https://github.com/awslabs/amazon-sqs-java-messaging-lib/releases) pick it up from Maven:
14+
* **Download** — Download the [latest preview release](https://github.com/awslabs/amazon-sqs-java-messaging-lib/releases) or pick it up from Maven:
1515
```xml
1616
<dependency>
1717
<groupId>com.amazonaws</groupId>
@@ -25,4 +25,3 @@ for communicating with Amazon Simple Queue Service. This project builds on top o
2525
##Feedback
2626
* Give us feedback [here](https://github.com/awslabs/amazon-sqs-java-messaging-lib/issues).
2727
* If you'd like to contribute a new feature or bug fix, we'd love to see Github pull requests from you.
28-

src/main/java/com/amazonaws/sqsjms/AmazonSQSClientJMSWrapper.java

Lines changed: 95 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
import com.amazonaws.services.sqs.model.SendMessageResult;
4646

4747
/**
48-
* This is a JMS Wrapper of AmazonSQSClient. This class changes all
49-
* AmazonServiceException and AmazonClientException into
48+
* This is a JMS Wrapper of <code>AmazonSQSClient</code>. This class changes all
49+
* <code>AmazonServiceException</code> and <code>AmazonClientException</code> into
5050
* JMSException/JMSSecurityException.
5151
*/
5252
public class AmazonSQSClientJMSWrapper {
@@ -57,7 +57,7 @@ public class AmazonSQSClientJMSWrapper {
5757
/**
5858
* List of exceptions that can classified as security. These exceptions
5959
* are not thrown during connection-set-up rather after the service
60-
* calls of the AmazonSQSClient
60+
* calls of the <code>AmazonSQSClient</code>.
6161
*/
6262
SECURITY_EXCEPTION_ERROR_CODES = new HashSet<String>();
6363
SECURITY_EXCEPTION_ERROR_CODES.add("MissingClientTokenId");
@@ -84,14 +84,16 @@ public AmazonSQSClientJMSWrapper(AmazonSQS amazonSQSClient) throws JMSException
8484
/**
8585
* If one uses any other AWS SDK operations other than explicitly listed
8686
* here, the exceptions thrown by those operations will not be wrapped as
87-
* JMSExceptions.
87+
* <code>JMSException</code>.
8888
* @return amazonSQSClient
8989
*/
9090
public AmazonSQS getAmazonSQSClient() {
9191
return amazonSQSClient;
9292
}
9393

9494
/**
95+
* Sets SQS endpoint and wraps IllegalArgumentException.
96+
*
9597
* @param endpoint
9698
* The endpoint (ex: "sqs.us-east-1.amazonaws.com") of the region
9799
* specific AWS endpoint this client will communicate with.
@@ -107,6 +109,9 @@ public void setEndpoint(String endpoint) throws JMSException {
107109
}
108110

109111
/**
112+
* Sets SQS region and wraps <code>IllegalArgumentException</code>. This is the recommend
113+
* way to set-up the SQS end-points.
114+
*
110115
* @param region
111116
* The region this client will communicate with. See
112117
* {@link Region#getRegion(com.amazonaws.regions.Regions)} for
@@ -123,6 +128,9 @@ public void setRegion(Region region) throws JMSException {
123128
}
124129

125130
/**
131+
* Calls <code>deleteMessage</code> and wraps <code>AmazonClientException</code>. This is used to
132+
* acknowledge single messages, so that they can be deleted from SQS queue.
133+
*
126134
* @param deleteMessageRequest
127135
* Container for the necessary parameters to execute the
128136
* deleteMessage service method on AmazonSQS.
@@ -137,10 +145,17 @@ public void deleteMessage(DeleteMessageRequest deleteMessageRequest) throws JMSE
137145
}
138146

139147
/**
148+
* Calls <code>deleteMessageBatch</code> and wraps
149+
* <code>AmazonClientException</code>. This is used to acknowledge multiple
150+
* messages on client_acknowledge mode, so that they can be deleted from SQS
151+
* queue.
152+
*
140153
* @param deleteMessageBatchRequest
141154
* Container for the necessary parameters to execute the
142155
* deleteMessageBatch service method on AmazonSQS. This is the
143156
* batch version of deleteMessage. Max batch size is 10.
157+
* @return The response from the deleteMessageBatch service method, as
158+
* returned by AmazonSQS
144159
* @throws JMSException
145160
*/
146161
public DeleteMessageBatchResult deleteMessageBatch(DeleteMessageBatchRequest deleteMessageBatchRequest) throws JMSException {
@@ -152,9 +167,14 @@ public DeleteMessageBatchResult deleteMessageBatch(DeleteMessageBatchRequest del
152167
}
153168

154169
/**
170+
* Calls <code>sendMessage</code> and wraps
171+
* <code>AmazonClientException</code>.
172+
*
155173
* @param sendMessageRequest
156174
* Container for the necessary parameters to execute the
157175
* sendMessage service method on AmazonSQS.
176+
* @return The response from the sendMessage service method, as returned by
177+
* AmazonSQS
158178
* @throws JMSException
159179
*/
160180
public SendMessageResult sendMessage(SendMessageRequest sendMessageRequest) throws JMSException {
@@ -166,11 +186,12 @@ public SendMessageResult sendMessage(SendMessageRequest sendMessageRequest) thro
166186
}
167187

168188
/**
169-
* Check if the requested queue exists. This function works by calling
170-
* GetQueueUrl for the given queue name, returning true on
171-
* success, false if it gets QueueDoesNotExistException.
189+
* Check if the requested queue exists. This function calls
190+
* <code>GetQueueUrl</code> for the given queue name, returning true on
191+
* success, false if it gets <code>QueueDoesNotExistException</code>.
172192
*
173-
* @param queueName the queue to check
193+
* @param queueName
194+
* the queue to check
174195
* @return true if the queue exists, false if it doesn't.
175196
* @throws JMSException
176197
*/
@@ -186,6 +207,34 @@ public boolean queueExists(String queueName) throws JMSException {
186207
}
187208

188209
/**
210+
* Check if the requested queue exists. This function calls
211+
* <code>GetQueueUrl</code> for the given queue name with the given owner
212+
* accountId, returning true on success, false if it gets
213+
* <code>QueueDoesNotExistException</code>.
214+
*
215+
* @param queueName
216+
* the queue to check
217+
* @param queueOwnerAccountId
218+
* The AWS accountId of the account that created the queue
219+
* @return true if the queue exists, false if it doesn't.
220+
* @throws JMSException
221+
*/
222+
public boolean queueExists(String queueName, String queueOwnerAccountId) throws JMSException {
223+
try {
224+
GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest(queueName);
225+
getQueueUrlRequest.setQueueOwnerAWSAccountId(queueOwnerAccountId);
226+
amazonSQSClient.getQueueUrl(getQueueUrlRequest);
227+
return true;
228+
} catch (QueueDoesNotExistException e) {
229+
return false;
230+
} catch (AmazonClientException e) {
231+
throw handleException(e, "getQueueUrl");
232+
}
233+
}
234+
235+
/**
236+
* Gets the queueUrl of a queue given a queue name.
237+
*
189238
* @param queueName
190239
* @return The response from the GetQueueUrl service method, as returned by
191240
* AmazonSQS, which will include queue`s URL
@@ -194,8 +243,25 @@ public boolean queueExists(String queueName) throws JMSException {
194243
public GetQueueUrlResult getQueueUrl(String queueName) throws JMSException {
195244
return getQueueUrl(new GetQueueUrlRequest(queueName));
196245
}
246+
247+
/**
248+
* Gets the queueUrl of a queue given a queue name owned by the provided accountId.
249+
*
250+
* @param queueName
251+
* @param queueOwnerAccountId The AWS accountId of the account that created the queue
252+
* @return The response from the GetQueueUrl service method, as returned by
253+
* AmazonSQS, which will include queue`s URL
254+
* @throws JMSException
255+
*/
256+
public GetQueueUrlResult getQueueUrl(String queueName, String queueOwnerAccountId) throws JMSException {
257+
GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest(queueName);
258+
getQueueUrlRequest.setQueueOwnerAWSAccountId(queueOwnerAccountId);
259+
return getQueueUrl(getQueueUrlRequest);
260+
}
197261

198262
/**
263+
* Calls <code>getQueueUrl</code> and wraps <code>AmazonClientException</code>
264+
*
199265
* @param getQueueUrlRequest
200266
* Container for the necessary parameters to execute the
201267
* getQueueUrl service method on AmazonSQS.
@@ -212,7 +278,8 @@ public GetQueueUrlResult getQueueUrl(GetQueueUrlRequest getQueueUrlRequest) thro
212278
}
213279

214280
/**
215-
* This function creates the queue with the default queue attributes.
281+
* Calls <code>createQueue</code> to create the queue with the default queue attributes,
282+
* and wraps <code>AmazonClientException</code>
216283
*
217284
* @param queueName
218285
* @return The response from the createQueue service method, as returned by
@@ -229,6 +296,9 @@ public CreateQueueResult createQueue(String queueName) throws JMSException {
229296
}
230297

231298
/**
299+
* Calls <code>createQueue</code> to create the queue with the provided queue attributes
300+
* if any, and wraps <code>AmazonClientException</code>
301+
*
232302
* @param createQueueRequest
233303
* Container for the necessary parameters to execute the
234304
* createQueue service method on AmazonSQS.
@@ -246,6 +316,11 @@ public CreateQueueResult createQueue(CreateQueueRequest createQueueRequest) thro
246316
}
247317

248318
/**
319+
* Calls <code>receiveMessage</code> and wraps <code>AmazonClientException</code>. Used by
320+
* {@link SQSMessageConsumerPrefetch} to receive up to minimum of
321+
* (<code>numberOfMessagesToPrefetch</code>,10) messages from SQS queue into consumer
322+
* prefetch buffers.
323+
*
249324
* @param receiveMessageRequest
250325
* Container for the necessary parameters to execute the
251326
* receiveMessage service method on AmazonSQS.
@@ -262,6 +337,9 @@ public ReceiveMessageResult receiveMessage(ReceiveMessageRequest receiveMessageR
262337
}
263338

264339
/**
340+
* Calls <code>changeMessageVisibility</code> and wraps <code>AmazonClientException</code>. This is
341+
* used to for negative acknowledge of a single message, so that messages can be received again without any delay.
342+
*
265343
* @param changeMessageVisibilityRequest
266344
* Container for the necessary parameters to execute the
267345
* changeMessageVisibility service method on AmazonSQS.
@@ -278,6 +356,10 @@ public void changeMessageVisibility(ChangeMessageVisibilityRequest changeMessage
278356
}
279357

280358
/**
359+
* Calls <code>changeMessageVisibilityBatch</code> and wraps <code>AmazonClientException</code>. This is
360+
* used to for negative acknowledge of messages in batch, so that messages
361+
* can be received again without any delay.
362+
*
281363
* @param changeMessageVisibilityBatchRequest
282364
* Container for the necessary parameters to execute the
283365
* changeMessageVisibilityBatch service method on AmazonSQS.
@@ -295,8 +377,8 @@ public ChangeMessageVisibilityBatchResult changeMessageVisibilityBatch(ChangeMes
295377
}
296378

297379
/**
298-
* Create generic error message for AmazonServiceException. Message include
299-
* ActionCall, RequestId, HTTPStatusCode, AmazonErrorCode.
380+
* Create generic error message for <code>AmazonServiceException</code>. Message include
381+
* Action, RequestId, HTTPStatusCode, and AmazonErrorCode.
300382
*/
301383
private String logAndGetAmazonServiceException(AmazonServiceException ase, String action) {
302384
String errorMessage = "AmazonServiceException: " + action + ". RequestId: " + ase.getRequestId() +
@@ -307,8 +389,8 @@ private String logAndGetAmazonServiceException(AmazonServiceException ase, Strin
307389
}
308390

309391
/**
310-
* Create generic error message for AmazonClientException. Message include
311-
* ActionCall.
392+
* Create generic error message for <code>AmazonClientException</code>. Message include
393+
* Action.
312394
*/
313395
private String logAndGetAmazonClientException(AmazonClientException ace, String action) {
314396
String errorMessage = "AmazonClientException: " + action + ".";

src/main/java/com/amazonaws/sqsjms/BulkSQSOperation.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,21 @@
3131
public abstract class BulkSQSOperation {
3232

3333
/**
34-
* Bulk action on list of message identifiers up to the indexOfMessage.
34+
* Bulk action on list of message identifiers up to the provided index
35+
*
36+
* @param messageIdentifierList
37+
* Container for the list of message identifiers
38+
* @param indexOfMessage
39+
* The action will apply to all messages up to this index
40+
* @throws JMSException
41+
* if <code>action</code> throws
3542
*/
3643
public void bulkAction(List<SQSMessageIdentifier> messageIdentifierList, int indexOfMessage)
3744
throws JMSException {
45+
46+
assert indexOfMessage > 0;
47+
assert indexOfMessage <= messageIdentifierList.size();
48+
3849
Map<String, List<String>> receiptHandleWithSameQueueUrl = new HashMap<String, List<String>>();
3950

4051
// Add all messages up to and including requested message into Map.
@@ -66,7 +77,15 @@ public void bulkAction(List<SQSMessageIdentifier> messageIdentifierList, int ind
6677
}
6778

6879
/**
69-
* Action call block for bulk action.
80+
* Action call block. This action can be applied on multiple messages for
81+
* the same queue.
82+
*
83+
* @param queueUrl
84+
* queueUrl of the queue, which the receipt handles belong
85+
* @param receiptHandles
86+
* the list of handles, which is be used to (negative)acknowledge
87+
* the messages.
88+
* @throws JMSException
7089
*/
7190
public abstract void action(String queueUrl, List<String> receiptHandles) throws JMSException;
7291

src/main/java/com/amazonaws/sqsjms/PrefetchManager.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
package com.amazonaws.sqsjms;
1616

1717
/**
18-
* This interface is helper to notify when the prefetch should be resumed.
18+
* This interface is helper to notify when the prefetchThread should be resuming
19+
* messages.
1920
*/
2021
public interface PrefetchManager {
2122

@@ -25,6 +26,12 @@ public interface PrefetchManager {
2526
* called.
2627
*/
2728
public void messageDispatched();
28-
29+
30+
/**
31+
* This is used to determine the state of the consumer, when the message
32+
* listener scheduler is processing the messages.
33+
*
34+
* @return The message consumer, which owns the prefetchThread
35+
*/
2936
public SQSMessageConsumer getMessageConsumer();
30-
}
37+
}

0 commit comments

Comments
 (0)