Created
February 8, 2012 13:05
-
-
Save thom-nic/1769257 to your computer and use it in GitHub Desktop.
Rainbows + AMQP configuration
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
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Calling
AMQP.connect
from withinEventMachine.next_tick
seems to make this work, versus callingAMQP.start
prior tonext_tick