pingu
pingu

Reputation: 8827

Using AWS SQS with Ruby on Rails

I am unable to find any example on how to Use Amazon AWS SQS service in conjunction with Ruby on Rails.

Please could someone provide a simple, barebones example of using SQS to send email.

Upvotes: 6

Views: 7996

Answers (2)

Pablo Cantero
Pablo Cantero

Reputation: 6357

You may check Shoryuken, it's integrated with SQS and Rails (ActiveJob). But you can also use it without Rails, in a standalone Ruby app.

Upvotes: 6

Naveen Vijay
Naveen Vijay

Reputation: 16482

You may look into these examples. I have taken this from the GitHub GIST - 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

Upvotes: 4

Related Questions