module Nagare::Publisher
Publisher is a mixin that allows classes to easily publish events to a redis stream.
Public Class Methods
included(base)
click to toggle source
# File lib/nagare/publisher.rb, line 61 def included(base) base.extend ClassMethods end
Public Instance Methods
publish(event_name, data, stream = nil)
click to toggle source
Publishes a message to the configured stream for this class.
The message is always in the format { event_name: data } hence the 2 separate parameters for this method.
Event name will be used on the listener side to determine which method of the listener to invoke.
@param event_name [String] event_name name of the event. If it matches a method on a listener on this stream, that method will be invoked upon receiving the message
@param data [Object] an object representing the data @param stream [String] name of the stream to publish to
# File lib/nagare/publisher.rb, line 43 def publish(event_name, data, stream = nil) stream ||= stream_name Nagare.logger.info "Publishing to stream #{stream}: "\ "#{event_name}: #{data}" Nagare::RedisStreams.publish(stream, event_name, data.to_json) end
stream_name()
click to toggle source
Returns the name of the configured or default stream for this publisher class.
@return [String] stream name
# File lib/nagare/publisher.rb, line 55 def stream_name own_class = self.class own_class.redis_publisher_stream || own_class.name.downcase end