2011-02-05 23:17:47 -05:00
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class SQS
|
|
|
|
class Real
|
|
|
|
|
|
|
|
require 'fog/aws/parsers/sqs/send_message'
|
|
|
|
|
2011-07-19 16:10:26 -04:00
|
|
|
# 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
|
|
|
|
# http://docs.amazonwebservices.com/AWSSimpleQueueService/latest/APIReference/Query_QuerySendMessage.html
|
|
|
|
#
|
|
|
|
|
|
|
|
def send_message(queue_url, message)
|
2011-02-05 23:17:47 -05:00
|
|
|
request({
|
|
|
|
'Action' => 'SendMessage',
|
|
|
|
'MessageBody' => message,
|
2011-07-19 16:10:26 -04:00
|
|
|
:path => path_from_queue_url(queue_url),
|
2011-02-05 23:17:47 -05:00
|
|
|
:parser => Fog::Parsers::AWS::SQS::SendMessage.new
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2011-09-18 16:00:58 -04:00
|
|
|
|
|
|
|
class Mock
|
|
|
|
|
|
|
|
def send_message(queue_url, message)
|
|
|
|
Excon::Response.new.tap do |response|
|
|
|
|
if (queue = data[:queues][queue_url])
|
|
|
|
response.status = 200
|
|
|
|
|
|
|
|
now = Time.now
|
|
|
|
message_id = Fog::AWS::Mock.sqs_message_id
|
|
|
|
md5 = Digest::MD5.hexdigest(message)
|
|
|
|
|
|
|
|
queue[:messages][message_id] = {
|
|
|
|
'MessageId' => message_id,
|
|
|
|
'Body' => message,
|
|
|
|
'MD5OfBody' => md5,
|
|
|
|
'Attributes' => {
|
|
|
|
'SenderId' => Fog::AWS::Mock.sqs_message_id,
|
|
|
|
'SentTimestamp' => now
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
queue['Attributes']['LastModifiedTimestamp'] = now
|
|
|
|
|
|
|
|
response.body = {
|
|
|
|
'ResponseMetadata' => {
|
|
|
|
'RequestId' => Fog::AWS::Mock.request_id
|
|
|
|
},
|
|
|
|
'MessageId' => message_id,
|
|
|
|
'MD5OfMessageBody' => md5
|
|
|
|
}
|
|
|
|
else
|
|
|
|
response.status = 404
|
|
|
|
raise(Excon::Errors.status_error({:expects => 200}, response))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2011-02-05 23:17:47 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|