Class: Basquiat::Adapters::RabbitMq::Connection
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Basquiat::Adapters::RabbitMq::Connection
- Defined in:
- lib/basquiat/adapters/rabbitmq/connection.rb
Overview
Control the connection to the RabitMQ server. Delegates calls to Bunny::Connection
Instance Method Summary collapse
-
#connected? ⇒ Boolean
checks if the connection is started.
-
#create_channel ⇒ Bunny::Channel
Creates a channel.
-
#disconnect ⇒ Object
Closes all channels and then the connection.
-
#initialize(hosts:, port: 5672, vhost: '/', tls_options: {}, failover: {}, auth: {}) ⇒ Connection
constructor
A new instance of Connection.
-
#start ⇒ Object
Starts the connection if needed.
Constructor Details
#initialize(hosts:, port: 5672, vhost: '/', tls_options: {}, failover: {}, auth: {}) ⇒ Connection
Returns a new instance of Connection.
24 25 26 27 28 29 30 31 |
# File 'lib/basquiat/adapters/rabbitmq/connection.rb', line 24 def initialize(hosts:, port: 5672, vhost: '/', tls_options: {}, failover: {}, auth: {}) @hosts = hosts @port = port @vhost = vhost = @failover = failover @auth = auth end |
Instance Method Details
#connected? ⇒ Boolean
checks if the connection is started
48 49 50 |
# File 'lib/basquiat/adapters/rabbitmq/connection.rb', line 48 def connected? connection.status == :started end |
#create_channel ⇒ Bunny::Channel
Creates a channel
35 36 37 38 39 |
# File 'lib/basquiat/adapters/rabbitmq/connection.rb', line 35 def create_channel connection.start unless connected? Basquiat.logger.debug 'Creating a new channel' connection.create_channel end |
#disconnect ⇒ Object
Closes all channels and then the connection.
53 54 55 56 57 |
# File 'lib/basquiat/adapters/rabbitmq/connection.rb', line 53 def disconnect connection.close_all_channels connection.close reset end |
#start ⇒ Object
Starts the connection if needed
42 43 44 45 |
# File 'lib/basquiat/adapters/rabbitmq/connection.rb', line 42 def start Basquiat.logger.debug 'Connecting to RabbitMQ' connection.start unless connection.connected? end |