class Artsy::EventService::RabbitMQConnection

Public Class Methods

build_connection() click to toggle source

Build a new connection to RabbitMQ

# File lib/artsy-eventservice/artsy/event_service/rabbitmq_connection.rb, line 11
def self.build_connection
  conn = Bunny.new(self.rabbitmq_url, **self.bunny_params)
  conn.start
  conn
end
bunny_params() click to toggle source
# File lib/artsy-eventservice/artsy/event_service/rabbitmq_connection.rb, line 38
def self.bunny_params
  self.config.tls ? self.tls_params : self.no_tls_params
end
config() click to toggle source
# File lib/artsy-eventservice/artsy/event_service/rabbitmq_connection.rb, line 56
def self.config
  Artsy::EventService.config
end
get_channel() { |channel| ... } click to toggle source

Get a channel from the connection - synchronized access to create_channel is provided by Bunny

# File lib/artsy-eventservice/artsy/event_service/rabbitmq_connection.rb, line 27
def self.get_channel
  channel = self.get_connection.create_channel
  yield channel if block_given?
ensure
  channel.close if channel && channel.open?
end
get_connection() click to toggle source

Synchronized access to the connection

# File lib/artsy-eventservice/artsy/event_service/rabbitmq_connection.rb, line 18
def self.get_connection
  @mutex.synchronize do
    @connection ||= self.build_connection
    @connection = self.build_connection if @connection.closed?
    @connection
  end
end
no_tls_params() click to toggle source
# File lib/artsy-eventservice/artsy/event_service/rabbitmq_connection.rb, line 52
def self.no_tls_params
  {}
end
rabbitmq_url() click to toggle source
# File lib/artsy-eventservice/artsy/event_service/rabbitmq_connection.rb, line 34
def self.rabbitmq_url
  self.config.rabbitmq_url
end
tls_params() click to toggle source
# File lib/artsy-eventservice/artsy/event_service/rabbitmq_connection.rb, line 42
def self.tls_params
  {
    tls: self.config.tls,
    tls_cert: self.config.tls_cert,
    tls_key: self.config.tls_key,
    tls_ca_certificates: [self.config.tls_ca_certificate],
    verify_peer: self.config.verify_peer
  }
end