Class: Rabbit::Publishing::Message
- Inherits:
-
Object
- Object
- Rabbit::Publishing::Message
- Includes:
- Tainbox
- Defined in:
- lib/rabbit/publishing/message.rb
Instance Method Summary collapse
- #basic_publish_args ⇒ Object
- #exchange_name=(names) ⇒ Object
- #headers ⇒ Object
- #real_exchange_name ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object
Instance Method Details
#basic_publish_args ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rabbit/publishing/message.rb', line 32 def basic_publish_args Rabbit.config.validate! raise "Routing key not specified" unless routing_key raise "Event name not specified" unless event = { mandatory: confirm_select?, persistent: true, type: event, content_type: "application/json", app_id: Rabbit.config.app_name, headers: headers, message_id: , } [JSON.dump(data), real_exchange_name, routing_key.to_s, ] end |
#exchange_name=(names) ⇒ Object
51 52 53 |
# File 'lib/rabbit/publishing/message.rb', line 51 def exchange_name=(names) super(Array(names).map(&:to_s)) end |
#headers ⇒ Object
59 60 61 |
# File 'lib/rabbit/publishing/message.rb', line 59 def headers super || {} end |
#real_exchange_name ⇒ Object
55 56 57 |
# File 'lib/rabbit/publishing/message.rb', line 55 def real_exchange_name [Rabbit.config.group_id, Rabbit.config.project_id, *exchange_name].join(".") end |
#to_hash ⇒ Object
21 22 23 24 25 26 |
# File 'lib/rabbit/publishing/message.rb', line 21 def to_hash { **attributes, data: JSON.parse(data.to_json), } end |
#to_s ⇒ Object
28 29 30 |
# File 'lib/rabbit/publishing/message.rb', line 28 def to_s "#{real_exchange_name} -> #{routing_key} -> #{event}" end |