Module: Messaging::Message::ClassMethods
- Defined in:
- lib/messaging/message.rb
Instance Method Summary collapse
- #default_topic_name ⇒ Object
-
#key_attribute(attribute = nil) ⇒ Object
The attribute which value should be used as the key of the message.
- #message_name ⇒ Object
- #message_type ⇒ Object
-
#publish(attributes) ⇒ Message
Shorcut for creating a new message and publishing it.
-
#stream_name(name = nil) ⇒ Object
The stream that the message will be stored in when published.
-
#topic(topic_name = nil) ⇒ Object
By default the topic is the same as the name of the message.
Instance Method Details
#default_topic_name ⇒ Object
68 69 70 71 72 |
# File 'lib/messaging/message.rb', line 68 def default_topic_name return superclass.topic if superclass.respond_to?(:topic) .gsub('/', '-') end |
#key_attribute(attribute = nil) ⇒ Object
The attribute which value should be used as the key of the message. Must specify an attribute if ordering is important.
63 64 65 66 |
# File 'lib/messaging/message.rb', line 63 def key_attribute(attribute = nil) @key_attribute = attribute if attribute @key_attribute end |
#message_name ⇒ Object
84 85 86 |
# File 'lib/messaging/message.rb', line 84 def name.underscore end |
#message_type ⇒ Object
88 89 90 |
# File 'lib/messaging/message.rb', line 88 def to_s end |
#publish(attributes) ⇒ Message
Shorcut for creating a new message and publishing it
80 81 82 |
# File 'lib/messaging/message.rb', line 80 def publish(attributes) new(attributes).publish end |
#stream_name(name = nil) ⇒ Object
The stream that the message will be stored in when published.
Stream names consists of the stream category and the stream id separated by a $. For instance “customer$123” where “customer” is the category and “123” is the id.
When no stream name is given the message will not be persisted in the message store.
49 50 51 52 |
# File 'lib/messaging/message.rb', line 49 def stream_name(name = nil) return @stream_name unless name @stream_name = name end |
#topic(topic_name = nil) ⇒ Object
By default the topic is the same as the name of the message. We change the / that would be set for a namespaced message as “/” isn’t valid in a topic To change the topic for a message just set it to whatever you want in your class definition.
57 58 59 |
# File 'lib/messaging/message.rb', line 57 def topic(topic_name = nil) @topic ||= topic_name&.to_s || default_topic_name end |