Sha256: 4a15a8706127441573f542919d728140a52571df5698d88a4721d44ff19b3976

Contents?: true

Size: 1.53 KB

Versions: 3

Compression:

Stored size: 1.53 KB

Contents

require_relative "base"

module Moleculer
  module Packets
    ##
    # Represents a REQ packet
    class Req < Base
      attr_reader :action,
                  :params,
                  :meta,
                  :timeout,
                  :level,
                  :parent_id,
                  :request_id,
                  :stream,
                  :metrics,
                  :stream,
                  :id,
                  :node

      def initialize(data)
        super(data)

        @id         = HashUtil.fetch(data, :id)
        @action     = HashUtil.fetch(data, :action)
        @params     = HashUtil.fetch(data, :params)
        @meta       = HashUtil.fetch(data, :meta)
        @timeout    = HashUtil.fetch(data, :timeout, nil)
        @level      = HashUtil.fetch(data, :level, 1)
        @metrics    = HashUtil.fetch(data, :metrics, false)
        @parent_id  = HashUtil.fetch(data, :parent_id, nil)
        @request_id = HashUtil.fetch(data, :request_id, nil)
        @stream     = false
        @node       = HashUtil.fetch(data, :node, nil)
      end

      def as_json # rubocop:disable Metrics/MethodLength
        super.merge(
          id:         @id,
          action:     @action,
          params:     @params,
          meta:       @meta,
          timeout:    @timeout,
          level:      @level,
          metrics:    @metrics,
          parent_id:  @parent_id,
          request_id: @request_id,
          stream:     @stream,
        )
      end

      def topic
        "#{super}.#{@node.id}"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
moleculer-0.2.0 lib/moleculer/packets/req.rb
moleculer-0.1.1 lib/moleculer/packets/req.rb
moleculer-0.1.0 lib/moleculer/packets/req.rb