Sha256: 6b7025fedfe10f7d1124a9dc7cd2a7287ed2e25d6ce093a5c69f08d7da71f35f

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 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

      def channel
        Legion::Transport::Connection.channel
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
legion-transport-1.1.9 lib/legion/transport/exchange.rb