kareem-h
8/18/2016 - 7:18 PM

AWS SQS Example

AWS SQS Example

#!/usr/bin/env ruby

require 'yaml'
require 'aws-sdk'

config_file = File.join(File.dirname(__FILE__),"config.yml")
config = YAML.load(File.read(config_file))
AWS.config(config)

# http://rubydoc.info/github/amazonwebservices/aws-sdk-for-ruby/master/AWS/SQS

sqs = AWS::SQS.new
queue = sqs.queues.create("my_queue")

# http://rubydoc.info/github/amazonwebservices/aws-sdk-for-ruby/master/AWS/SQS/Queue

send = lambda { |name, queue|
  while true do
    queue.send_message("#{name}:#{Time.now.to_s}")
    sleep 1
  end
}

Thread.new { send.call("t1", queue) }
Thread.new { send.call("t2", queue) }
Thread.new { send.call("t3", queue) }

sleep 1000
#!/usr/bin/env ruby

require 'yaml'
require 'aws-sdk'

config_file = File.join(File.dirname(__FILE__),"config.yml")
config = YAML.load(File.read(config_file))
AWS.config(config)

sqs = AWS::SQS.new
queue = sqs.queues.create("my_queue")
queue.poll do |msg|
  puts msg.body
end
access_key_id: xxx
secret_access_key: yyy