Sha256: d06951fa78a084bcb4c2063de50522de40f8ea42deae7c460a430297482abddc

Contents?: true

Size: 1.54 KB

Versions: 3

Compression:

Stored size: 1.54 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 = {}
        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
        {}
      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

3 entries across 3 versions & 2 rubygems

Version Path
legion-transport-1.1.5 lib/legion/transport/exchange.rb
legion-transport-java-1.1.4 lib/legion/transport/exchange.rb
legion-transport-1.1.4 lib/legion/transport/exchange.rb