Created
November 3, 2011 12:40
-
-
Save rapind/1336397 to your computer and use it in GitHub Desktop.
SQS Send and Receive Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fog' | |
require 'yaml' | |
Message = Struct.new(:idx, :body, :sent_at) | |
@lorem = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.' | |
# You need to create an amazon aws account to setup an SQS queue and get the access and secret key. | |
QUEUE_URL = 'https://queue.amazonaws.com/446249531791/test_queue' | |
ACCESS_KEY = 'change_me' | |
SECRET_KEY = 'chage_me' | |
sqs = Fog::AWS::SQS.new( | |
:aws_access_key_id => ACCESS_KEY, | |
:aws_secret_access_key => SECRET_KEY | |
) | |
while 1 == 1 do | |
response = sqs.receive_message(QUEUE_URL, { 'Attributes' => [], 'MaxNumberOfMessages' => 10 }) | |
messages = response.body['Message'] | |
unless messages.empty? | |
puts "----" | |
messages.each do |m| | |
body = m['Body'] | |
message = YAML::load(body) | |
puts "Delta for #{message.idx} in seconds: #{Time.now.to_i - message.sent_at.to_i}" | |
end | |
messages.each_with_index do |m, idx| | |
puts "Deleting ##{idx}" | |
sqs.delete_message(QUEUE_URL, m['ReceiptHandle']) | |
end | |
end | |
sleep 5 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fog' | |
require 'yaml' | |
Message = Struct.new(:idx, :body, :sent_at) | |
@lorem = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.' | |
# You need to create an amazon aws account to setup an SQS queue and get the access and secret key. | |
QUEUE_URL = 'https://queue.amazonaws.com/446249531791/test_queue' | |
ACCESS_KEY = 'change_me' | |
SECRET_KEY = 'chage_me' | |
sqs = Fog::AWS::SQS.new( | |
:aws_access_key_id => ACCESS_KEY, | |
:aws_secret_access_key => SECRET_KEY | |
) | |
10000.times do |idx| | |
message = Message.new( idx, @lorem, Time.now.to_i ) | |
serialized_message = YAML::dump(message) | |
sqs.send_message(QUEUE_URL, serialized_message) | |
puts "Sent #{idx}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment