summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2015-11-07 15:38:01 -0700
committermo khan <mo@mokhan.ca>2015-11-07 15:38:01 -0700
commit9511d7350dc913561fe23208c5cbc7b8e7435468 (patch)
tree3a1d22f084a5ed3b0e4046fb2bb6e4e8a179f70c
parent7a73f5aec92f7390669f9836492fe9700e7421cb (diff)
move heartbeat and prefetch to amqp.yml
-rw-r--r--config/amqp.yml6
-rw-r--r--lib/killjoy/amqp_configuration.rb8
-rw-r--r--lib/killjoy/message_bus.rb4
-rw-r--r--lib/killjoy/tasks/rabbitmq.rake12
4 files changed, 26 insertions, 4 deletions
diff --git a/config/amqp.yml b/config/amqp.yml
index 859cf94..d816d7f 100644
--- a/config/amqp.yml
+++ b/config/amqp.yml
@@ -3,13 +3,19 @@ development:
exchange: 'killjoy'
exchange_type: 'x-modulus-hash'
shards: <%= ENV.fetch("RMQ_SHARDS", 4).to_i %>
+ heartbeat: 2
+ prefetch: 8
test:
amqp_uri: '<%= ENV.fetch("RABBITMQ_URL", "amqp://guest:guest@localhost:5672") %>'
exchange: 'killjoy'
exchange_type: 'x-modulus-hash'
shards: <%= ENV.fetch("RMQ_SHARDS", 4).to_i %>
+ heartbeat: 2
+ prefetch: 8
production:
amqp_uri: '<%= ENV.fetch("RABBITMQ_URL", "amqp://guest:guest@localhost:5672") %>'
exchange: 'killjoy'
exchange_type: 'x-modulus-hash'
+ heartbeat: 2
+ prefetch: 8
shards: <%= ENV.fetch("RMQ_SHARDS", 4).to_i %>
diff --git a/lib/killjoy/amqp_configuration.rb b/lib/killjoy/amqp_configuration.rb
index 87bfab3..62262f8 100644
--- a/lib/killjoy/amqp_configuration.rb
+++ b/lib/killjoy/amqp_configuration.rb
@@ -10,6 +10,14 @@ module Killjoy
configuration['amqp_uri']
end
+ def heartbeat
+ configuration['heartbeat'].to_i
+ end
+
+ def prefetch
+ configuration['prefetch'].to_i
+ end
+
def exchange
configuration['exchange']
end
diff --git a/lib/killjoy/message_bus.rb b/lib/killjoy/message_bus.rb
index f60080a..cfb6cd5 100644
--- a/lib/killjoy/message_bus.rb
+++ b/lib/killjoy/message_bus.rb
@@ -43,7 +43,7 @@ module Killjoy
def connection
@connection ||= Bunny.new(
configuration.amqp_uri,
- heartbeat: 2,
+ heartbeat: configuration.heartbeat,
logger: Killjoy.logger
).tap do |connection|
connection.start
@@ -52,7 +52,7 @@ module Killjoy
def channel
@channel ||= connection.create_channel(nil, @cpus).tap do |x|
- x.prefetch(@cpus)
+ x.prefetch(configuration.prefetch)
end
end
diff --git a/lib/killjoy/tasks/rabbitmq.rake b/lib/killjoy/tasks/rabbitmq.rake
index f44e9e9..e18f9d5 100644
--- a/lib/killjoy/tasks/rabbitmq.rake
+++ b/lib/killjoy/tasks/rabbitmq.rake
@@ -1,4 +1,9 @@
namespace :rabbitmq do
+ require 'active_support/core_ext/string'
+ require 'erb'
+ require 'yaml'
+ require_relative '../amqp_configuration'
+
desc 'setup rabbitmqadmin'
task :setup do
sh "wget http://127.0.0.1:15672/cli/rabbitmqadmin"
@@ -16,8 +21,11 @@ namespace :rabbitmq do
desc "create sharded exchange."
task :create do
- shards = ENV.fetch("RMQ_SHARDS", 4)
- sh "rabbitmqadmin declare exchange --vhost=/ name=killjoy type=x-modulus-hash"
+ configuration = Killjoy::AMQPConfiguration.new
+ exchange = configuration.exchange
+ exchange_type = configuration.exchange_type
+ shards = configuration.shards
+ sh "rabbitmqadmin declare exchange --vhost=/ name=#{exchange} type=#{exchange_type}"
sh "sudo rabbitmqctl set_policy killjoy-shard \"^killjoy$\" '{\"shards-per-node\": #{shards}, \"routing-key\": \"#\"}' --apply-to exchanges"
end