Sha256: a18956c779fbfb9f4c8e24a718d051b36cfa4ccd4be1ae133a8517e6eae88a71

Contents?: true

Size: 1.44 KB

Versions: 32

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

module RubyRabbitmqJanus
  module Rabbit
    # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
    #
    # Class for manage connection with RabbitMQ
    class Connect
      # Initialize connection to server RabbitMQ
      def initialize
        @rabbit = Bunny.new(Tools::Config.instance.server_settings)
      rescue => exception
        raise Errors::Rabbit::Connect::Initialize, exception
      end

      # Create an transaction with rabbitmq and close after response is received
      def transaction_short
        response = transaction_long { yield }
        close
        response
      rescue => exception
        raise Errors::Rabbit::Connect::TransactionShort, exception
      end

      # Create an transaction with rabbitmq and not close
      def transaction_long
        start
        yield
      rescue => exception
        raise Errors::Rabbit::Connect::TransactionLong, exception
      end

      # Opening a connection with RabbitMQ
      def start
        @rabbit.start
      rescue => exception
        raise Errors::Rabbit::Connect::Start, exception
      end

      # Close connection to server RabbitMQ
      def close
        @rabbit.close
      rescue => exception
        raise Errors::Rabbit::Connect::Close, exception
      end

      # Create an channel
      def channel
        @rabbit.create_channel
      rescue => exception
        raise Errors::Rabbit::Connect::Channel, exception
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
ruby_rabbitmq_janus-3.0.0.pre.327 lib/rrj/rabbit/connect.rb
ruby_rabbitmq_janus-2.7.2 lib/rrj/rabbit/connect.rb
ruby_rabbitmq_janus-2.7.2.pre.322 lib/rrj/rabbit/connect.rb
ruby_rabbitmq_janus-2.7.2.pre.317 lib/rrj/rabbit/connect.rb
ruby_rabbitmq_janus-2.7.2.pre.316 lib/rrj/rabbit/connect.rb
ruby_rabbitmq_janus-2.7.2.pre.315 lib/rrj/rabbit/connect.rb
ruby_rabbitmq_janus-2.7.2.pre.314 lib/rrj/rabbit/connect.rb
ruby_rabbitmq_janus-2.7.2.pre.312 lib/rrj/rabbit/connect.rb
ruby_rabbitmq_janus-2.7.2.pre.310 lib/rrj/rabbit/connect.rb
ruby_rabbitmq_janus-2.7.2.pre.309 lib/rrj/rabbit/connect.rb
ruby_rabbitmq_janus-2.7.2.pre.308 lib/rrj/rabbit/connect.rb
ruby_rabbitmq_janus-2.7.2.pre.307 lib/rrj/rabbit/connect.rb
ruby_rabbitmq_janus-2.7.2.pre.306 lib/rrj/rabbit/connect.rb
ruby_rabbitmq_janus-2.7.2.pre.305 lib/rrj/rabbit/connect.rb
ruby_rabbitmq_janus-2.7.2.pre.302 lib/rrj/rabbit/connect.rb
ruby_rabbitmq_janus-2.7.2.pre.297 lib/rrj/rabbit/connect.rb
ruby_rabbitmq_janus-2.7.2.pre.296 lib/rrj/rabbit/connect.rb
ruby_rabbitmq_janus-2.7.2.pre.286 lib/rrj/rabbit/connect.rb
ruby_rabbitmq_janus-2.7.2.pre.285 lib/rrj/rabbit/connect.rb
ruby_rabbitmq_janus-2.7.2.pre.284 lib/rrj/rabbit/connect.rb