Class: Rabbithole::Connection
- Inherits:
-
Object
- Object
- Rabbithole::Connection
- Defined in:
- lib/rabbithole/connection.rb
Defined Under Namespace
Classes: Settings
Constant Summary collapse
- QUEUE_PREFIX =
"rabbithole/#{Rails.application.class.parent_name.downcase}"
- DEFAULT_QUEUE =
'default_queue'
Class Method Summary collapse
- .channel ⇒ Object
- .configuration ⇒ Object
- .create_channel(worker_pool_size = 1, name = nil) ⇒ Object
- .default_queue ⇒ Object
- .get_queue_name(queue) ⇒ Object
- .publish(queue_name, payload) ⇒ Object
- .queue(name, channel = self.channel) ⇒ Object
- .session ⇒ Object
Class Method Details
.channel ⇒ Object
45 46 47 |
# File 'lib/rabbithole/connection.rb', line 45 def channel @channel ||= create_channel end |
.configuration ⇒ Object
41 42 43 |
# File 'lib/rabbithole/connection.rb', line 41 def configuration @configuration ||= Settings.to_url end |
.create_channel(worker_pool_size = 1, name = nil) ⇒ Object
37 38 39 |
# File 'lib/rabbithole/connection.rb', line 37 def create_channel(worker_pool_size = 1, name = nil) self.session.create_channel(name, worker_pool_size) end |
.default_queue ⇒ Object
17 18 19 |
# File 'lib/rabbithole/connection.rb', line 17 def default_queue queue DEFAULT_QUEUE end |
.get_queue_name(queue) ⇒ Object
21 22 23 |
# File 'lib/rabbithole/connection.rb', line 21 def get_queue_name(queue) "#{QUEUE_PREFIX}.#{queue}" end |
.publish(queue_name, payload) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/rabbithole/connection.rb', line 10 def publish(queue_name, payload) channel = create_channel queue(queue_name) channel.default_exchange.publish(payload, :routing_key => get_queue_name(queue_name)) channel.close end |
.queue(name, channel = self.channel) ⇒ Object
25 26 27 |
# File 'lib/rabbithole/connection.rb', line 25 def queue(name, channel = self.channel) channel.queue(get_queue_name(name), :durable => true) end |
.session ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/rabbithole/connection.rb', line 29 def session @connection ||= begin connection = Bunny.new(configuration) connection.start end end |