Class: Rabbit::Publishing::Message

Inherits:
Object
  • Object
show all
Includes:
Tainbox
Defined in:
lib/rabbit/publishing/message.rb

Instance Method Summary collapse

Instance Method Details

#basic_publish_argsObject



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

  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

#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

#headersObject



59
60
61
# File 'lib/rabbit/publishing/message.rb', line 59

def headers
  super || {}
end

#real_exchange_nameObject



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_hashObject



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_sObject



28
29
30
# File 'lib/rabbit/publishing/message.rb', line 28

def to_s
  "#{real_exchange_name} -> #{routing_key} -> #{event}"
end