Class: Fog::AWS::SQS::Real

Inherits:
Object
  • Object
show all
Includes:
CredentialFetcher::ConnectionMethods
Defined in:
lib/fog/aws/sqs.rb,
lib/fog/aws/requests/sqs/list_queues.rb,
lib/fog/aws/requests/sqs/create_queue.rb,
lib/fog/aws/requests/sqs/delete_queue.rb,
lib/fog/aws/requests/sqs/send_message.rb,
lib/fog/aws/requests/sqs/delete_message.rb,
lib/fog/aws/requests/sqs/receive_message.rb,
lib/fog/aws/requests/sqs/get_queue_attributes.rb,
lib/fog/aws/requests/sqs/set_queue_attributes.rb,
lib/fog/aws/requests/sqs/change_message_visibility.rb

Instance Method Summary collapse

Methods included from CredentialFetcher::ConnectionMethods

#refresh_credentials_if_expired

Constructor Details

#initialize(options = {}) ⇒ Real

Initialize connection to SQS

Notes

options parameter must include values for :aws_access_key_id and :aws_secret_access_key in order to create a connection

Examples

sqs = SQS.new(
 :aws_access_key_id => your_aws_access_key_id,
 :aws_secret_access_key => your_aws_secret_access_key
)

Parameters

  • options<~Hash> - config arguments for connection. Defaults to {}.

    • region<~String> - optional region to use. For instance, ‘eu-west-1’, ‘us-east-1’ and etc.

Returns

  • SQS object with connection to AWS.



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/fog/aws/sqs.rb', line 81

def initialize(options={})
  @use_iam_profile = options[:use_iam_profile]
  @instrumentor           = options[:instrumentor]
  @instrumentor_name      = options[:instrumentor_name] || 'fog.aws.sqs'
  @connection_options     = options[:connection_options] || {}
  options[:region] ||= 'us-east-1'
  @region = options[:region]
  @host = options[:host] || "sqs.#{options[:region]}.amazonaws.com"

  @path       = options[:path]        || '/'
  @persistent = options[:persistent]  || false
  @port       = options[:port]        || 443
  @scheme     = options[:scheme]      || 'https'
  @connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options)

  setup_credentials(options)
end

Instance Method Details

#change_message_visibility(queue_url, receipt_handle, visibility_timeout) ⇒ Object

Change visibility timeout for a message

Parameters

  • queue_url<~String> - Url of queue for message to update

  • receipt_handle<~String> - Token from previous recieve message

  • visibility_timeout<~Integer> - New visibility timeout in 0..43200

See Also

docs.amazonwebservices.com/AWSSimpleQueueService/latest/APIReference/Query_QueryChangeMessageVisibility.html



18
19
20
21
22
23
24
25
26
# File 'lib/fog/aws/requests/sqs/change_message_visibility.rb', line 18

def change_message_visibility(queue_url, receipt_handle, visibility_timeout)
  request({
    'Action'            => 'ChangeMessageVisibility',
    'ReceiptHandle'     => receipt_handle,
    'VisibilityTimeout' => visibility_timeout,
    :parser             => Fog::Parsers::AWS::SQS::Basic.new,
    :path               => path_from_queue_url(queue_url)
  })
end

#create_queue(name, options = {}) ⇒ Object

Create a queue

Parameters

  • name<~String> - Name of queue to create

  • options<~Hash>:

    • DefaultVisibilityTimeout<~String> - Time, in seconds, to hide a message after it has been received, in 0..43200, defaults to 30

See Also

docs.amazonwebservices.com/AWSSimpleQueueService/latest/APIReference/Query_QueryCreateQueue.html



18
19
20
21
22
23
24
# File 'lib/fog/aws/requests/sqs/create_queue.rb', line 18

def create_queue(name, options = {})
  request({
    'Action'    => 'CreateQueue',
    'QueueName' => name,
    :parser     => Fog::Parsers::AWS::SQS::CreateQueue.new
  }.merge!(options))
end

#delete_message(queue_url, receipt_handle) ⇒ Object

Delete a message from a queue

Parameters

  • queue_url<~String> - Url of queue to delete message from

  • receipt_handle<~String> - Token from previous recieve message

See Also

docs.amazonwebservices.com/AWSSimpleQueueService/latest/APIReference/Query_QueryDeleteMessage.html



17
18
19
20
21
22
23
24
# File 'lib/fog/aws/requests/sqs/delete_message.rb', line 17

def delete_message(queue_url, receipt_handle)
  request({
    'Action'        => 'DeleteMessage',
    'ReceiptHandle' => receipt_handle,
    :parser         => Fog::Parsers::AWS::SQS::Basic.new,
    :path           => path_from_queue_url(queue_url),
  })
end

#delete_queue(queue_url) ⇒ Object

Delete a queue

Parameters

  • queue_url<~String> - Url of queue to delete

See Also

docs.amazonwebservices.com/AWSSimpleQueueService/latest/APIReference/Query_QueryDeleteQueue.html



16
17
18
19
20
21
22
# File 'lib/fog/aws/requests/sqs/delete_queue.rb', line 16

def delete_queue(queue_url)
  request({
    'Action' => 'DeleteQueue',
    :parser  => Fog::Parsers::AWS::SQS::Basic.new,
    :path    => path_from_queue_url(queue_url),
  })
end

#get_queue_attributes(queue_url, attribute_name) ⇒ Object

Get attributes of a queue

Parameters

  • queue_url<~String> - Url of queue to get attributes for

  • attribute_name<~Array> - Name of attribute to return, in [‘All’, ‘ApproximateNumberOfMessages’, ‘ApproximateNumberOfMessagesNotVisible’, ‘CreatedTimestamp’, ‘LastModifiedTimestamp’, ‘MaximumMessageSize’, ‘MessageRetentionPeriod’, ‘Policy’, ‘QueueArn’, ‘VisibilityTimeout’]

See Also

docs.amazonwebservices.com/AWSSimpleQueueService/latest/APIReference/Query_QueryGetQueueAttributes.html



17
18
19
20
21
22
23
24
# File 'lib/fog/aws/requests/sqs/get_queue_attributes.rb', line 17

def get_queue_attributes(queue_url, attribute_name)
  request({
    'Action'        => 'GetQueueAttributes',
    'AttributeName' => attribute_name,
    :path           => path_from_queue_url(queue_url),
    :parser         => Fog::Parsers::AWS::SQS::GetQueueAttributes.new
  })
end

#list_queues(options = {}) ⇒ Object

List queues

Parameters

  • options<~Hash>:

    • QueueNamePrefix<~String> - String used to filter results to only those with matching prefixes

See Also

docs.amazonwebservices.com/AWSSimpleQueueService/latest/APIReference/Query_QueryListQueues.html



17
18
19
20
21
22
# File 'lib/fog/aws/requests/sqs/list_queues.rb', line 17

def list_queues(options = {})
  request({
    'Action' => 'ListQueues',
    :parser  => Fog::Parsers::AWS::SQS::ListQueues.new
  }.merge!(options))
end

#receive_message(queue_url, options = {}) ⇒ Object

Get a message from a queue (marks it as unavailable temporarily, but does not remove from queue, see delete_message)

Parameters

  • queue_url<~String> - Url of queue to get message from

  • options<~Hash>:

    • Attributes<~Array> - List of attributes to return, in [‘All’, ‘ApproximateFirstReceiveTimestamp’, ‘ApproximateReceiveCount’, ‘SenderId’, ‘SentTimestamp’], defaults to ‘All’

    • MaxNumberOfMessages<~Integer> - Maximum number of messages to return, defaults to 1

    • VisibilityTimeout<~Integer> - Duration, in seconds, to hide message from other receives. In 0..43200, defaults to visibility timeout for queue

See Also

docs.amazonwebservices.com/AWSSimpleQueueService/latest/APIReference/Query_QueryReceiveMessage.html



20
21
22
23
24
25
26
27
# File 'lib/fog/aws/requests/sqs/receive_message.rb', line 20

def receive_message(queue_url, options = {})
  request({
    'Action'        => 'ReceiveMessage',
    'AttributeName' => 'All',
    :path           => path_from_queue_url(queue_url),
    :parser         => Fog::Parsers::AWS::SQS::ReceiveMessage.new
  }.merge!(options))
end

#reloadObject



99
100
101
# File 'lib/fog/aws/sqs.rb', line 99

def reload
  @connection.reset
end

#send_message(queue_url, message) ⇒ Object

Add a message to a queue

Parameters

  • queue_url<~String> - Url of queue to add message to

  • message<~String> - Message to add to queue

See Also

docs.amazonwebservices.com/AWSSimpleQueueService/latest/APIReference/Query_QuerySendMessage.html



17
18
19
20
21
22
23
24
# File 'lib/fog/aws/requests/sqs/send_message.rb', line 17

def send_message(queue_url, message)
  request({
    'Action'      => 'SendMessage',
    'MessageBody' => message,
    :path         => path_from_queue_url(queue_url),
    :parser       => Fog::Parsers::AWS::SQS::SendMessage.new
  })
end

#set_queue_attributes(queue_url, attribute_name, attribute_value) ⇒ Object

Get attributes of a queue

Parameters

  • queue_url<~String> - Url of queue to get attributes for

  • attribute_name<~String> - Name of attribute to set, keys in [‘MaximumMessageSize’, ‘MessageRetentionPeriod’, ‘Policy’, ‘VisibilityTimeout’]

  • attribute_value<~String> - Value to set for attribute

See Also

docs.amazonwebservices.com/AWSSimpleQueueService/latest/APIReference/Query_QuerySetQueueAttributes.html



18
19
20
21
22
23
24
25
26
# File 'lib/fog/aws/requests/sqs/set_queue_attributes.rb', line 18

def set_queue_attributes(queue_url, attribute_name, attribute_value)
  request({
    'Action'          => 'SetQueueAttributes',
    'Attribute.Name'  => attribute_name,
    'Attribute.Value' => attribute_value,
    :path             => path_from_queue_url(queue_url),
    :parser           => Fog::Parsers::AWS::SQS::Basic.new
  })
end