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

Inherits:
Object
  • Object
show all
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

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, in [‘eu-west-1’, ‘us-east-1’, ‘us-west-1’, ‘us-west-2’, ‘ap-southeast-1’]

Returns

  • SQS object with connection to AWS.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/fog/aws/sqs.rb', line 78

def initialize(options={})
  @aws_access_key_id      = options[:aws_access_key_id]
  @aws_secret_access_key  = options[:aws_secret_access_key]
  @connection_options     = options[:connection_options] || {}
  @hmac = Fog::HMAC.new('sha256', @aws_secret_access_key)
  options[:region] ||= 'us-east-1'
  @host = options[:host] || case options[:region]
  when 'ap-southeast-1'
    'ap-southeast-1.queue.amazonaws.com'
  when 'eu-west-1'
    'eu-west-1.queue.amazonaws.com'
  when 'us-east-1'
    'queue.amazonaws.com'
  when 'us-west-1'
    'us-west-1.queue.amazonaws.com'
  when 'us-west-2'
    'us-west-2.queue.amazonaws.com'
  else
    raise ArgumentError, "Unknown region: #{options[:region].inspect}"
  end
  @path       = options[:path]        || '/'
  @persistent = options[:persistent]  || false
  @port       = options[:port]        || 443
  @scheme     = options[:scheme]      || 'https'
  @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



105
106
107
# File 'lib/fog/aws/sqs.rb', line 105

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



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

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



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

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