legion-transport-java 1.1.3 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/legion/transport.rb +5 -5
 - data/lib/legion/transport/connection.rb +38 -8
 - data/lib/legion/transport/exchange.rb +9 -3
 - data/lib/legion/transport/message.rb +7 -1
 - data/lib/legion/transport/messages/subtask.rb +0 -11
 - data/lib/legion/transport/queue.rb +2 -2
 - data/lib/legion/transport/settings.rb +1 -1
 - data/lib/legion/transport/version.rb +1 -1
 - data/settings/transport.json +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 9fdf527820df05c7bef42a3b791b8a6d41bff76e5ba0f7a4cae339bf7218ff42
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: f960161a203c93bb1d4a9f08f0f74417823da111e229f1ebc6588fc1e8958b08
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 8d68e3a437304d70798e16c47a31efee681e9c1757d5da663edd29e29520d9a28ded595aef4da5a49bd2fe8345b6b7f2008563aad57ef99f0cd82916c88c27e9
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 44aaba9fd6138fa50ba86acf0cd8ef5b5ac9bd50ee078084e6061095e35f45d1e8c3801a4ac663e97a77e6c9a24d37e286a06f198a5aee6ea98e3ac509270c2a
         
     | 
    
        data/lib/legion/transport.rb
    CHANGED
    
    | 
         @@ -3,10 +3,11 @@ require_relative 'transport/settings' 
     | 
|
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
            module Legion
         
     | 
| 
       5 
5 
     | 
    
         
             
              module Transport
         
     | 
| 
       6 
     | 
    
         
            -
                 
     | 
| 
       7 
     | 
    
         
            -
                   
     | 
| 
       8 
     | 
    
         
            -
                   
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
      
 6 
     | 
    
         
            +
                begin
         
     | 
| 
      
 7 
     | 
    
         
            +
                  require 'march_hare'
         
     | 
| 
      
 8 
     | 
    
         
            +
                  TYPE = 'march_hare'.freeze
         
     | 
| 
      
 9 
     | 
    
         
            +
                  CONNECTOR = ::MarchHare
         
     | 
| 
      
 10 
     | 
    
         
            +
                rescue LoadError
         
     | 
| 
       10 
11 
     | 
    
         
             
                  require 'bunny'
         
     | 
| 
       11 
12 
     | 
    
         
             
                  TYPE = 'bunny'.freeze
         
     | 
| 
       12 
13 
     | 
    
         
             
                  CONNECTOR = ::Bunny
         
     | 
| 
         @@ -16,6 +17,5 @@ module Legion 
     | 
|
| 
       16 
17 
     | 
    
         
             
              require_relative 'transport/common'
         
     | 
| 
       17 
18 
     | 
    
         
             
              require_relative 'transport/queue'
         
     | 
| 
       18 
19 
     | 
    
         
             
              require_relative 'transport/exchange'
         
     | 
| 
       19 
     | 
    
         
            -
              require_relative 'transport/consumer'
         
     | 
| 
       20 
20 
     | 
    
         
             
              require_relative 'transport/message'
         
     | 
| 
       21 
21 
     | 
    
         
             
            end
         
     | 
| 
         @@ -8,11 +8,24 @@ module Legion 
     | 
|
| 
       8 
8 
     | 
    
         
             
                      Legion::Transport::CONNECTOR
         
     | 
| 
       9 
9 
     | 
    
         
             
                    end
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
                    def setup # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
         
     | 
| 
      
 11 
     | 
    
         
            +
                    def setup # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
         
     | 
| 
      
 12 
     | 
    
         
            +
                      Legion::Logging.info("Using transport connector: #{Legion::Transport::CONNECTOR}")
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
       12 
14 
     | 
    
         
             
                      if @session.respond_to?(:value) && session.respond_to?(:closed?) && session.closed?
         
     | 
| 
       13 
     | 
    
         
            -
                        @channel_thread = Concurrent::ThreadLocalVar.new
         
     | 
| 
      
 15 
     | 
    
         
            +
                        @channel_thread = Concurrent::ThreadLocalVar.new(nil)
         
     | 
| 
       14 
16 
     | 
    
         
             
                      elsif @session.respond_to?(:value) && session.respond_to?(:closed?) && session.open?
         
     | 
| 
       15 
     | 
    
         
            -
                         
     | 
| 
      
 17 
     | 
    
         
            +
                        nil
         
     | 
| 
      
 18 
     | 
    
         
            +
                      elsif Legion::Transport::TYPE == 'march_hare'
         
     | 
| 
      
 19 
     | 
    
         
            +
                        @session ||= Concurrent::Atom.new(
         
     | 
| 
      
 20 
     | 
    
         
            +
                          MarchHare.connect(host: Legion::Settings[:transport][:connection][:host],
         
     | 
| 
      
 21 
     | 
    
         
            +
                                            vhost: Legion::Settings[:transport][:connection][:vhost],
         
     | 
| 
      
 22 
     | 
    
         
            +
                                            user: Legion::Settings[:transport][:connection][:user],
         
     | 
| 
      
 23 
     | 
    
         
            +
                                            password: Legion::Settings[:transport][:connection][:password],
         
     | 
| 
      
 24 
     | 
    
         
            +
                                            port: Legion::Settings[:transport][:connection][:port])
         
     | 
| 
      
 25 
     | 
    
         
            +
                        )
         
     | 
| 
      
 26 
     | 
    
         
            +
                        @channel_thread = Concurrent::ThreadLocalVar.new(nil)
         
     | 
| 
      
 27 
     | 
    
         
            +
                        session.start
         
     | 
| 
      
 28 
     | 
    
         
            +
                        session.create_channel.basic_qos(1)
         
     | 
| 
       16 
29 
     | 
    
         
             
                      else
         
     | 
| 
       17 
30 
     | 
    
         
             
                        @session ||= Concurrent::Atom.new(
         
     | 
| 
       18 
31 
     | 
    
         
             
                          connector.new(
         
     | 
| 
         @@ -21,18 +34,35 @@ module Legion 
     | 
|
| 
       21 
34 
     | 
    
         
             
                            log_level: :info
         
     | 
| 
       22 
35 
     | 
    
         
             
                          )
         
     | 
| 
       23 
36 
     | 
    
         
             
                        )
         
     | 
| 
       24 
     | 
    
         
            -
                        @channel_thread = Concurrent::ThreadLocalVar.new
         
     | 
| 
      
 37 
     | 
    
         
            +
                        @channel_thread = Concurrent::ThreadLocalVar.new(nil)
         
     | 
| 
      
 38 
     | 
    
         
            +
                        session.start
         
     | 
| 
      
 39 
     | 
    
         
            +
                        session.create_channel.basic_qos(20, true)
         
     | 
| 
       25 
40 
     | 
    
         
             
                      end
         
     | 
| 
       26 
41 
     | 
    
         | 
| 
       27 
     | 
    
         
            -
                      session. 
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
      
 42 
     | 
    
         
            +
                      if session.respond_to? :on_blocked
         
     | 
| 
      
 43 
     | 
    
         
            +
                        session.on_blocked { Legion::Logging.warn('Legion::Transport is being blocked by RabbitMQ!') }
         
     | 
| 
      
 44 
     | 
    
         
            +
                      end
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                      if session.respond_to? :on_unblocked
         
     | 
| 
      
 47 
     | 
    
         
            +
                        session.on_unblocked { Legion::Logging.info('Legion::Transport is no longer being blocked by RabbitMQ') }
         
     | 
| 
      
 48 
     | 
    
         
            +
                      end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                      if session.respond_to? :after_recovery_completed
         
     | 
| 
      
 51 
     | 
    
         
            +
                        session.after_recovery_completed { Legion::Logging.info('Legion::Transport has completed recovery') }
         
     | 
| 
      
 52 
     | 
    
         
            +
                      end
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                      true
         
     | 
| 
       29 
55 
     | 
    
         
             
                    end
         
     | 
| 
       30 
56 
     | 
    
         | 
| 
       31 
     | 
    
         
            -
                    def channel
         
     | 
| 
      
 57 
     | 
    
         
            +
                    def channel # rubocop:disable Metrics/AbcSize
         
     | 
| 
       32 
58 
     | 
    
         
             
                      return @channel_thread.value if !@channel_thread.value.nil? && @channel_thread.value.open?
         
     | 
| 
       33 
59 
     | 
    
         | 
| 
       34 
60 
     | 
    
         
             
                      @channel_thread.value = session.create_channel
         
     | 
| 
       35 
     | 
    
         
            -
                       
     | 
| 
      
 61 
     | 
    
         
            +
                      if Legion::Transport::TYPE == 'march_hare'
         
     | 
| 
      
 62 
     | 
    
         
            +
                        @channel_thread.value.basic_qos(Legion::Settings[:transport][:prefetch])
         
     | 
| 
      
 63 
     | 
    
         
            +
                      else
         
     | 
| 
      
 64 
     | 
    
         
            +
                        @channel_thread.value.prefetch(Legion::Settings[:transport][:prefetch])
         
     | 
| 
      
 65 
     | 
    
         
            +
                      end
         
     | 
| 
       36 
66 
     | 
    
         
             
                      @channel_thread.value
         
     | 
| 
       37 
67 
     | 
    
         
             
                    end
         
     | 
| 
       38 
68 
     | 
    
         | 
| 
         @@ -6,8 +6,14 @@ module Legion 
     | 
|
| 
       6 
6 
     | 
    
         
             
                  def initialize(exchange = exchange_name, options = {})
         
     | 
| 
       7 
7 
     | 
    
         
             
                    @options = options
         
     | 
| 
       8 
8 
     | 
    
         
             
                    @type = options[:type] || default_type
         
     | 
| 
       9 
     | 
    
         
            -
                     
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
      
 9 
     | 
    
         
            +
                    if Legion::Transport::TYPE == 'march_hare'
         
     | 
| 
      
 10 
     | 
    
         
            +
                      super_options = options_builder(default_options, exchange_options, @options)
         
     | 
| 
      
 11 
     | 
    
         
            +
                      super_options[:type] = @type
         
     | 
| 
      
 12 
     | 
    
         
            +
                      super(channel, exchange, **super_options)
         
     | 
| 
      
 13 
     | 
    
         
            +
                    else
         
     | 
| 
      
 14 
     | 
    
         
            +
                      super(channel, @type, exchange, options_builder(default_options, exchange_options, @options))
         
     | 
| 
      
 15 
     | 
    
         
            +
                    end
         
     | 
| 
      
 16 
     | 
    
         
            +
                  rescue Legion::Transport::CONNECTOR::PreconditionFailed, Legion::Transport::CONNECTOR::ChannelAlreadyClosed
         
     | 
| 
       11 
17 
     | 
    
         
             
                    raise unless @retries.nil?
         
     | 
| 
       12 
18 
     | 
    
         | 
| 
       13 
19 
     | 
    
         
             
                    @retries = 1
         
     | 
| 
         @@ -39,7 +45,7 @@ module Legion 
     | 
|
| 
       39 
45 
     | 
    
         
             
                  def delete(options = {})
         
     | 
| 
       40 
46 
     | 
    
         
             
                    super(options)
         
     | 
| 
       41 
47 
     | 
    
         
             
                    true
         
     | 
| 
       42 
     | 
    
         
            -
                  rescue :: 
     | 
| 
      
 48 
     | 
    
         
            +
                  rescue Legion::Transport::CONNECTOR::PreconditionFailed
         
     | 
| 
       43 
49 
     | 
    
         
             
                    false
         
     | 
| 
       44 
50 
     | 
    
         
             
                  end
         
     | 
| 
       45 
51 
     | 
    
         | 
| 
         @@ -11,7 +11,9 @@ module Legion 
     | 
|
| 
       11 
11 
     | 
    
         
             
                  def publish(options = @options) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
         
     | 
| 
       12 
12 
     | 
    
         
             
                    raise unless @valid
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
                     
     | 
| 
      
 14 
     | 
    
         
            +
                    $exchanges = {} if $exchanges.nil?
         
     | 
| 
      
 15 
     | 
    
         
            +
                    $exchanges[exchange.to_s] = exchange.new unless $exchanges.key?(exchange.to_s)
         
     | 
| 
      
 16 
     | 
    
         
            +
                    exchange_dest = $exchanges[exchange.to_s]
         
     | 
| 
       15 
17 
     | 
    
         
             
                    exchange_dest.publish(encode_message,
         
     | 
| 
       16 
18 
     | 
    
         
             
                                          routing_key: routing_key || '',
         
     | 
| 
       17 
19 
     | 
    
         
             
                                          content_type: options[:content_type] || content_type,
         
     | 
| 
         @@ -26,6 +28,10 @@ module Legion 
     | 
|
| 
       26 
28 
     | 
    
         
             
                    @options
         
     | 
| 
       27 
29 
     | 
    
         
             
                  end
         
     | 
| 
       28 
30 
     | 
    
         | 
| 
      
 31 
     | 
    
         
            +
                  def routing_key
         
     | 
| 
      
 32 
     | 
    
         
            +
                    nil
         
     | 
| 
      
 33 
     | 
    
         
            +
                  end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
       29 
35 
     | 
    
         
             
                  def encode_message
         
     | 
| 
       30 
36 
     | 
    
         
             
                    message_payload = message
         
     | 
| 
       31 
37 
     | 
    
         
             
                    message_payload = Legion::JSON.dump(message_payload) unless message_payload.is_a? String
         
     | 
| 
         @@ -16,17 +16,6 @@ module Legion 
     | 
|
| 
       16 
16 
     | 
    
         
             
                      }
         
     | 
| 
       17 
17 
     | 
    
         
             
                    end
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
                    def routing_key # rubocop:disable Metrics/AbcSize
         
     | 
| 
       20 
     | 
    
         
            -
                      if @options[:conditions].is_a?(String) && @options[:conditions].length > 2
         
     | 
| 
       21 
     | 
    
         
            -
                        'task.subtask.conditioner'
         
     | 
| 
       22 
     | 
    
         
            -
                      elsif @options[:transformation].is_a?(String) && @options[:transformation].length > 2
         
     | 
| 
       23 
     | 
    
         
            -
                        'task.subtask.transform'
         
     | 
| 
       24 
     | 
    
         
            -
                      elsif @options[:function_id].is_a? Integer
         
     | 
| 
       25 
     | 
    
         
            -
                        function = Legion::Data::Model::Function[@options[:function_id]]
         
     | 
| 
       26 
     | 
    
         
            -
                        "#{function.runner.extension.values[:exchange]}.#{function.runner.values[:queue]}.#{function.values[:name]}"
         
     | 
| 
       27 
     | 
    
         
            -
                      end
         
     | 
| 
       28 
     | 
    
         
            -
                    end
         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
19 
     | 
    
         
             
                    def validate
         
     | 
| 
       31 
20 
     | 
    
         
             
                      raise TypeError unless @options[:function].is_a? String
         
     | 
| 
       32 
21 
     | 
    
         | 
| 
         @@ -7,7 +7,7 @@ module Legion 
     | 
|
| 
       7 
7 
     | 
    
         
             
                    retries ||= 0
         
     | 
| 
       8 
8 
     | 
    
         
             
                    @options = options
         
     | 
| 
       9 
9 
     | 
    
         
             
                    super(channel, queue, options_builder(default_options, queue_options, options))
         
     | 
| 
       10 
     | 
    
         
            -
                  rescue :: 
     | 
| 
      
 10 
     | 
    
         
            +
                  rescue Legion::Transport::CONNECTOR::PreconditionFailed
         
     | 
| 
       11 
11 
     | 
    
         
             
                    retries.zero? ? retries = 1 : raise
         
     | 
| 
       12 
12 
     | 
    
         
             
                    recreate_queue(channel, queue)
         
     | 
| 
       13 
13 
     | 
    
         
             
                    retry
         
     | 
| 
         @@ -51,7 +51,7 @@ module Legion 
     | 
|
| 
       51 
51 
     | 
    
         
             
                  def delete(options = { if_unused: true, if_empty: true })
         
     | 
| 
       52 
52 
     | 
    
         
             
                    super(options)
         
     | 
| 
       53 
53 
     | 
    
         
             
                    true
         
     | 
| 
       54 
     | 
    
         
            -
                  rescue :: 
     | 
| 
      
 54 
     | 
    
         
            +
                  rescue Legion::Transport::CONNECTOR::PreconditionFailed
         
     | 
| 
       55 
55 
     | 
    
         
             
                    false
         
     | 
| 
       56 
56 
     | 
    
         
             
                  end
         
     | 
| 
       57 
57 
     | 
    
         | 
    
        data/settings/transport.json
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: legion-transport-java
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 1.1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.1.4
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Esity
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2020- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2020-10-14 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     |