Class: Tackle::Rabbit
- Inherits:
-
Object
- Object
- Tackle::Rabbit
- Includes:
- TackleLogger
- Defined in:
- lib/tackle/rabbit.rb
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#dead_letter_queue ⇒ Object
readonly
Returns the value of attribute dead_letter_queue.
-
#exchange ⇒ Object
readonly
Returns the value of attribute exchange.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
Instance Method Summary collapse
- #close ⇒ Object
- #connect ⇒ Object
- #dead_letter_exchange_name ⇒ Object
- #dead_letter_queue_name ⇒ Object
-
#initialize(exchange_name, routing_key, queue_name, amqp_url, retry_delay, logger) ⇒ Rabbit
constructor
A new instance of Rabbit.
- #on_uncaught_exception(blk) ⇒ Object
Methods included from TackleLogger
Constructor Details
#initialize(exchange_name, routing_key, queue_name, amqp_url, retry_delay, logger) ⇒ Rabbit
11 12 13 14 15 16 17 18 |
# File 'lib/tackle/rabbit.rb', line 11 def initialize(exchange_name, routing_key, queue_name, amqp_url, retry_delay, logger) @exchange_name = exchange_name @routing_key = routing_key @queue_name = queue_name @amqp_url = amqp_url @retry_delay = retry_delay @logger = logger end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
9 10 11 |
# File 'lib/tackle/rabbit.rb', line 9 def channel @channel end |
#dead_letter_queue ⇒ Object (readonly)
Returns the value of attribute dead_letter_queue.
9 10 11 |
# File 'lib/tackle/rabbit.rb', line 9 def dead_letter_queue @dead_letter_queue end |
#exchange ⇒ Object (readonly)
Returns the value of attribute exchange.
9 10 11 |
# File 'lib/tackle/rabbit.rb', line 9 def exchange @exchange end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
9 10 11 |
# File 'lib/tackle/rabbit.rb', line 9 def queue @queue end |
Instance Method Details
#close ⇒ Object
41 42 43 44 45 46 |
# File 'lib/tackle/rabbit.rb', line 41 def close @channel.close tackle_log("Closed channel") @conn.close tackle_log("Closed connection to RabbitMQ") end |
#connect ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/tackle/rabbit.rb', line 20 def connect @conn = Bunny.new(@amqp_url) @conn.start tackle_log("Connected to RabbitMQ") @channel = @conn.create_channel @channel.prefetch(1) tackle_log("Connected to channel") connect_queue connect_dead_letter_queue rescue StandardError => ex tackle_log("An exception occured while connecting to the server message='#{ex.message}'") raise ex end |
#dead_letter_exchange_name ⇒ Object
48 49 50 |
# File 'lib/tackle/rabbit.rb', line 48 def dead_letter_exchange_name "#{@exchange_name}.dead_letter_exchange" end |
#dead_letter_queue_name ⇒ Object
52 53 54 |
# File 'lib/tackle/rabbit.rb', line 52 def dead_letter_queue_name "#{@queue_name}_dead_letters" end |
#on_uncaught_exception(blk) ⇒ Object
37 38 39 |
# File 'lib/tackle/rabbit.rb', line 37 def on_uncaught_exception(blk) @channel.on_uncaught_exception(&blk) end |