Sha256: e84da5bd6a7a3282fa16dcfeffc05f5c248b10731803fa5f088450ba2bdde3a8

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

module ManageIQ
  module Messaging
    module Common
      private

      def encode_body(headers, body)
        return body if body.kind_of?(String)
        headers[:encoding] = encoding
        case encoding
        when "json"
          JSON.generate(body)
        when "yaml"
          body.to_yaml
        else
          raise "unknown message encoding: #{encoding}"
        end
      end

      def decode_body(headers, raw_body)
        return raw_body unless headers.kind_of?(Hash)
        case headers["encoding"]
        when "json"
          JSON.parse(raw_body)
        when "yaml"
          YAML.safe_load(raw_body)
        else
          raw_body
        end
      rescue => e # JSON or YAML parsing error
        logger.error("Error decoding message body: #{e.message}")
        logger.error(e.backtrace.join("\n"))
        raw_body
      end

      def payload_log(payload)
        payload.to_s[0..100]
      end

      def auto_ack?(options)
        options.key?(:auto_ack) ? options[:auto_ack] : true
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
manageiq-messaging-0.1.7 lib/manageiq/messaging/common.rb
manageiq-messaging-0.1.6 lib/manageiq/messaging/common.rb