modularized sqs

This commit is contained in:
Adrian Cole 2012-09-14 09:11:04 -07:00
parent 00da07aec4
commit 887d4d1de8
12 changed files with 977 additions and 653 deletions

View File

@ -0,0 +1,209 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License 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 org.jclouds.sqs;
import java.net.URI;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.sqs.domain.Message;
import org.jclouds.sqs.domain.MessageIdAndMD5;
import org.jclouds.sqs.options.ReceiveMessageOptions;
import org.jclouds.sqs.options.SendMessageOptions;
/**
* Provides access to SQS via their REST API.
* <p/>
*
* @see SQSAsyncApi
* @author Adrian Cole
*/
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
public interface MessageApi {
/**
* The DeleteMessage action deletes the specified message from the specified
* queue. You specify the message by using the message's receipt handle and
* not the message ID you received when you sent the message. Even if the
* message is locked by another reader due to the visibility timeout setting,
* it is still deleted from the queue. If you leave a message in the queue
* for more than 4 days, SQS automatically deletes it.
*
* <h4>Note</h4>
*
* The receipt handle is associated with a specific instance of receiving the
* message. If you receive a message more than once, the receipt handle you
* get each time you receive the message is different. When you request
* DeleteMessage, if you don't provide the most recently received receipt
* handle for the message, the request will still succeed, but the message
* might not be deleted.
*
* <h4>Important</h4>
*
* It is possible you will receive a message even after you have deleted it.
* This might happen on rare occasions if one of the servers storing a copy
* of the message is unavailable when you request to delete the message. The
* copy remains on the server and might be returned to you again on a
* subsequent receive request. You should create your system to be idempotent
* so that receiving a particular message more than once is not a problem.
*
* @param queue
* the queue the message is in
* @param receiptHandle
* The receipt handle associated with the message you want to
* delete.
*/
void delete(String receiptHandle);
/**
* The ChangeMessageVisibility action changes the visibility timeout of a
* specified message in a queue to a new value. The maximum allowed timeout
* value you can set the value to is 12 hours. This means you can't extend
* the timeout of a message in an existing queue to more than a total
* visibility timeout of 12 hours. (For more information visibility timeout,
* see Visibility Timeout in the Amazon SQS Developer Guide.)
*
* For example, let's say the timeout for the queue is 30 seconds, and you
* receive a message. Once you're 20 seconds into the timeout for that
* message (i.e., you have 10 seconds left), you extend it by 60 seconds by
* calling ChangeMessageVisibility with VisibilityTimeoutset to 60 seconds.
* You have then changed the remaining visibility timeout from 10 seconds to
* 60 seconds.
*
* <h4>Important</h4>
*
* If you attempt to set the VisibilityTimeout to an amount more than the
* maximum time left, Amazon SQS returns an error. It will not automatically
* recalculate and increase the timeout to the maximum time remaining.
*
* <h4>Important</h4>
*
* Unlike with a queue, when you change the visibility timeout for a specific
* message, that timeout value is applied immediately but is not saved in
* memory for that message. If you don't delete a message after it is
* received, the visibility timeout for the message the next time it is
* received reverts to the original timeout value, not the value you set with
* the ChangeMessageVisibility action.
*
* @param queue
* the queue the message is in
* @param receiptHandle
* The receipt handle associated with the message whose visibility
* timeout you want to change. This parameter is returned by the
* ReceiveMessage action.
* @param visibilityTimeout
* The new value for the message's visibility timeout (in seconds)
* from 0 to 43200 (maximum 12 hours)
*/
void changeVisibility(String receiptHandle, int visibilityTimeout);
/**
* The SendMessage action delivers a message to the specified queue. The
* maximum allowed message size is 64 KB.
*
* <h4>Important</h4>
*
* The following list shows the characters (in Unicode) allowed in your
* message, according to the W3C XML specification (for more information, go
* to http://www.w3.org/TR/REC-xml/#charsets). If you send any characters not
* included in the list, your request will be rejected.
*
*
* {@code #x9 | #xA | #xD | [#x20 to #xD7FF] | [#xE000 to #xFFFD] | [#x10000 to #x10FFFF]}
*
* @param queue
* queue you want to send to
*
* @param message
* Type: String maximum 64 KB in size. For a list of allowed
* characters, see the preceding important note.
* @return id of the message and md5 of the content sent
*/
MessageIdAndMD5 send(String message);
/**
* same as {@link #sendMessage(URI, String)} except you can control options
* such as delay seconds.
*
* @param options
* options such as delay seconds
* @see #sendMessage(URI, String)
*/
MessageIdAndMD5 send(String message, SendMessageOptions options);
/**
* The ReceiveMessage action retrieves one or more messages from the
* specified queue. The ReceiveMessage action does not delete the message
* after it is retrieved. To delete a message, you must use the DeleteMessage
* action. For more information about message deletion in the message life
* cycle, see Message Lifecycle.
*
* <h4>Note</h4>
*
* Due to the distributed nature of the queue, a weighted random set of
* machines is sampled on a ReceiveMessage call. That means only the messages
* on the sampled machines are returned. If the number of messages in the
* queue is small (less than 1000), it is likely you will get fewer messages
* than you requested per ReceiveMessage call. If the number of messages in
* the queue is extremely small, you might not receive any messages in a
* particular ReceiveMessage response; in which case you should repeat the
* request.
*
* @param queue
* from where you are receiving messages
* @return message including the receipt handle you can use to delete it
*/
Message receive();
/**
* same as {@link #receive(URI)} except you can provide options like
* VisibilityTimeout parameter in your request, which will be applied to the
* messages that SQS returns in the response. If you do not include the
* parameter, the overall visibility timeout for the queue is used for the
* returned messages.
*
* @param options
* options such as VisibilityTimeout
* @see #receive(URI)
*/
Message receive(ReceiveMessageOptions options);
/**
* same as {@link #receive(URI)} except you can receive multiple messages.
*
* @param max
* maximum messages to receive, current limit is 10
* @see #receive(URI)
*/
Set<Message> receive(int max);
/**
* same as {@link #receive(URI, int)} except you can provide options like
* VisibilityTimeout parameter in your request, which will be applied to the
* messages that SQS returns in the response. If you do not include the
* parameter, the overall visibility timeout for the queue is used for the
* returned messages.
*
* @param options
* options such as VisibilityTimeout
* @see #receive(URI, int)
*/
Set<Message> receive(int max, ReceiveMessageOptions options);
}

View File

@ -0,0 +1,130 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License 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 org.jclouds.sqs;
import static org.jclouds.sqs.reference.SQSParameters.ACTION;
import static org.jclouds.sqs.reference.SQSParameters.VERSION;
import java.util.Set;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.jclouds.Constants;
import org.jclouds.aws.filters.FormSigner;
import org.jclouds.rest.annotations.FormParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.VirtualHost;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.sqs.domain.Message;
import org.jclouds.sqs.domain.MessageIdAndMD5;
import org.jclouds.sqs.options.ReceiveMessageOptions;
import org.jclouds.sqs.options.SendMessageOptions;
import org.jclouds.sqs.xml.MessageHandler;
import org.jclouds.sqs.xml.ReceiveMessageResponseHandler;
import org.jclouds.sqs.xml.RegexMessageIdAndMD5Handler;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides access to SQS via their REST API.
* <p/>
*
* @author Adrian Cole
*/
@RequestFilters(FormSigner.class)
@FormParams(keys = VERSION, values = "{" + Constants.PROPERTY_API_VERSION + "}")
@VirtualHost
public interface MessageAsyncApi {
/**
* @see SQSApi#delete
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "DeleteMessage")
ListenableFuture<Void> delete(@FormParam("ReceiptHandle") String receiptHandle);
/**
* @see SQSApi#changeVisibility
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ChangeMessageVisibility")
ListenableFuture<Void> changeVisibility(@FormParam("ReceiptHandle") String receiptHandle,
@FormParam("VisibilityTimeout") int visibilityTimeout);
/**
* @see SQSApi#send
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "SendMessage")
@ResponseParser(RegexMessageIdAndMD5Handler.class)
ListenableFuture<? extends MessageIdAndMD5> send(@FormParam("MessageBody") String message);
/**
* @see SQSApi#send
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "SendMessage")
@ResponseParser(RegexMessageIdAndMD5Handler.class)
ListenableFuture<? extends MessageIdAndMD5> send(@FormParam("MessageBody") String message, SendMessageOptions options);
/**
* @see SQSApi#receive
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ReceiveMessage")
@XMLResponseParser(MessageHandler.class)
ListenableFuture<Message> receive();
/**
* @see SQSApi#receive
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ReceiveMessage")
@XMLResponseParser(MessageHandler.class)
ListenableFuture<? extends Message> receive(ReceiveMessageOptions options);
/**
* @see SQSApi#receive
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ReceiveMessage")
@XMLResponseParser(ReceiveMessageResponseHandler.class)
ListenableFuture<? extends Set<? extends Message>> receive(@FormParam("MaxNumberOfMessages") int max);
/**
* @see SQSApi#receive
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ReceiveMessage")
@XMLResponseParser(ReceiveMessageResponseHandler.class)
ListenableFuture<? extends Set<? extends Message>> receive(@FormParam("MaxNumberOfMessages") int max,
ReceiveMessageOptions options);
}

View File

@ -0,0 +1,87 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License 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 org.jclouds.sqs;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.sqs.domain.Action;
/**
* Provides access to SQS via their REST API.
* <p/>
*
* @see SQSAsyncApi
* @author Adrian Cole
*/
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
public interface PermissionApi {
/**
* The AddPermission action adds a permission to a queue for a specific
* principal. This allows for sharing access to the queue.
*
* When you create a queue, you have full control access rights for the
* queue. Only you (as owner of the queue) can grant or deny permissions to
* the queue. For more information about these permissions, see Shared Queues
* in the Amazon SQS Developer Guide.
*
* Note
*
* AddPermission writes an SQS-generated policy. If you want to write your
* own policy, use SetQueueAttributes to upload your policy.
*
* @param queue
* queue to change permissions on
* @param label
*
* The unique identification of the permission you're setting.
* example: AliceSendMessage
*
* Constraints: Maximum 80 characters; alphanumeric characters,
* hyphens (-), and underscores (_) are allowed.
* @param permission
* The action you want to allow for the specified principal.
* @param accountId
* The AWS account number of the principal who will be given
* permission. The principal must have an AWS account, but does not
* need to be signed up for Amazon SQS. For information about
* locating the AWS account identification, see Your AWS
* Identifiers in the Amazon SQS Developer Guide.
*
* Constraints: Valid 12-digit AWS account number, without hyphens
*
*/
void addPermissionToAccount(String label, Action permission, String accountId);
/**
* The RemovePermission action revokes any permissions in the queue policy
* that matches the Label parameter. Only the owner of the queue can remove
* permissions.
*
* @param queue
* queue to change permissions on
*
* @param label
* The identification of the permission you want to remove. This is
* the label you added in AddPermission. example: AliceSendMessage
*/
void remove(String label);
}

View File

@ -0,0 +1,65 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License 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 org.jclouds.sqs;
import static org.jclouds.sqs.reference.SQSParameters.ACTION;
import static org.jclouds.sqs.reference.SQSParameters.VERSION;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.jclouds.Constants;
import org.jclouds.aws.filters.FormSigner;
import org.jclouds.rest.annotations.FormParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.VirtualHost;
import org.jclouds.sqs.domain.Action;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides access to SQS via their REST API.
* <p/>
*
* @author Adrian Cole
*/
@RequestFilters(FormSigner.class)
@FormParams(keys = VERSION, values = "{" + Constants.PROPERTY_API_VERSION + "}")
@VirtualHost
public interface PermissionAsyncApi {
/**
* @see SQSApi#addPermissionToAccount
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "AddPermission")
ListenableFuture<Void> addPermissionToAccount(@FormParam("Label") String label,
@FormParam("ActionName.1") Action permission, @FormParam("AWSAccountId.1") String accountId);
/**
* @see SQSApi#remove
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "RemovePermission")
ListenableFuture<Void> remove(@FormParam("Label") String label);
}

View File

@ -0,0 +1,212 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License 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 org.jclouds.sqs;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.sqs.domain.QueueAttributes;
import org.jclouds.sqs.options.CreateQueueOptions;
import org.jclouds.sqs.options.ListQueuesOptions;
/**
* Provides access to SQS via their REST API.
* <p/>
*
* @see SQSAsyncApi
* @author Adrian Cole
*/
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
public interface QueueApi {
/**
* The ListQueues action returns a list of your queues. The maximum number of
* queues that can be returned is 1000. If you specify a value for the
* optional QueueNamePrefix parameter, only queues with a name beginning with
* the specified value are returned
*
* @param region
* Queues are Region-specific.
* @param options
* specify prefix or other options
*
* @see <a href=
* "http://docs.amazonwebservices.com/AWSSimpleQueueService/2011-10-01/APIReference/Query_QueryListQueues.html"
* />
*/
Set<URI> list();
Set<URI> list(ListQueuesOptions options);
/**
* The CreateQueue action creates a new queue.
*
* When you request CreateQueue, you provide a name for the queue. To
* successfully create a new queue, you must provide a name that is unique
* within the scope of your own queues.
*
* <h4>Note</h4>
*
* If you delete a queue, you must wait at least 60 seconds before creating a
* queue with the same name.
*
* If you provide the name of an existing queue, along with the exact names
* and values of all the queue's attributes, CreateQueue returns the queue
* URL for the existing queue. If the queue name, attribute names, or
* attribute values do not match an existing queue, CreateQueue returns an
* error.
*
* <h4>Tip</h4>
*
* Use GetQueueUrl to get a queue's URL. GetQueueUrl requires only the
* QueueName parameter.
*
* @param region
* Queues are Region-specific.
* @param queueName
* The name to use for the queue created. Constraints: Maximum 80
* characters; alphanumeric characters, hyphens (-), and
* underscores (_) are allowed.
*/
// this will gracefully attempt to resolve name issues
@Timeout(duration = 61, timeUnit = TimeUnit.SECONDS)
URI create(String queueName);
/**
* same as {@link #create(String, String)} except you can
* control options such as delay seconds.
*
* @param options
* options such as delay seconds
* @see #create(String, String)
*/
@Timeout(duration = 61, timeUnit = TimeUnit.SECONDS)
URI create(String queueName, CreateQueueOptions options);
/**
* The DeleteQueue action deletes the queue specified by the queue URL,
* regardless of whether the queue is empty. If the specified queue does not
* exist, SQS returns a successful response.
*
* <h4>Caution</h4>
*
* Use DeleteQueue with care; once you delete your queue, any messages in the
* queue are no longer available.
*
* When you delete a queue, the deletion process takes up to 60 seconds.
* Requests you send involving that queue during the 60 seconds might
* succeed. For example, a SendMessage request might succeed, but after the
* 60 seconds, the queue and that message you sent no longer exist. Also,
* when you delete a queue, you must wait at least 60 seconds before creating
* a queue with the same name.
*
* We reserve the right to delete queues that have had no activity for more
* than 30 days. For more information, see About SQS Queues in the Amazon SQS
* Developer Guide.
*
* @param queue
* queue you want to delete
*/
void delete(URI queue);
/**
* returns all attributes of a queue.
*
* @param queue
* queue to get the attributes of
*/
QueueAttributes getAttributes(URI queue);
/**
* The SetQueueAttributes action sets one attribute of a queue per request.
* When you change a queue's attributes, the change can take up to 60 seconds
* to propagate throughout the SQS system.
*
* @param queue
* queue to set the attribute on
* @param name
*
* The name of the attribute you want to set.
*
* VisibilityTimeout - The length of time (in seconds) that a
* message received from a queue will be invisible to other
* receiving components when they ask to receive messages. For more
* information about VisibilityTimeout, see Visibility Timeout in
* the Amazon SQS Developer Guide.
*
* Policy - The formal description of the permissions for a
* resource. For more information about Policy, see Basic Policy
* Structure in the Amazon SQS Developer Guide.
*
* MaximumMessageSize - The limit of how many bytes a message can
* contain before Amazon SQS rejects it.
*
* MessageRetentionPeriod - The number of seconds Amazon SQS
* retains a message.
*
* DelaySeconds - The time in seconds that the delivery of all
* messages in the queue will be delayed.
* @param value
* The value of the attribute you want to set. To delete a queue's
* access control policy, set the policy to "".
*
* Constraints: Constraints are specific for each value.
*
* VisibilityTimeout - An integer from 0 to 43200 (12 hours). The
* default for this attribute is 30 seconds.
*
* Policy - A valid form-url-encoded policy. For more information
* about policy structure, see Basic Policy Structure in the Amazon
* SQS Developer Guide. For more information about
* form-url-encoding, see
* http://www.w3.org/MarkUp/html-spec/html-spec_8.html#SEC8.2.1.
*
* MaximumMessageSize - An integer from 1024 bytes (1 KiB) up to
* 65536 bytes (64 KiB). The default for this attribute is 65536
* (64 KiB).
*
* MessageRetentionPeriod - Integer representing seconds, from 60
* (1 minute) to 1209600 (14 days). The default for this attribute
* is 345600 (4 days).
*
* DelaySeconds - An integer from 0 to 900 (15 minutes). The
* default for this attribute is 0.
*/
void setAttribute(URI queue, String name, String value);
/**
* returns some attributes of a queue.
*
* @param queue
* queue to get the attributes of
*/
Map<String, String> getAttributes(URI queue, Iterable<String> attributeNames);
/**
* returns an attribute of a queue.
*
* @param queue
* queue to get the attributes of
*/
String getAttribute(URI queue, String attributeName);
}

View File

@ -0,0 +1,150 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License 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 org.jclouds.sqs;
import static org.jclouds.sqs.reference.SQSParameters.ACTION;
import static org.jclouds.sqs.reference.SQSParameters.VERSION;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.jclouds.Constants;
import org.jclouds.aws.filters.FormSigner;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.FormParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.Transform;
import org.jclouds.rest.annotations.VirtualHost;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.sqs.binders.BindAttributeNamesToIndexedFormParams;
import org.jclouds.sqs.domain.QueueAttributes;
import org.jclouds.sqs.functions.MapToQueueAttributes;
import org.jclouds.sqs.options.CreateQueueOptions;
import org.jclouds.sqs.options.ListQueuesOptions;
import org.jclouds.sqs.xml.AttributesHandler;
import org.jclouds.sqs.xml.RegexListQueuesResponseHandler;
import org.jclouds.sqs.xml.RegexQueueHandler;
import org.jclouds.sqs.xml.ValueHandler;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides access to SQS via their REST API.
* <p/>
*
* @author Adrian Cole
*/
@RequestFilters(FormSigner.class)
@FormParams(keys = VERSION, values = "{" + Constants.PROPERTY_API_VERSION + "}")
@VirtualHost
public interface QueueAsyncApi {
/**
* @see SQSApi#list
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ListQueues")
@ResponseParser(RegexListQueuesResponseHandler.class)
ListenableFuture<Set<URI>> list();
/**
* @see SQSApi#list
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ListQueues")
@ResponseParser(RegexListQueuesResponseHandler.class)
ListenableFuture<Set<URI>> list(ListQueuesOptions options);
/**
* @see SQSApi#create
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "CreateQueue")
@ResponseParser(RegexQueueHandler.class)
ListenableFuture<URI> create(@FormParam("QueueName") String queueName);
/**
* @see SQSApi#create
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "CreateQueue")
@ResponseParser(RegexQueueHandler.class)
ListenableFuture<URI> create(@FormParam("QueueName") String queueName, CreateQueueOptions options);
/**
* @see SQSApi#delete
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "DeleteQueue")
ListenableFuture<Void> delete(@EndpointParam URI queue);
/**
* @see SQSApi#getAttributes(URI)
*/
@POST
@Path("/")
@FormParams(keys = { ACTION, "AttributeName.1" }, values = { "GetQueueAttributes", "All" })
@Transform(MapToQueueAttributes.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@XMLResponseParser(AttributesHandler.class)
ListenableFuture<? extends QueueAttributes> getAttributes(@EndpointParam URI queue);
/**
* @see SQSApi#getAttributes(URI, Iterable)
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "GetQueueAttributes")
@XMLResponseParser(AttributesHandler.class)
ListenableFuture<Map<String, String>> getAttributes(@EndpointParam URI queue,
@BinderParam(BindAttributeNamesToIndexedFormParams.class) Iterable<String> attributeNames);
/**
* @see SQSApi#getAttribute
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "GetQueueAttributes")
@XMLResponseParser(ValueHandler.class)
ListenableFuture<String> getAttribute(@EndpointParam URI queue, @FormParam("AttributeName.1") String attributeName);
/**
* @see SQSApi#setAttribute
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "SetQueueAttributes")
ListenableFuture<Void> setAttribute(@EndpointParam URI queue, @FormParam("Attribute.Name") String name,
@FormParam("Attribute.Value") String value);
}

View File

@ -19,420 +19,57 @@
package org.jclouds.sqs;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.sqs.domain.Action;
import org.jclouds.sqs.domain.Message;
import org.jclouds.sqs.domain.MessageIdAndMD5;
import org.jclouds.sqs.domain.QueueAttributes;
import org.jclouds.sqs.options.CreateQueueOptions;
import org.jclouds.sqs.options.ListQueuesOptions;
import org.jclouds.sqs.options.ReceiveMessageOptions;
import org.jclouds.sqs.options.SendMessageOptions;
import org.jclouds.location.Region;
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.annotations.EndpointParam;
import com.google.common.annotations.Beta;
import com.google.inject.Provides;
/**
* Provides access to SQS via their REST API.
* <p/>
*
* @see SQSAsyncApi
* @author Adrian Cole
* @see SQSAsyncApi
*/
@Beta
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
public interface SQSApi {
/**
*
* @return the Region codes configured
*/
@Provides
@Region
Set<String> getConfiguredRegions();
/**
* The ListQueues action returns a list of your queues. The maximum number of
* queues that can be returned is 1000. If you specify a value for the
* optional QueueNamePrefix parameter, only queues with a name beginning with
* the specified value are returned
*
* @param region
* Queues are Region-specific.
* @param options
* specify prefix or other options
*
* @see <a href=
* "http://docs.amazonwebservices.com/AWSSimpleQueueService/2011-10-01/APIReference/Query_QueryListQueues.html"
* />
* Provides synchronous access to Queue features.
*/
Set<URI> listQueuesInRegion(@Nullable String region);
@Delegate
QueueApi getQueueApi();
Set<URI> listQueuesInRegion(@Nullable String region, ListQueuesOptions options);
@Delegate
QueueApi getQueueApiForRegion(@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
/**
* The CreateQueue action creates a new queue.
*
* When you request CreateQueue, you provide a name for the queue. To
* successfully create a new queue, you must provide a name that is unique
* within the scope of your own queues.
*
* <h4>Note</h4>
*
* If you delete a queue, you must wait at least 60 seconds before creating a
* queue with the same name.
*
* If you provide the name of an existing queue, along with the exact names
* and values of all the queue's attributes, CreateQueue returns the queue
* URL for the existing queue. If the queue name, attribute names, or
* attribute values do not match an existing queue, CreateQueue returns an
* error.
*
* <h4>Tip</h4>
*
* Use GetQueueUrl to get a queue's URL. GetQueueUrl requires only the
* QueueName parameter.
*
* @param region
* Queues are Region-specific.
* @param queueName
* The name to use for the queue created. Constraints: Maximum 80
* characters; alphanumeric characters, hyphens (-), and
* underscores (_) are allowed.
* Provides synchronous access to Message features.
*/
// this will gracefully attempt to resolve name issues
@Timeout(duration = 61, timeUnit = TimeUnit.SECONDS)
URI createQueueInRegion(@Nullable String region, String queueName);
@Delegate
MessageApi getMessageApiForQueue(@EndpointParam URI queue);
/**
* same as {@link #createQueueInRegion(String, String)} except you can
* control options such as delay seconds.
*
* @param options
* options such as delay seconds
* @see #createQueueInRegion(String, String)
* Provides synchronous access to Permission features.
*/
@Timeout(duration = 61, timeUnit = TimeUnit.SECONDS)
URI createQueueInRegion(@Nullable String region, String queueName, CreateQueueOptions options);
@Delegate
PermissionApi getPermissionApiForQueue(@EndpointParam URI queue);
/**
* The DeleteQueue action deletes the queue specified by the queue URL,
* regardless of whether the queue is empty. If the specified queue does not
* exist, SQS returns a successful response.
*
* <h4>Caution</h4>
*
* Use DeleteQueue with care; once you delete your queue, any messages in the
* queue are no longer available.
*
* When you delete a queue, the deletion process takes up to 60 seconds.
* Requests you send involving that queue during the 60 seconds might
* succeed. For example, a SendMessage request might succeed, but after the
* 60 seconds, the queue and that message you sent no longer exist. Also,
* when you delete a queue, you must wait at least 60 seconds before creating
* a queue with the same name.
*
* We reserve the right to delete queues that have had no activity for more
* than 30 days. For more information, see About SQS Queues in the Amazon SQS
* Developer Guide.
*
* @param queue
* queue you want to delete
*/
void deleteQueue(URI queue);
/**
* The DeleteMessage action deletes the specified message from the specified
* queue. You specify the message by using the message's receipt handle and
* not the message ID you received when you sent the message. Even if the
* message is locked by another reader due to the visibility timeout setting,
* it is still deleted from the queue. If you leave a message in the queue
* for more than 4 days, SQS automatically deletes it.
*
* <h4>Note</h4>
*
* The receipt handle is associated with a specific instance of receiving the
* message. If you receive a message more than once, the receipt handle you
* get each time you receive the message is different. When you request
* DeleteMessage, if you don't provide the most recently received receipt
* handle for the message, the request will still succeed, but the message
* might not be deleted.
*
* <h4>Important</h4>
*
* It is possible you will receive a message even after you have deleted it.
* This might happen on rare occasions if one of the servers storing a copy
* of the message is unavailable when you request to delete the message. The
* copy remains on the server and might be returned to you again on a
* subsequent receive request. You should create your system to be idempotent
* so that receiving a particular message more than once is not a problem.
*
* @param queue
* the queue the message is in
* @param receiptHandle
* The receipt handle associated with the message you want to
* delete.
*/
void deleteMessage(URI queue, String receiptHandle);
/**
* The ChangeMessageVisibility action changes the visibility timeout of a
* specified message in a queue to a new value. The maximum allowed timeout
* value you can set the value to is 12 hours. This means you can't extend
* the timeout of a message in an existing queue to more than a total
* visibility timeout of 12 hours. (For more information visibility timeout,
* see Visibility Timeout in the Amazon SQS Developer Guide.)
*
* For example, let's say the timeout for the queue is 30 seconds, and you
* receive a message. Once you're 20 seconds into the timeout for that
* message (i.e., you have 10 seconds left), you extend it by 60 seconds by
* calling ChangeMessageVisibility with VisibilityTimeoutset to 60 seconds.
* You have then changed the remaining visibility timeout from 10 seconds to
* 60 seconds.
*
* <h4>Important</h4>
*
* If you attempt to set the VisibilityTimeout to an amount more than the
* maximum time left, Amazon SQS returns an error. It will not automatically
* recalculate and increase the timeout to the maximum time remaining.
*
* <h4>Important</h4>
*
* Unlike with a queue, when you change the visibility timeout for a specific
* message, that timeout value is applied immediately but is not saved in
* memory for that message. If you don't delete a message after it is
* received, the visibility timeout for the message the next time it is
* received reverts to the original timeout value, not the value you set with
* the ChangeMessageVisibility action.
*
* @param queue
* the queue the message is in
* @param receiptHandle
* The receipt handle associated with the message whose visibility
* timeout you want to change. This parameter is returned by the
* ReceiveMessage action.
* @param visibilityTimeout
* The new value for the message's visibility timeout (in seconds)
* from 0 to 43200 (maximum 12 hours)
*/
void changeMessageVisibility(URI queue, String receiptHandle, int visibilityTimeout);
/**
* The AddPermission action adds a permission to a queue for a specific
* principal. This allows for sharing access to the queue.
*
* When you create a queue, you have full control access rights for the
* queue. Only you (as owner of the queue) can grant or deny permissions to
* the queue. For more information about these permissions, see Shared Queues
* in the Amazon SQS Developer Guide.
*
* Note
*
* AddPermission writes an SQS-generated policy. If you want to write your
* own policy, use SetQueueAttributes to upload your policy.
*
* @param queue
* queue to change permissions on
* @param label
*
* The unique identification of the permission you're setting.
* example: AliceSendMessage
*
* Constraints: Maximum 80 characters; alphanumeric characters,
* hyphens (-), and underscores (_) are allowed.
* @param permission
* The action you want to allow for the specified principal.
* @param accountId
* The AWS account number of the principal who will be given
* permission. The principal must have an AWS account, but does not
* need to be signed up for Amazon SQS. For information about
* locating the AWS account identification, see Your AWS
* Identifiers in the Amazon SQS Developer Guide.
*
* Constraints: Valid 12-digit AWS account number, without hyphens
*
*/
void addPermissionToAccount(URI queue, String label, Action permission, String accountId);
/**
* The RemovePermission action revokes any permissions in the queue policy
* that matches the Label parameter. Only the owner of the queue can remove
* permissions.
*
* @param queue
* queue to change permissions on
*
* @param label
* The identification of the permission you want to remove. This is
* the label you added in AddPermission. example: AliceSendMessage
*/
void removePermission(URI queue, String label);
/**
* The SendMessage action delivers a message to the specified queue. The
* maximum allowed message size is 64 KB.
*
* <h4>Important</h4>
*
* The following list shows the characters (in Unicode) allowed in your
* message, according to the W3C XML specification (for more information, go
* to http://www.w3.org/TR/REC-xml/#charsets). If you send any characters not
* included in the list, your request will be rejected.
*
*
* {@code #x9 | #xA | #xD | [#x20 to #xD7FF] | [#xE000 to #xFFFD] | [#x10000 to #x10FFFF]}
*
* @param queue
* queue you want to send to
*
* @param message
* Type: String maximum 64 KB in size. For a list of allowed
* characters, see the preceding important note.
* @return id of the message and md5 of the content sent
*/
MessageIdAndMD5 sendMessage(URI queue, String message);
/**
* same as {@link #sendMessage(URI, String)} except you can control options
* such as delay seconds.
*
* @param options
* options such as delay seconds
* @see #sendMessage(URI, String)
*/
MessageIdAndMD5 sendMessage(URI queue, String message, SendMessageOptions options);
/**
* The ReceiveMessage action retrieves one or more messages from the
* specified queue. The ReceiveMessage action does not delete the message
* after it is retrieved. To delete a message, you must use the DeleteMessage
* action. For more information about message deletion in the message life
* cycle, see Message Lifecycle.
*
* <h4>Note</h4>
*
* Due to the distributed nature of the queue, a weighted random set of
* machines is sampled on a ReceiveMessage call. That means only the messages
* on the sampled machines are returned. If the number of messages in the
* queue is small (less than 1000), it is likely you will get fewer messages
* than you requested per ReceiveMessage call. If the number of messages in
* the queue is extremely small, you might not receive any messages in a
* particular ReceiveMessage response; in which case you should repeat the
* request.
*
* @param queue
* from where you are receiving messages
* @return message including the receipt handle you can use to delete it
*/
Message receiveMessage(URI queue);
/**
* same as {@link #receiveMessage(URI)} except you can provide options like
* VisibilityTimeout parameter in your request, which will be applied to the
* messages that SQS returns in the response. If you do not include the
* parameter, the overall visibility timeout for the queue is used for the
* returned messages.
*
* @param options
* options such as VisibilityTimeout
* @see #receiveMessage(URI)
*/
Message receiveMessage(URI queue, ReceiveMessageOptions options);
/**
* same as {@link #receiveMessage(URI)} except you can receive multiple
* messages.
*
* @param max
* maximum messages to receive, current limit is 10
* @see #receiveMessage(URI)
*/
Set<Message> receiveMessages(URI queue, int max);
/**
* returns all attributes of a queue.
*
* @param queue
* queue to get the attributes of
*/
QueueAttributes getQueueAttributes(URI queue);
/**
* The SetQueueAttributes action sets one attribute of a queue per request.
* When you change a queue's attributes, the change can take up to 60 seconds
* to propagate throughout the SQS system.
*
* @param queue
* queue to set the attribute on
* @param name
*
* The name of the attribute you want to set.
*
* VisibilityTimeout - The length of time (in seconds) that a
* message received from a queue will be invisible to other
* receiving components when they ask to receive messages. For more
* information about VisibilityTimeout, see Visibility Timeout in
* the Amazon SQS Developer Guide.
*
* Policy - The formal description of the permissions for a
* resource. For more information about Policy, see Basic Policy
* Structure in the Amazon SQS Developer Guide.
*
* MaximumMessageSize - The limit of how many bytes a message can
* contain before Amazon SQS rejects it.
*
* MessageRetentionPeriod - The number of seconds Amazon SQS
* retains a message.
*
* DelaySeconds - The time in seconds that the delivery of all
* messages in the queue will be delayed.
* @param value
* The value of the attribute you want to set. To delete a queue's
* access control policy, set the policy to "".
*
* Constraints: Constraints are specific for each value.
*
* VisibilityTimeout - An integer from 0 to 43200 (12 hours). The
* default for this attribute is 30 seconds.
*
* Policy - A valid form-url-encoded policy. For more information
* about policy structure, see Basic Policy Structure in the Amazon
* SQS Developer Guide. For more information about
* form-url-encoding, see
* http://www.w3.org/MarkUp/html-spec/html-spec_8.html#SEC8.2.1.
*
* MaximumMessageSize - An integer from 1024 bytes (1 KiB) up to
* 65536 bytes (64 KiB). The default for this attribute is 65536
* (64 KiB).
*
* MessageRetentionPeriod - Integer representing seconds, from 60
* (1 minute) to 1209600 (14 days). The default for this attribute
* is 345600 (4 days).
*
* DelaySeconds - An integer from 0 to 900 (15 minutes). The
* default for this attribute is 0.
*/
void setQueueAttribute(URI queue, String name, String value);
/**
* returns some attributes of a queue.
*
* @param queue
* queue to get the attributes of
*/
Map<String, String> getQueueAttributes(URI queue, Iterable<String> attributeNames);
/**
* returns an attribute of a queue.
*
* @param queue
* queue to get the attributes of
*/
String getQueueAttribute(URI queue, String attributeName);
/**
* same as {@link #receiveMessages(URI, int)} except you can provide options
* like VisibilityTimeout parameter in your request, which will be applied to
* the messages that SQS returns in the response. If you do not include the
* parameter, the overall visibility timeout for the queue is used for the
* returned messages.
*
* @param options
* options such as VisibilityTimeout
* @see #receiveMessages(URI, int)
*/
Set<Message> receiveMessages(URI queue, int max, ReceiveMessageOptions options);
}

View File

@ -18,243 +18,62 @@
*/
package org.jclouds.sqs;
import static org.jclouds.sqs.reference.SQSParameters.ACTION;
import static org.jclouds.sqs.reference.SQSParameters.VERSION;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.jclouds.Constants;
import org.jclouds.aws.filters.FormSigner;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.location.Region;
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.FormParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.Transform;
import org.jclouds.rest.annotations.VirtualHost;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.sqs.binders.BindAttributeNamesToIndexedFormParams;
import org.jclouds.sqs.domain.Action;
import org.jclouds.sqs.domain.Message;
import org.jclouds.sqs.domain.MessageIdAndMD5;
import org.jclouds.sqs.domain.QueueAttributes;
import org.jclouds.sqs.functions.MapToQueueAttributes;
import org.jclouds.sqs.options.CreateQueueOptions;
import org.jclouds.sqs.options.ListQueuesOptions;
import org.jclouds.sqs.options.ReceiveMessageOptions;
import org.jclouds.sqs.options.SendMessageOptions;
import org.jclouds.sqs.xml.AttributesHandler;
import org.jclouds.sqs.xml.MessageHandler;
import org.jclouds.sqs.xml.ReceiveMessageResponseHandler;
import org.jclouds.sqs.xml.RegexListQueuesResponseHandler;
import org.jclouds.sqs.xml.RegexMessageIdAndMD5Handler;
import org.jclouds.sqs.xml.RegexQueueHandler;
import org.jclouds.sqs.xml.ValueHandler;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.annotations.Beta;
import com.google.inject.Provides;
/**
* Provides access to SQS via their REST API.
* Provides access to SQS via REST API.
* <p/>
*
* @see <a
* href="http://docs.amazonwebservices.com/AWSSimpleQueueService/2011-10-01/APIReference/Welcome.html">SQS
* documentation</a>
* @author Adrian Cole
*/
@Beta
@RequestFilters(FormSigner.class)
@FormParams(keys = VERSION, values = "{" + Constants.PROPERTY_API_VERSION + "}")
@VirtualHost
public interface SQSAsyncApi {
/**
*
* @return the Region codes configured
*/
@Provides
@Region
Set<String> getConfiguredRegions();
/**
* @see SQSApi#listQueuesInRegion
* Provides asynchronous access to Queue features.
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ListQueues")
@ResponseParser(RegexListQueuesResponseHandler.class)
ListenableFuture<Set<URI>> listQueuesInRegion(
@Delegate
QueueAsyncApi getQueueApi();
@Delegate
QueueAsyncApi getQueueApiForRegion(
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
/**
* @see SQSApi#listQueuesInRegion
* Provides asynchronous access to Message features.
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ListQueues")
@ResponseParser(RegexListQueuesResponseHandler.class)
ListenableFuture<Set<URI>> listQueuesInRegion(
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
ListQueuesOptions options);
@Delegate
MessageAsyncApi getMessageApiForQueue(@EndpointParam URI queue);
/**
* @see SQSApi#createQueueInRegion
* Provides asynchronous access to Permission features.
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "CreateQueue")
@ResponseParser(RegexQueueHandler.class)
ListenableFuture<URI> createQueueInRegion(
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
@FormParam("QueueName") String queueName);
/**
* @see SQSApi#createQueueInRegion
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "CreateQueue")
@ResponseParser(RegexQueueHandler.class)
ListenableFuture<URI> createQueueInRegion(
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
@FormParam("QueueName") String queueName, CreateQueueOptions options);
/**
* @see SQSApi#deleteQueue
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "DeleteQueue")
ListenableFuture<Void> deleteQueue(@EndpointParam URI queue);
/**
* @see SQSApi#deleteMessage
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "DeleteMessage")
ListenableFuture<Void> deleteMessage(@EndpointParam URI queue, @FormParam("ReceiptHandle") String receiptHandle);
/**
* @see SQSApi#changeMessageVisibility
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ChangeMessageVisibility")
ListenableFuture<Void> changeMessageVisibility(@EndpointParam URI queue,
@FormParam("ReceiptHandle") String receiptHandle, @FormParam("VisibilityTimeout") int visibilityTimeout);
/**
* @see SQSApi#sendMessage
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "SendMessage")
@ResponseParser(RegexMessageIdAndMD5Handler.class)
ListenableFuture<? extends MessageIdAndMD5> sendMessage(@EndpointParam URI queue,
@FormParam("MessageBody") String message);
/**
* @see SQSApi#sendMessage
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "SendMessage")
@ResponseParser(RegexMessageIdAndMD5Handler.class)
ListenableFuture<? extends MessageIdAndMD5> sendMessage(@EndpointParam URI queue,
@FormParam("MessageBody") String message, SendMessageOptions options);
/**
* @see SQSApi#receiveMessage
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ReceiveMessage")
@XMLResponseParser(MessageHandler.class)
ListenableFuture<Message> receiveMessage(@EndpointParam URI queue);
/**
* @see SQSApi#receiveMessage
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ReceiveMessage")
@XMLResponseParser(MessageHandler.class)
ListenableFuture<? extends Message> receiveMessage(@EndpointParam URI queue, ReceiveMessageOptions options);
/**
* @see SQSApi#getQueueAttributes(URI)
*/
@POST
@Path("/")
@FormParams(keys = { ACTION, "AttributeName.1" }, values = { "GetQueueAttributes", "All" })
@Transform(MapToQueueAttributes.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@XMLResponseParser(AttributesHandler.class)
ListenableFuture<? extends QueueAttributes> getQueueAttributes(@EndpointParam URI queue);
/**
* @see SQSApi#getQueueAttributes(URI, Iterable)
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "GetQueueAttributes")
@XMLResponseParser(AttributesHandler.class)
ListenableFuture<Map<String, String>> getQueueAttributes(@EndpointParam URI queue,
@BinderParam(BindAttributeNamesToIndexedFormParams.class) Iterable<String> attributeNames);
/**
* @see SQSApi#getQueueAttribute
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "GetQueueAttributes")
@XMLResponseParser(ValueHandler.class)
ListenableFuture<String> getQueueAttribute(@EndpointParam URI queue,
@FormParam("AttributeName.1") String attributeName);
/**
* @see SQSApi#setQueueAttribute
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "SetQueueAttributes")
ListenableFuture<Void> setQueueAttribute(@EndpointParam URI queue, @FormParam("Attribute.Name") String name,
@FormParam("Attribute.Value") String value);
/**
* @see SQSApi#receiveMessages
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ReceiveMessage")
@XMLResponseParser(ReceiveMessageResponseHandler.class)
ListenableFuture<? extends Set<? extends Message>> receiveMessages(@EndpointParam URI queue,
@FormParam("MaxNumberOfMessages") int max);
/**
* @see SQSApi#receiveMessages
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ReceiveMessage")
@XMLResponseParser(ReceiveMessageResponseHandler.class)
ListenableFuture<? extends Set<? extends Message>> receiveMessages(@EndpointParam URI queue,
@FormParam("MaxNumberOfMessages") int max, ReceiveMessageOptions options);
/**
* @see SQSApi#addPermissionToAccount
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "AddPermission")
ListenableFuture<Void> addPermissionToAccount(@EndpointParam URI queue, @FormParam("Label") String label,
@FormParam("ActionName.1") Action permission, @FormParam("AWSAccountId.1") String accountId);
/**
* @see SQSApi#removePermission
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "RemovePermission")
ListenableFuture<Void> removePermission(@EndpointParam URI queue, @FormParam("Label") String label);
@Delegate
PermissionAsyncApi getPermissionApiForQueue(@EndpointParam URI queue);
}

View File

@ -18,6 +18,8 @@
*/
package org.jclouds.sqs.config;
import java.util.Map;
import org.jclouds.aws.config.FormSigningRestClientModule;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.HttpRetryHandler;
@ -25,11 +27,18 @@ import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.sqs.MessageApi;
import org.jclouds.sqs.MessageAsyncApi;
import org.jclouds.sqs.PermissionApi;
import org.jclouds.sqs.PermissionAsyncApi;
import org.jclouds.sqs.QueueApi;
import org.jclouds.sqs.QueueAsyncApi;
import org.jclouds.sqs.SQSApi;
import org.jclouds.sqs.SQSAsyncApi;
import org.jclouds.sqs.handlers.ParseSQSErrorFromXmlContent;
import org.jclouds.sqs.handlers.SQSErrorRetryHandler;
import com.google.common.collect.ImmutableMap;
import com.google.common.reflect.TypeToken;
/**
@ -39,11 +48,16 @@ import com.google.common.reflect.TypeToken;
*/
@ConfiguresRestClient
public class SQSRestClientModule extends FormSigningRestClientModule<SQSApi, SQSAsyncApi> {
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()//
.put(QueueApi.class, QueueAsyncApi.class)
.put(MessageApi.class, MessageAsyncApi.class)
.put(PermissionApi.class, PermissionAsyncApi.class)
.build();
public SQSRestClientModule() {
super(TypeToken.of(SQSApi.class), TypeToken.of(SQSAsyncApi.class));
super(TypeToken.of(SQSApi.class), TypeToken.of(SQSAsyncApi.class), DELEGATE_MAP);
}
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseSQSErrorFromXmlContent.class);

View File

@ -41,7 +41,9 @@ import com.google.common.collect.Iterables;
*/
@Test(groups = "unit", testName = "SQSApiExpectTest")
public class SQSApiExpectTest extends BaseSQSApiExpectTest {
URI queue = URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/");
public HttpRequest createQueue = HttpRequest.builder()
.method("POST")
.endpoint("https://sqs.us-east-1.amazonaws.com/")
@ -62,7 +64,8 @@ public class SQSApiExpectTest extends BaseSQSApiExpectTest {
SQSApi apiWhenExist = requestSendsResponse(createQueue, createQueueResponse);
assertEquals(apiWhenExist.createQueueInRegion(null, "queueName").toString(), new CreateQueueResponseTest().expected().toString());
assertEquals(apiWhenExist.getQueueApi().create("queueName").toString(), new CreateQueueResponseTest().expected()
.toString());
}
public HttpRequest sendMessage = HttpRequest.builder()
@ -85,7 +88,8 @@ public class SQSApiExpectTest extends BaseSQSApiExpectTest {
SQSApi apiWhenExist = requestSendsResponse(sendMessage, sendMessageResponse);
assertEquals(apiWhenExist.sendMessage(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"), "hardyharhar").toString(), new SendMessageResponseTest().expected().toString());
assertEquals(apiWhenExist.getMessageApiForQueue(queue).send("hardyharhar").toString(),
new SendMessageResponseTest().expected().toString());
}
@ -108,9 +112,8 @@ public class SQSApiExpectTest extends BaseSQSApiExpectTest {
SQSApi apiWhenExist = requestSendsResponse(receiveMessage, receiveMessageResponse);
assertEquals(
apiWhenExist.receiveMessage(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"))
.toString(), Iterables.get(new ReceiveMessageResponseTest().expected(), 0).toString());
assertEquals(apiWhenExist.getMessageApiForQueue(queue).receive().toString(),
Iterables.get(new ReceiveMessageResponseTest().expected(), 0).toString());
}
@ -134,9 +137,8 @@ public class SQSApiExpectTest extends BaseSQSApiExpectTest {
SQSApi apiWhenExist = requestSendsResponse(receiveMessages, receiveMessagesResponse);
assertEquals(
apiWhenExist.receiveMessages(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"), 10)
.toString(), new ReceiveMessageResponseTest().expected().toString());
assertEquals(apiWhenExist.getMessageApiForQueue(queue).receive(10).toString(), new ReceiveMessageResponseTest()
.expected().toString());
}
public HttpRequest deleteMessage = HttpRequest.builder()
@ -163,8 +165,7 @@ public class SQSApiExpectTest extends BaseSQSApiExpectTest {
SQSApi apiWhenExist = requestSendsResponse(deleteMessage, deleteMessageResponse);
apiWhenExist.deleteMessage(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"),
"eXJYhj5rDr9cAe");
apiWhenExist.getMessageApiForQueue(queue).delete("eXJYhj5rDr9cAe");
}
@ -193,8 +194,7 @@ public class SQSApiExpectTest extends BaseSQSApiExpectTest {
SQSApi apiWhenExist = requestSendsResponse(changeMessageVisibility, changeMessageVisibilityResponse);
apiWhenExist.changeMessageVisibility(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"),
"eXJYhj5rDr9cAe", 10);
apiWhenExist.getMessageApiForQueue(queue).changeVisibility("eXJYhj5rDr9cAe", 10);
}
public HttpRequest getQueueAttribute = HttpRequest.builder()
@ -221,7 +221,7 @@ public class SQSApiExpectTest extends BaseSQSApiExpectTest {
SQSApi apiWhenExist = requestSendsResponse(getQueueAttribute, getQueueAttributeResponse);
assertEquals(apiWhenExist.getQueueAttribute(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"), "VisibilityTimeout"), "30");
assertEquals(apiWhenExist.getQueueApi().getAttribute(queue, "VisibilityTimeout"), "30");
}
public HttpRequest getQueueAttributes = HttpRequest.builder()
@ -244,7 +244,8 @@ public class SQSApiExpectTest extends BaseSQSApiExpectTest {
SQSApi apiWhenExist = requestSendsResponse(getQueueAttributes, getQueueAttributesResponse);
assertEquals(apiWhenExist.getQueueAttributes(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/")).toString(), new MapToQueueAttributesTest().expected().toString());
assertEquals(apiWhenExist.getQueueApi().getAttributes(queue).toString(), new MapToQueueAttributesTest()
.expected().toString());
}
public HttpRequest getQueueAttributesSubset = HttpRequest.builder()
@ -268,10 +269,8 @@ public class SQSApiExpectTest extends BaseSQSApiExpectTest {
SQSApi apiWhenExist = requestSendsResponse(getQueueAttributesSubset, getQueueAttributesSubsetResponse);
assertEquals(
apiWhenExist.getQueueAttributes(
URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"),
ImmutableSet.of("VisibilityTimeout", "DelaySeconds")).toString(),
assertEquals(apiWhenExist.getQueueApi()
.getAttributes(queue, ImmutableSet.of("VisibilityTimeout", "DelaySeconds")).toString(),
new GetQueueAttributesResponseTest().expected().toString());
}
@ -300,8 +299,7 @@ public class SQSApiExpectTest extends BaseSQSApiExpectTest {
SQSApi apiWhenExist = requestSendsResponse(setQueueAttribute, setQueueAttributeResponse);
apiWhenExist.setQueueAttribute(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"),
"MaximumMessageSize", "1");
apiWhenExist.getQueueApi().setAttribute(queue, "MaximumMessageSize", "1");
}
public HttpRequest addPermission = HttpRequest.builder()
@ -330,7 +328,7 @@ public class SQSApiExpectTest extends BaseSQSApiExpectTest {
SQSApi apiWhenExist = requestSendsResponse(addPermission, addPermissionResponse);
apiWhenExist.addPermissionToAccount(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"), "testLabel", Action.RECEIVE_MESSAGE, "125074342641");
apiWhenExist.getPermissionApiForQueue(queue).addPermissionToAccount("testLabel", Action.RECEIVE_MESSAGE, "125074342641");
}
public HttpRequest removePermission = HttpRequest.builder()
@ -357,6 +355,6 @@ public class SQSApiExpectTest extends BaseSQSApiExpectTest {
SQSApi apiWhenExist = requestSendsResponse(removePermission, removePermissionResponse);
apiWhenExist.removePermission(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"), "testLabel");
apiWhenExist.getPermissionApiForQueue(queue).remove("testLabel");
}
}

View File

@ -18,6 +18,8 @@
*/
package org.jclouds.sqs;
import static com.google.common.collect.Iterables.get;
import static com.google.common.collect.Iterables.getLast;
import static org.jclouds.concurrent.MoreExecutors.sameThreadExecutor;
import static org.jclouds.providers.AnonymousProviderMetadata.forClientMappedToAsyncClientOnEndpoint;
import static org.jclouds.sqs.options.ListQueuesOptions.Builder.queuePrefix;
@ -30,7 +32,6 @@ import static org.testng.Assert.assertNull;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.concurrent.TimeUnit;
import javax.ws.rs.POST;
@ -51,7 +52,6 @@ import org.testng.annotations.Test;
import com.google.common.base.Charsets;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import com.google.common.hash.HashCode;
import com.google.common.hash.Hashing;
@ -74,10 +74,10 @@ public class SQSApiLiveTest extends BaseSQSApiLiveTest {
}
protected void listQueuesInRegion(String region) throws InterruptedException {
SortedSet<URI> allResults = Sets.newTreeSet(api().listQueuesInRegion(region));
Set<URI> allResults = api().getQueueApiForRegion(region).list();
assertNotNull(allResults);
if (allResults.size() >= 1) {
URI queue = allResults.last();
URI queue = getLast(allResults);
assertQueueInList(region, queue);
}
}
@ -91,11 +91,12 @@ public class SQSApiLiveTest extends BaseSQSApiLiveTest {
}
public String recreateQueueInRegion(String queueName, String region) throws InterruptedException {
Set<URI> result = api().listQueuesInRegion(region, queuePrefix(queueName));
QueueApi api = api().getQueueApiForRegion(region);
Set<URI> result = api.list(queuePrefix(queueName));
if (result.size() >= 1) {
api().deleteQueue(Iterables.getLast(result));
api.delete(getLast(result));
}
URI queue = api().createQueueInRegion(region, queueName);
URI queue = api.create(queueName);
assertQueueInList(region, queue);
queues.add(queue);
return queueName;
@ -104,8 +105,8 @@ public class SQSApiLiveTest extends BaseSQSApiLiveTest {
@Test(dependsOnMethods = "testCanRecreateQueueGracefully")
protected void testGetQueueAttributes() {
for (URI queue : queues) {
Map<String, String> attributes = api().getQueueAttributes(queue, ImmutableSet.of("All"));
assertEquals(api().getQueueAttributes(queue, attributes.keySet()), attributes);
Map<String, String> attributes = api().getQueueApi().getAttributes(queue, ImmutableSet.of("All"));
assertEquals(api().getQueueApi().getAttributes(queue, attributes.keySet()), attributes);
}
}
@ -128,29 +129,30 @@ public class SQSApiLiveTest extends BaseSQSApiLiveTest {
@Test(dependsOnMethods = "testGetQueueAttributes")
protected void testAddAnonymousPermission() throws InterruptedException {
for (URI queue : queues) {
QueueAttributes attributes = api().getQueueAttributes(queue);
QueueAttributes attributes = api().getQueueApi().getAttributes(queue);
assertNoPermissions(queue);
String accountToAuthorize = getAccountToAuthorize(queue);
api().addPermissionToAccount(queue, "fubar", Action.GET_QUEUE_ATTRIBUTES, accountToAuthorize);
api().getPermissionApiForQueue(queue).addPermissionToAccount("fubar", Action.GET_QUEUE_ATTRIBUTES,
accountToAuthorize);
String policyForAuthorizationByAccount = assertPolicyPresent(queue);
String policyForAnonymous = policyForAuthorizationByAccount.replace("\"" + accountToAuthorize + "\"", "\"*\"");
api().setQueueAttribute(queue, "Policy", policyForAnonymous);
api().getQueueApi().setAttribute(queue, "Policy", policyForAnonymous);
assertEquals(getAnonymousAttributesApi(queue).getQueueArn(), attributes.getQueueArn());
}
}
protected String getAccountToAuthorize(URI queue) {
return Iterables.get(Splitter.on('/').split(queue.getPath()), 1);
return get(Splitter.on('/').split(queue.getPath()), 1);
}
@Test(dependsOnMethods = "testAddAnonymousPermission")
protected void testRemovePermission() throws InterruptedException {
for (URI queue : queues) {
api().removePermission(queue, "fubar");
api().getPermissionApiForQueue(queue).remove("fubar");
assertNoPermissions(queue);
}
}
@ -158,22 +160,22 @@ public class SQSApiLiveTest extends BaseSQSApiLiveTest {
@Test(dependsOnMethods = "testGetQueueAttributes")
protected void testSetQueueAttribute() {
for (URI queue : queues) {
api().setQueueAttribute(queue, "MaximumMessageSize", "1024");
assertEquals(api().getQueueAttributes(queue).getMaximumMessageSize(), 1024);
api().getQueueApi().setAttribute(queue, "MaximumMessageSize", "1024");
assertEquals(api().getQueueApi().getAttributes(queue).getMaximumMessageSize(), 1024);
}
}
@Test(dependsOnMethods = "testGetQueueAttributes")
protected void testSendMessage() {
for (URI queue : queues) {
assertEquals(api().sendMessage(queue, message).getMD5(), md5);
assertEquals(api().getMessageApiForQueue(queue).send(message).getMD5(), md5);
}
}
@Test(dependsOnMethods = "testSendMessage")
protected void testReceiveMessageWithoutHidingMessage() {
for (URI queue : queues) {
assertEquals(api().receiveMessage(queue, attribute("All").visibilityTimeout(0)).getMD5(), md5);
assertEquals(api().getMessageApiForQueue(queue).receive(attribute("All").visibilityTimeout(0)).getMD5(), md5);
}
}
@ -182,21 +184,22 @@ public class SQSApiLiveTest extends BaseSQSApiLiveTest {
@Test(dependsOnMethods = "testReceiveMessageWithoutHidingMessage")
protected void testChangeMessageVisibility() {
for (URI queue : queues) {
MessageApi api = api().getMessageApiForQueue(queue);
// start hiding it at 5 seconds
receiptHandle = api().receiveMessage(queue, attribute("None").visibilityTimeout(5)).getReceiptHandle();
receiptHandle = api.receive(attribute("None").visibilityTimeout(5)).getReceiptHandle();
// hidden message, so we can't see it
assertNull(api().receiveMessage(queue));
assertNull(api.receive());
// this should unhide it
api().changeMessageVisibility(queue, receiptHandle, 0);
api.changeVisibility(receiptHandle, 0);
// so we can see it again
assertEquals(api().receiveMessage(queue, attribute("All").visibilityTimeout(0)).getMD5(), md5);
assertEquals(api.receive(attribute("All").visibilityTimeout(0)).getMD5(), md5);
}
}
@Test(dependsOnMethods = "testChangeMessageVisibility")
protected void testDeleteMessage() throws InterruptedException {
for (URI queue : queues) {
api().deleteMessage(queue, receiptHandle);
api().getMessageApiForQueue(queue).delete(receiptHandle);
assertNoMessages(queue);
}
}
@ -205,7 +208,7 @@ public class SQSApiLiveTest extends BaseSQSApiLiveTest {
@AfterClass(groups = "live")
protected void tearDownContext() {
for (URI queue : queues) {
api().deleteQueue(queue);
api().getQueueApi().delete(queue);
}
super.tearDownContext();
}

View File

@ -56,7 +56,7 @@ public class BaseSQSApiLiveTest extends BaseContextLiveTest<RestContext<SQSApi,
final AtomicReference<String> policy = new AtomicReference<String>();
assertEventually(new Runnable() {
public void run() {
String policyForAuthorizationByAccount = api().getQueueAttribute(queue, "Policy");
String policyForAuthorizationByAccount = api().getQueueApi().getAttribute(queue, "Policy");
assertNotNull(policyForAuthorizationByAccount);
policy.set(policyForAuthorizationByAccount);
@ -68,7 +68,7 @@ public class BaseSQSApiLiveTest extends BaseContextLiveTest<RestContext<SQSApi,
protected void assertNoPermissions(final URI queue) throws InterruptedException {
assertEventually(new Runnable() {
public void run() {
String policy = api().getQueueAttribute(queue, "Policy");
String policy = api().getQueueApi().getAttribute(queue, "Policy");
assertTrue(policy == null || policy.indexOf("\"Statement\":[]") != -1, policy);
}
});
@ -77,7 +77,7 @@ public class BaseSQSApiLiveTest extends BaseContextLiveTest<RestContext<SQSApi,
protected void assertNoMessages(final URI queue) throws InterruptedException {
assertEventually(new Runnable() {
public void run() {
Message message = api().receiveMessage(queue);
Message message = api().getMessageApiForQueue(queue).receive();
assertNull(message, "message: " + message + " left in queue " + queue);
}
});
@ -87,7 +87,7 @@ public class BaseSQSApiLiveTest extends BaseContextLiveTest<RestContext<SQSApi,
final URI finalQ = queue;
assertEventually(new Runnable() {
public void run() {
Set<URI> result = api().listQueuesInRegion(region);
Set<URI> result = api().getQueueApiForRegion(region).list();
assertNotNull(result);
assert result.size() >= 1 : result;
assertTrue(result.contains(finalQ), finalQ + " not in " + result);