sul-dlss/dor-services-app

View on GitHub
app/services/notifications/rabbit_channel.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
# frozen_string_literal: true

module Notifications
  # Creates a connection to RabbitMQ using the Bunny gem
  class RabbitChannel
    include Singleton

    delegate :topic, to: :channel

    def channel
      @channel ||= connection.create_channel
    end

    def connection
      @connection ||= Bunny.new(hostname: Settings.rabbitmq.hostname,
                                vhost: Settings.rabbitmq.vhost,
                                username: Settings.rabbitmq.username,
                                password: Settings.rabbitmq.password).tap(&:start)
    end
  end
end