Class: AngieCoreApi::Message::AMQPClient
- Inherits:
-
Object
- Object
- AngieCoreApi::Message::AMQPClient
- Includes:
- Singleton
- Defined in:
- lib/angie-core-api/message/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
- #amqp_url ⇒ Object
-
#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 28 |
# File 'lib/angie-core-api/message/amqp_client.rb', line 16 def initialize @rabbitmq_config = AngieCoreApi.configuration.rabbitmq @config = HashWithIndifferentAccess.new(@rabbitmq_config) @connection = Bunny.new(config[:url]) @connection.start @channel = @connection.create_channel puts "Connected to #{amqp_url}" 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/angie-core-api/message/amqp_client.rb', line 10 def channel @channel end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
10 11 12 |
# File 'lib/angie-core-api/message/amqp_client.rb', line 10 def config @config end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
10 11 12 |
# File 'lib/angie-core-api/message/amqp_client.rb', line 10 def connection @connection end |
Class Method Details
.classes ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/angie-core-api/message/amqp_client.rb', line 30 def self.classes Dir["app/topics/*.rb"]. map { |file| File.basename(file, ".rb") }. select { |type| type != "application_topic" }. map(&:camelize). map(&:constantize) end |
.connect ⇒ Object
38 39 40 41 42 |
# File 'lib/angie-core-api/message/amqp_client.rb', line 38 def self.connect AMQPClient.instance classes.each { |k| k.new } end |
.disconnect! ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/angie-core-api/message/amqp_client.rb', line 44 def self.disconnect! amqp_url = AMQPClient.instance.amqp_url AMQPClient.instance.channel.close AMQPClient.instance.connection.close @@instance = nil puts "Disconnected from #{amqp_url}" end |
.instance ⇒ Object
12 13 14 |
# File 'lib/angie-core-api/message/amqp_client.rb', line 12 def self.instance @@instance ||= new end |
.reconnect! ⇒ Object
54 55 56 57 |
# File 'lib/angie-core-api/message/amqp_client.rb', line 54 def self.reconnect! disconnect! connect end |
Instance Method Details
#amqp_url ⇒ Object
59 60 61 |
# File 'lib/angie-core-api/message/amqp_client.rb', line 59 def amqp_url @config[:url].sub(/\/\/.*@/, "//") end |