amqp-client 1.2.0 → 2.0.0
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/amqp/client/channel.rb +115 -46
- data/lib/amqp/client/configuration.rb +66 -0
- data/lib/amqp/client/connection.rb +35 -18
- data/lib/amqp/client/consumer.rb +47 -0
- data/lib/amqp/client/errors.rb +84 -9
- data/lib/amqp/client/exchange.rb +30 -28
- data/lib/amqp/client/frame_bytes.rb +3 -4
- data/lib/amqp/client/message.rb +66 -1
- data/lib/amqp/client/message_codec_registry.rb +106 -0
- data/lib/amqp/client/message_codecs.rb +43 -0
- data/lib/amqp/client/properties.rb +16 -15
- data/lib/amqp/client/queue.rb +52 -14
- data/lib/amqp/client/rpc_client.rb +56 -0
- data/lib/amqp/client/table.rb +2 -2
- data/lib/amqp/client/version.rb +1 -1
- data/lib/amqp/client.rb +369 -61
- metadata +8 -18
- data/.github/workflows/codeql-analysis.yml +0 -41
- data/.github/workflows/docs.yml +0 -28
- data/.github/workflows/main.yml +0 -140
- data/.github/workflows/release.yml +0 -26
- data/.gitignore +0 -9
- data/.rubocop.yml +0 -30
- data/.rubocop_todo.yml +0 -65
- data/.yardopts +0 -1
- data/CHANGELOG.md +0 -109
- data/CODEOWNERS +0 -1
- data/Gemfile +0 -18
- data/README.md +0 -193
- data/Rakefile +0 -180
- data/amqp-client.gemspec +0 -29
- data/bin/console +0 -15
- data/bin/setup +0 -8
| @@ -0,0 +1,56 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module AMQP
         | 
| 4 | 
            +
              class Client
         | 
| 5 | 
            +
                # Reusable RPC client, when RPC performance is important
         | 
| 6 | 
            +
                class RPCClient
         | 
| 7 | 
            +
                  # @param channel [AMQP::Client::Connection::Channel] the channel to use for the RPC calls
         | 
| 8 | 
            +
                  def initialize(channel)
         | 
| 9 | 
            +
                    @ch = channel
         | 
| 10 | 
            +
                    @correlation_id = 0
         | 
| 11 | 
            +
                    @lock = Mutex.new
         | 
| 12 | 
            +
                    @messages = ::Queue.new
         | 
| 13 | 
            +
                  end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  # Start listening for responses from the RPC calls
         | 
| 16 | 
            +
                  # @return [self]
         | 
| 17 | 
            +
                  def start
         | 
| 18 | 
            +
                    @ch.basic_consume("amq.rabbitmq.reply-to") do |msg|
         | 
| 19 | 
            +
                      @messages.push msg
         | 
| 20 | 
            +
                    end
         | 
| 21 | 
            +
                    self
         | 
| 22 | 
            +
                  end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  # Do a RPC call, sends a messages, waits for a response
         | 
| 25 | 
            +
                  # @param method [String, Symbol] name of the method to call (i.e. queue name on the server side)
         | 
| 26 | 
            +
                  # @param arguments [String] arguments/body to the call
         | 
| 27 | 
            +
                  # @param timeout [Numeric, nil] Number of seconds to wait for a response
         | 
| 28 | 
            +
                  # @option (see Client#publish)
         | 
| 29 | 
            +
                  # @raise [Timeout::Error] if no response is received within the timeout period
         | 
| 30 | 
            +
                  # @return [String] Returns the result from the call
         | 
| 31 | 
            +
                  def call(method, arguments, timeout: nil, **properties)
         | 
| 32 | 
            +
                    correlation_id = @lock.synchronize { @correlation_id += 1 }.to_s(36)
         | 
| 33 | 
            +
                    @ch.basic_publish(arguments, exchange: "", routing_key: method.to_s,
         | 
| 34 | 
            +
                                                 reply_to: "amq.rabbitmq.reply-to", correlation_id:, **properties)
         | 
| 35 | 
            +
                    Timeout.timeout(timeout) do # Timeout the whole loop if we never find the right correlation_id
         | 
| 36 | 
            +
                      loop do
         | 
| 37 | 
            +
                        msg = @messages.pop(timeout:) # Timeout individual pop to avoid blocking forever
         | 
| 38 | 
            +
                        raise Timeout::Error if msg.nil? && timeout
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                        return msg.body if msg.properties.correlation_id == correlation_id
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                        @messages.push msg
         | 
| 43 | 
            +
                      end
         | 
| 44 | 
            +
                    end
         | 
| 45 | 
            +
                  rescue Timeout::Error
         | 
| 46 | 
            +
                    raise Timeout::Error, "No response received in #{timeout} seconds"
         | 
| 47 | 
            +
                  end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                  # Closes the channel used by the RPCClient
         | 
| 50 | 
            +
                  def close
         | 
| 51 | 
            +
                    @ch.close
         | 
| 52 | 
            +
                    @messages.close
         | 
| 53 | 
            +
                  end
         | 
| 54 | 
            +
                end
         | 
| 55 | 
            +
              end
         | 
| 56 | 
            +
            end
         | 
    
        data/lib/amqp/client/table.rb
    CHANGED
    
    | @@ -9,7 +9,7 @@ module AMQP | |
| 9 9 | 
             
                  # @param hash [Hash]
         | 
| 10 10 | 
             
                  # @return [String] Byte array
         | 
| 11 11 | 
             
                  def self.encode(hash)
         | 
| 12 | 
            -
                    return "" if hash.empty?
         | 
| 12 | 
            +
                    return "" if hash.nil? || hash.empty?
         | 
| 13 13 |  | 
| 14 14 | 
             
                    arr = []
         | 
| 15 15 | 
             
                    fmt = String.new
         | 
| @@ -136,7 +136,7 @@ module AMQP | |
| 136 136 | 
             
                      scale = bytes.getbyte(pos)
         | 
| 137 137 | 
             
                      pos += 1
         | 
| 138 138 | 
             
                      value = bytes.byteslice(pos, 4).unpack1("L>")
         | 
| 139 | 
            -
                      d = value / 10**scale
         | 
| 139 | 
            +
                      d = value / (10**scale)
         | 
| 140 140 | 
             
                      [5, d]
         | 
| 141 141 | 
             
                    when "x"
         | 
| 142 142 | 
             
                      len = bytes.byteslice(pos, 4).unpack1("L>")
         |