Class: Connectors::Rabbitmq
- Inherits:
-
Object
- Object
- Connectors::Rabbitmq
- Defined in:
- lib/connectors/rabbitmq.rb
Overview
Rabbitmq health checker
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.configured? ⇒ Boolean
24 25 26 27 28 |
# File 'lib/connectors/rabbitmq.rb', line 24 def self.configured? raise StandardError, 'Please make sure you have RabbitMQ installed' unless defined?(::Bunny) 'configured' end |
Instance Method Details
#connect ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/connectors/rabbitmq.rb', line 6 def connect @conn = ::Bunny.new @conn.start @channel = @conn.create_channel @queue = @channel.queue('health_check', auto_delete: true) @queue.publish('ping') true rescue ::Bunny::Exception, ::Bunny::TCPConnectionFailed, ::Bunny::PossibleAuthenticationFailureError => e puts "RabbitMQ Connection Error: #{e.}" false ensure # Queue with auto_delete: true will be automatically deleted when connection closes. @queue&.delete @queue&.purge @channel&.close @conn&.close end |