Module: Messaging::Message::ClassMethods

Defined in:
lib/messaging/message.rb

Instance Method Summary collapse

Instance Method Details

#default_topic_nameObject



42
43
44
45
46
# File 'lib/messaging/message.rb', line 42

def default_topic_name
  return superclass.topic if superclass.respond_to?(:topic)

  message_name.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.



37
38
39
40
# File 'lib/messaging/message.rb', line 37

def key_attribute(attribute = nil)
  @key_attribute = attribute if attribute
  @key_attribute
end

#message_nameObject



58
59
60
# File 'lib/messaging/message.rb', line 58

def message_name
  name.underscore
end

#message_typeObject



62
63
64
# File 'lib/messaging/message.rb', line 62

def message_type
  to_s
end

#publish(attributes) ⇒ Message

Shorcut for creating a new message and publishing it

Parameters:

  • attributes (Hash)

    The attributes of the message

Options Hash (attributes):

  • :expected_version (:any, Integer)

    Concurrency control

Returns:

  • (Message)

    the message just published

Raises:



54
55
56
# File 'lib/messaging/message.rb', line 54

def publish(attributes)
  new(attributes).publish
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.



31
32
33
# File 'lib/messaging/message.rb', line 31

def topic(topic_name = nil)
  @topic ||= topic_name&.to_s || default_topic_name
end