public class

SQSConnector

extends Object
java.lang.Object
   ↳ org.mule.modules.sqs.SQSConnector
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Amazon Simple Queue Service (Amazon SQS) is a distributed queue messaging service introduced by Amazon.com in April of 2006. It supports programmatic sending of messages via web service applications as a way to communicate over the internet. The intent of SQS is to provide a highly scalable hosted message queue that resolves issues arising from the common producer-consumer problem or connectivity between producer and consumer.

Summary

Fields
private Config config
private static final Logger logger
private AmazonSQSClient msgQueue
private AmazonSQSAsync msgQueueAsync
Public Constructors
SQSConnector()
Public Methods
void addPermission(String label, List<String> accountIds, List<String> actions, String queueUrl)
Adds a permission to this message queue.
void changeMessageVisibility(String receiptHandle, Integer visibilityTimeout, String queueUrl)
Changes the visibility timeout of a specified message in a queue to a new value.
ChangeMessageVisibilityBatchResult changeMessageVisibilityBatch(List<ChangeMessageVisibilityBatchRequestEntry> receiptHandles, String queueUrl)
Changes the visibility timeout of multiple messages.
CreateQueueResult createQueue(String queueName, RegionEndpoint region, Map<String, String> attributes)
Creates a new queue, or returns the URL of an existing one.
void deleteMessage(String receiptHandle, String queueUrl)
Deletes the message identified by message object on the queue this object represents.
DeleteMessageBatchResult deleteMessageBatch(List<DeleteMessageBatchRequestEntry> receiptHandles, String queueUrl)
Deletes up to ten messages from the specified queue.
void deleteQueue(String queueUrl)
Deletes the message queue represented by this object.
int getApproximateNumberOfMessages(String queueUrl)
Gets an approximate number of visible messages for a queue.
Config getConfig()
GetQueueAttributesResult getQueueAttributes(List<String> attributeNames, String queueUrl)
Gets queue attributes.
GetQueueUrlResult getQueueUrl(String queueName, String queueOwnerAWSAccountId)
Returns the URL of an existing queue.
ListDeadLetterSourceQueuesResult listDeadLetterSourceQueues(String queueUrl)
Returns a list of your queues that have the RedrivePolicy queue attribute configured with a dead letter queue.
ListQueuesResult listQueues(String queueNamePrefix)
Returns a list of your queues.
void purgeQueue(String queueUrl)
Deletes the messages in a queue specified by the queue URL.
void receiveMessages(SourceCallback callback, Integer visibilityTimeout, Boolean preserveMessages, Integer numberOfMessages, String queueUrl)
Attempts to receive messages from a queue.
void removePermission(String label, String queueUrl)
Removes a permission from this message queue.
SendMessageResult sendMessage(String message, Integer delaySeconds, Map<String, Object> messageAttributes, String queueUrl)
Sends a message to a specified queue.
SendMessageBatchResult sendMessageBatch(List<SendMessageBatchRequestEntry> messages, String queueUrl)
Delivers up to ten messages to the specified queue.
void setConfig(Config config)
void setQueueAttributes(Map<String, String> attributes, String queueUrl)
Sets the value of one or more queue attributes.
[Expand]
Inherited Methods
From class java.lang.Object

Fields

private Config config

private static final Logger logger

private AmazonSQSClient msgQueue

private AmazonSQSAsync msgQueueAsync

Public Constructors

public SQSConnector ()

Public Methods

public void addPermission (String label, List<String> accountIds, List<String> actions, String queueUrl)

Adds a permission to this message queue.

Parameters
label A name for this permission
accountIds The AWS account ID's for the account to share this queue with
actions A list to indicate how much to share (SendMessage, ReceiveMessage, ChangeMessageVisibility, DeleteMessage, GetQueueAttributes)
queueUrl Permissions will be added to the queue represented by this URL.
Throws
SQSConnectorException If any internal errors are encountered inside the connector while attempting to make the request or handle the response. For example if a network connection is not available.

public void changeMessageVisibility (String receiptHandle, Integer visibilityTimeout, String queueUrl)

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.

Parameters
receiptHandle The receipt handle associated with the message whose visibility timeout should be changed.
visibilityTimeout The new value (in seconds - from 0 to 43200 - maximum 12 hours) for the message's visibility timeout.
queueUrl The URL of the Amazon SQS queue to take action on.
Throws
SQSConnectorException If any internal errors are encountered inside the connector while attempting to make the request or handle the response. For example if a network connection is not available.

public ChangeMessageVisibilityBatchResult changeMessageVisibilityBatch (List<ChangeMessageVisibilityBatchRequestEntry> receiptHandles, String queueUrl)

Changes the visibility timeout of multiple messages. This is a batch version of ChangeMessageVisibility. The result of the action on each message is reported individually in the response. You can send up to 10 ChangeMessageVisibility requests with each ChangeMessageVisibilityBatch action.

Parameters
receiptHandles A list of receipt handles of the messages for which the visibility timeout must be changed.
queueUrl The URL of the Amazon SQS queue to take action on.
Returns
  • ChangeMessageVisibilityBatchResult list items.
Throws
SQSConnectorException If any internal errors are encountered inside the connector while attempting to make the request or handle the response. For example if a network connection is not available.

public CreateQueueResult createQueue (String queueName, RegionEndpoint region, Map<String, String> attributes)

Creates a new queue, or returns the URL of an existing one.

Parameters
queueName The name for the queue to be created.
region The region in which the queue to be created.
attributes A map of attributes with their corresponding values. Valid Map Keys: Policy | VisibilityTimeout | MaximumMessageSize | MessageRetentionPeriod | ApproximateNumberOfMessages | ApproximateNumberOfMessagesNotVisible | CreatedTimestamp | LastModifiedTimestamp | QueueArn | ApproximateNumberOfMessagesDelayed | DelaySeconds | ReceiveMessageWaitTimeSeconds | RedrivePolicy
Returns
  • CreateQueueResult object containing the URL of the created Amazon SQS queue.
Throws
SQSConnectorException If any internal errors are encountered inside the connector while attempting to make the request or handle the response. For example if a network connection is not available.

public void deleteMessage (String receiptHandle, String queueUrl)

Deletes the message identified by message object on the queue this object represents.

Parameters
receiptHandle Receipt handle of the message to be deleted
queueUrl The URL of the queue to delete messages from
Throws
SQSConnectorException If any internal errors are encountered inside the connector while attempting to make the request or handle the response. For example if a network connection is not available.

public DeleteMessageBatchResult deleteMessageBatch (List<DeleteMessageBatchRequestEntry> receiptHandles, String queueUrl)

Deletes up to ten messages from the specified queue. This is a batch version of DeleteMessage.

Parameters
receiptHandles A list of receipt handles for the messages to be deleted.
queueUrl The URL of the queue to delete messages as a batch from.
Returns
  • DeleteMessageBatchResult
Throws
SQSConnectorException If any internal errors are encountered inside the connector while attempting to make the request or handle the response. For example if a network connection is not available.

public void deleteQueue (String queueUrl)

Deletes the message queue represented by this object. Will delete non-empty queue.

Parameters
queueUrl The URL of the queue to delete.
Throws
SQSConnectorException If any internal errors are encountered inside the connector while attempting to make the request or handle the response. For example if a network connection is not available.

public int getApproximateNumberOfMessages (String queueUrl)

Gets an approximate number of visible messages for a queue.

Parameters
queueUrl The URL of the queue
Returns
  • the approximate number of messages in the queue
Throws
SQSConnectorException If any internal errors are encountered inside the connector while attempting to make the request or handle the response. For example if a network connection is not available.

public Config getConfig ()

public GetQueueAttributesResult getQueueAttributes (List<String> attributeNames, String queueUrl)

Gets queue attributes. This is provided to expose the underlying functionality.

Parameters
attributeNames A list of attribute retrieve information for.
queueUrl The URL of the Amazon SQS queue to take action on.
Returns
  • GetQueueAttributesResult object map containing attributes and their values
Throws
SQSConnectorException If any internal errors are encountered inside the connector while attempting to make the request or handle the response. For example if a network connection is not available.

public GetQueueUrlResult getQueueUrl (String queueName, String queueOwnerAWSAccountId)

Returns the URL of an existing queue.

Parameters
queueName The name of the queue whose URL must be fetched.
queueOwnerAWSAccountId The AWS account ID of the owner that created the queue.
Returns
  • GetQueueUrlResult object containing the generated queue service url
Throws
SQSConnectorException If any internal errors are encountered inside the connector while attempting to make the request or handle the response. For example if a network connection is not available.

public ListDeadLetterSourceQueuesResult listDeadLetterSourceQueues (String queueUrl)

Returns a list of your queues that have the RedrivePolicy queue attribute configured with a dead letter queue.

Parameters
queueUrl The queue URL of a dead letter queue.
Returns
  • ListDeadLetterSourceQueuesResult object containing a list of source queue URLs that have the RedrivePolicy queue attribute configured with a dead letter queue.
Throws
SQSConnectorException If any internal errors are encountered inside the connector while attempting to make the request or handle the response. For example if a network connection is not available.

public ListQueuesResult listQueues (String queueNamePrefix)

Returns a list of your queues. The maximum number of queues that can be returned is 1000.

Parameters
queueNamePrefix A string to use for filtering the list results. Only those queues whose name begins with the specified string are returned.
Returns
  • ListQueuesResult object containing list of queue URLs.
Throws
SQSConnectorException If any internal errors are encountered inside the connector while attempting to make the request or handle the response. For example if a network connection is not available.

public void purgeQueue (String queueUrl)

Deletes the messages in a queue specified by the queue URL.

Parameters
queueUrl The queue URL where messages are to be fetched from.
Throws
SQSConnectorException If any internal errors are encountered inside the connector while attempting to make the request or handle the response. For example if a network connection is not available.

public void receiveMessages (SourceCallback callback, Integer visibilityTimeout, Boolean preserveMessages, Integer numberOfMessages, String queueUrl)

Attempts to receive messages from a queue. Every attribute of the incoming messages will be added as inbound properties. Also the following properties will also be added:

sqs.message.id = containing the message identification sqs.message.receipt.handle = containing the message identification

Parameters
callback Callback to call when new messages are available.
visibilityTimeout The duration (in seconds) the retrieved messages are hidden from subsequent calls to retrieve.
preserveMessages Flag that indicates if you want to preserve the messages in the queue. False by default, so the messages are going to be deleted.
numberOfMessages The number of messages to be retrieved on each call (10 messages max). By default, 1 message will be retrieved.
queueUrl The queue URL where messages are to be fetched from.
Throws
SQSConnectorException If any internal errors are encountered inside the connector while attempting to make the request or handle the response. For example if a network connection is not available.

public void removePermission (String label, String queueUrl)

Removes a permission from this message queue.

Parameters
label A name for the permission to be removed
queueUrl Permissions will be deleted from the queue represented by this URL.
Throws
SQSConnectorException If any internal errors are encountered inside the connector while attempting to make the request or handle the response. For example if a network connection is not available.

public SendMessageResult sendMessage (String message, Integer delaySeconds, Map<String, Object> messageAttributes, String queueUrl)

Sends a message to a specified queue. The message must be between 1 and 256K bytes long.

Parameters
message The message body to send.
delaySeconds The number of seconds (0 to 900 - 15 minutes) to delay a specific message.
messageAttributes A map of typed key-value pairs to be sent as message attributes. A value, key and data type must be specified for each entry.
queueUrl The queue where the message is to be sent.
Returns
  • The queue response of the sent message.
Throws
SQSConnectorException If any internal errors are encountered inside the connector while attempting to make the request or handle the response. For example if a network connection is not available.

public SendMessageBatchResult sendMessageBatch (List<SendMessageBatchRequestEntry> messages, String queueUrl)

Delivers up to ten messages to the specified queue. This is a batch version of SendMessage

Parameters
messages A list of SendMessageBatchRequestEntry items.
queueUrl The queue where the message is to be sent.
Returns
  • SendMessageBatchResult list items.
Throws
SQSConnectorException If any internal errors are encountered inside the connector while attempting to make the request or handle the response. For example if a network connection is not available.

public void setConfig (Config config)

Parameters
config

public void setQueueAttributes (Map<String, String> attributes, String queueUrl)

Sets the value of one or more queue attributes. When you change a queue's attributes, the change can take up to 60 seconds for most of the attributes to propagate throughout the SQS system. Changes made to the MessageRetentionPeriod attribute can take up to 15 minutes.

Parameters
attributes A map of attributes to set.
queueUrl The URL of the queue.
Throws
SQSConnectorException If any internal errors are encountered inside the connector while attempting to make the request or handle the response. For example if a network connection is not available.