Skip to content

Instantly share code, notes, and snippets.

@thom-nic
Created February 8, 2012 13:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thom-nic/1769257 to your computer and use it in GitHub Desktop.
Save thom-nic/1769257 to your computer and use it in GitHub Desktop.
Rainbows + AMQP configuration
# run with rainbows -c rainbows.config.rb
require 'rainbows'
listen 8888 # by default Unicorn listens on port 8080
worker_processes 9 # this should be >= nr_cpus
pid "unicorn.pid"
#stderr_path "unicorn.log"
#stdout_path "unicorn.log"
# nuke workers after 30 seconds instead of 60 seconds (the default)
timeout 30
preload_app true
Rainbows! do
use :EventMachine
worker_connections 50
end
after_fork do |server, worker|
require 'amqp'
EventMachine.next_tick do
AMQP.connect('amqp://localhost')
sleep 1.0
AMQP.channel ||= AMQP::Channel.new(AMQP.connection)
AMQP.channel.queue("schwartz.test").subscribe do |headers, msg|
puts "Got message: #{msg}"
end
3.times do |i|
AMQP.channel.default_exchange.publish(
"A warmup message #{i} from #{Time.now.strftime('%H:%M:%S %m/%b/%Y')}",
:routing_key => "schwartz.test")
end
puts "Sent warmup message..."
end
end
@thom-nic
Copy link
Author

thom-nic commented Feb 8, 2012

Calling AMQP.connect from within EventMachine.next_tick seems to make this work, versus calling AMQP.start prior to next_tick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment