Class: Bifrost::Message
Overview
A message is a letter that we send to a topic. It must contain a subject and body The receiver can process both fields on receipt of the message
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#message_id ⇒ Object
(also: #resource_id, #id)
readonly
Returns the value of attribute message_id.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(body, meta = {}) ⇒ Message
constructor
A message must have a valid subject and body.
-
#publish(topic) ⇒ Object
A message can be posted to a particular topic.
-
#publish!(topic) ⇒ Object
A message can be posted to a particular topic, if the message is succssfully delivered we return a unique identifier for the message.
-
#to_s ⇒ Object
A message when serialised to a string just renders the messag identifier.
Constructor Details
#initialize(body, meta = {}) ⇒ Message
A message must have a valid subject and body. The service bus is initialised in the Entity class
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/bifrost/message.rb', line 15 def initialize(body, = {}) @meta = if body.is_a?(Azure::ServiceBus::BrokeredMessage) merge(body) else @body ||= body @status ||= :undelivered end super() end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
8 9 10 |
# File 'lib/bifrost/message.rb', line 8 def body @body end |
#message_id ⇒ Object (readonly) Also known as: resource_id, id
Returns the value of attribute message_id.
8 9 10 |
# File 'lib/bifrost/message.rb', line 8 def @message_id end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
8 9 10 |
# File 'lib/bifrost/message.rb', line 8 def @meta end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
8 9 10 |
# File 'lib/bifrost/message.rb', line 8 def status @status end |
Instance Method Details
#publish(topic) ⇒ Object
A message can be posted to a particular topic
27 28 29 30 31 32 33 34 |
# File 'lib/bifrost/message.rb', line 27 def publish(topic) if topic.exists? (topic, ) true else false end end |
#publish!(topic) ⇒ Object
A message can be posted to a particular topic, if the message is succssfully delivered we return a unique identifier for the message
38 39 40 41 42 43 44 45 |
# File 'lib/bifrost/message.rb', line 38 def publish!(topic) if topic.exists? (topic, ) else raise Bifrost::Exceptions::MessageDeliveryError, "Could not post message to #{topic}" end end |
#to_s ⇒ Object
A message when serialised to a string just renders the messag identifier
48 49 50 |
# File 'lib/bifrost/message.rb', line 48 def to_s id end |