Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 408
pingu Avatar asked Jun 30 '14 10:06

pingu


2 Answers

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.

like image 102
Pablo Cantero Avatar answered Sep 20 '22 13:09

Pablo Cantero


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
like image 36
Naveen Vijay Avatar answered Sep 21 '22 13:09

Naveen Vijay