Sha256: 6b35fdaddba7eb45cf222c0ce271d7953861b0834bf4838cfbc932ac4e92e29d

Contents?: true

Size: 1.29 KB

Versions: 24

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true
module Msgr
  class Message
    attr_reader :delivery_info, :metadata, :payload, :route

    def initialize(connection, delivery_info, metadata, payload, route)
      @connection    = connection
      @delivery_info = delivery_info
      @metadata      = metadata
      @payload       = payload
      @route         = route

      # rubocop:disable Style/GuardClause
      if content_type == 'application/json'
        @payload = MultiJson.load(payload)
        @payload.symbolize_keys! if @payload.respond_to? :symbolize_keys!
      end
    end

    def content_type
      @metadata.content_type
    end

    # Check if message is already acknowledged.
    #
    # @return [Boolean] True if message is acknowledged, false otherwise.
    # @api public
    #
    def acked?
      @acked ? true : false
    end

    # Send message acknowledge to broker unless message is
    # already acknowledged.
    #
    # @api public
    #
    def ack
      return if acked?

      @acked = true
      @connection.ack delivery_info.delivery_tag
    end

    # Send negative message acknowledge to broker unless
    # message is  already acknowledged.
    #
    # @api public
    #
    def nack
      return if acked?

      @acked = true
      @connection.nack delivery_info.delivery_tag
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
msgr-0.15.2.1.b157 lib/msgr/message.rb
msgr-0.15.2.1.b156 lib/msgr/message.rb
msgr-0.15.2.1.b155 lib/msgr/message.rb
msgr-0.15.2.1.b154 lib/msgr/message.rb
msgr-0.15.2.1.b152 lib/msgr/message.rb
msgr-0.15.1.1.b151 lib/msgr/message.rb
msgr-0.15.2 lib/msgr/message.rb
msgr-0.15.1.1.b150 lib/msgr/message.rb
msgr-0.15.1.1.b146 lib/msgr/message.rb
msgr-0.15.1.1.b145 lib/msgr/message.rb
msgr-0.15.1.1.b144 lib/msgr/message.rb
msgr-0.15.1.1.b143 lib/msgr/message.rb
msgr-0.15.1.1.b141 lib/msgr/message.rb
msgr-0.15.0.1.b140 lib/msgr/message.rb
msgr-0.15.1 lib/msgr/message.rb
msgr-0.15.0.1.b139 lib/msgr/message.rb
msgr-0.15.0.1.b136 lib/msgr/message.rb
msgr-0.15.0.1.b135 lib/msgr/message.rb
msgr-0.15.0.1.b134 lib/msgr/message.rb
msgr-0.15.0.1.b131 lib/msgr/message.rb