Class: Warren::Message::Short
- Inherits:
-
Object
- Object
- Warren::Message::Short
- Defined in:
- lib/warren/message/short.rb
Overview
Light-weight interim message which can be expanded to a full payload later.
Instance Attribute Summary collapse
-
#record ⇒ Object
readonly
Returns the value of attribute record.
Instance Method Summary collapse
-
#headers ⇒ {}
For compatibility.
-
#initialize(record = nil, class_name: nil, id: nil) ⇒ Short
constructor
Create a ‘short’ message, where the payload is just the class name and id.
-
#payload ⇒ String
The contents of the message, a string in the form: [“<ClassName>”,<id>].
-
#queue(warren) ⇒ Object
Queues the message for broadcast at the end of the transaction.
-
#routing_key ⇒ String
The routing key for the message.
Constructor Details
#initialize(record = nil, class_name: nil, id: nil) ⇒ Short
Create a ‘short’ message, where the payload is just the class name and id. Designed for when you wish to use a delayed broadcast.
21 22 23 24 25 26 27 28 29 |
# File 'lib/warren/message/short.rb', line 21 def initialize(record = nil, class_name: nil, id: nil) if record @class_name = record.class.name @id = record.id else @class_name = class_name @id = id end end |
Instance Attribute Details
#record ⇒ Object (readonly)
Returns the value of attribute record.
13 14 15 |
# File 'lib/warren/message/short.rb', line 13 def record @record end |
Instance Method Details
#headers ⇒ {}
For compatibility. Returns an empty hash.
62 63 64 |
# File 'lib/warren/message/short.rb', line 62 def headers {} end |
#payload ⇒ String
The contents of the message, a string in the form:
- “<ClassName>”,<id>
54 55 56 |
# File 'lib/warren/message/short.rb', line 54 def payload [@class_name, @id].to_json end |
#queue(warren) ⇒ Object
Queues the message for broadcast at the end of the transaction. Actually want to make this the default behaviour, but only realised the need when doing some last minute integration tests. Will revisit this in the next version. (Or possibly post code review depending)
34 35 36 37 38 |
# File 'lib/warren/message/short.rb', line 34 def queue(warren) after_commit { warren << self } rescue NoMethodError raise StandardError, '#queue depends on the after_commit_everywhere gem. Please add this to your gemfile' end |
#routing_key ⇒ String
The routing key for the message.
44 45 46 |
# File 'lib/warren/message/short.rb', line 44 def routing_key "queue_broadcast.#{@class_name.underscore}.#{@id}" end |