Class: CommApi::Messaging::AMQPClient
- Inherits:
-
Object
- Object
- CommApi::Messaging::AMQPClient
- Includes:
- Singleton
- Defined in:
- lib/commapi/messaging/amqp_client.rb
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ AMQPClient
constructor
A new instance of AMQPClient.
Constructor Details
#initialize ⇒ AMQPClient
Returns a new instance of AMQPClient.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/commapi/messaging/amqp_client.rb', line 16 def initialize rabbitmq = CommApi.configuration.rabbitmq return unless rabbitmq&.has_key?(:url) @config = rabbitmq.with_indifferent_access @connection = Bunny.new(config[:url], log_level: config[:log_level].presence || :error) @connection.start @channel = @connection.create_channel rescue Bunny::TCPConnectionFailed => e puts "Connection to #{amqp_url} failed: #{e.}" end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
10 11 12 |
# File 'lib/commapi/messaging/amqp_client.rb', line 10 def channel @channel end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
10 11 12 |
# File 'lib/commapi/messaging/amqp_client.rb', line 10 def config @config end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
10 11 12 |
# File 'lib/commapi/messaging/amqp_client.rb', line 10 def connection @connection end |
Class Method Details
.classes ⇒ Object
29 30 31 32 33 34 |
# File 'lib/commapi/messaging/amqp_client.rb', line 29 def self.classes Dir["app/exchanges/*.rb", "engines/**/app/exchanges/*.rb"]. map { |file| File.basename(file, ".rb") }. map(&:camelize). map(&:constantize) end |
.connect ⇒ Object
36 37 38 |
# File 'lib/commapi/messaging/amqp_client.rb', line 36 def self.connect classes.each { |k| k.new } if instance.connection&.connected? end |
.disconnect! ⇒ Object
40 41 42 43 |
# File 'lib/commapi/messaging/amqp_client.rb', line 40 def self.disconnect! instance.connection.close @@instance = nil end |
.instance ⇒ Object
12 13 14 |
# File 'lib/commapi/messaging/amqp_client.rb', line 12 def self.instance @@instance ||= new end |