Sha256: f38d093f3f846c55e668bb057d4a4010817aded1f24be4a34c704a8387d74693

Contents?: true

Size: 1.58 KB

Versions: 2

Compression:

Stored size: 1.58 KB

Contents

module Legion
  module Transport
    class Exchange < Legion::Transport::CONNECTOR::Exchange
      include Legion::Transport::Common

      def initialize(exchange = exchange_name, options = {})
        @options = options
        @type = options[:type] || default_type
        if Legion::Transport::TYPE == 'march_hare'
          super_options = options_builder(default_options, exchange_options, @options)
          super_options[:type] = @type
          super(channel, exchange, **super_options)
        else
          super(channel, @type, exchange, options_builder(default_options, exchange_options, @options))
        end
      rescue Legion::Transport::CONNECTOR::PreconditionFailed, Legion::Transport::CONNECTOR::ChannelAlreadyClosed
        raise unless @retries.nil?

        @retries = 1
        delete_exchange(exchange)
        retry
      end

      def delete_exchange(exchange)
        Legion::Logging.warn "Exchange:#{exchange} exists with wrong parameters, deleting and creating"
        channel.exchange_delete(exchange)
      end

      def default_options
        hash = Concurrent::Hash.new
        hash[:durable] = true
        hash[:auto_delete] = false
        hash[:arguments] = {}
        hash
      end

      def exchange_name
        self.class.ancestors.first.to_s.split('::')[2].downcase
      end

      def exchange_options
        Concurrent::Hash.new
      end

      def delete(options = {})
        super(options)
        true
      rescue Legion::Transport::CONNECTOR::PreconditionFailed
        false
      end

      def default_type
        'topic'
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
legion-transport-1.1.8 lib/legion/transport/exchange.rb
legion-transport-1.1.6 lib/legion/transport/exchange.rb