Sha256: fb5c6d1159a9622f402ced478b1f1a5325e80119878510188b77733800344ad3
Contents?: true
Size: 1.42 KB
Versions: 2
Compression:
Stored size: 1.42 KB
Contents
# frozen_string_literal: true require "tainbox" module Rabbit::Publishing class Message include Tainbox attribute :routing_key, String attribute :event, String attribute :data, default: {} attribute :exchange_name, default: [] attribute :confirm_select, default: true attribute :realtime, default: false attribute :headers attribute :message_id alias_method :confirm_select?, :confirm_select alias_method :realtime?, :realtime def to_hash { **attributes, data: JSON.parse(data.to_json), } end def to_s "#{real_exchange_name} -> #{routing_key} -> #{event}" end def basic_publish_args Rabbit.config.validate! raise "Routing key not specified" unless routing_key raise "Event name not specified" unless event options = { mandatory: confirm_select?, persistent: true, type: event, content_type: "application/json", app_id: Rabbit.config.app_name, headers: headers, message_id: message_id, } [JSON.dump(data), real_exchange_name, routing_key.to_s, options] end def exchange_name=(names) super(Array(names).map(&:to_s)) end def real_exchange_name [Rabbit.config.group_id, Rabbit.config.project_id, *exchange_name].join(".") end private def headers super || {} end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rabbit_messaging-0.9.0 | lib/rabbit/publishing/message.rb |
rabbit_messaging-0.8.1 | lib/rabbit/publishing/message.rb |