Module: RMessage::Publisher

Defined in:
lib/rmessage/publisher.rb

Overview

A module to provide publishing functions to an Object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#channelString, ... (readonly)

Returns the channel to publish to.

Returns:

  • (String, Integer, Symbol)

    the channel to publish to



7
8
9
# File 'lib/rmessage/publisher.rb', line 7

def channel
  @channel
end

Instance Method Details

#publish(message, channel: @channel, connection: nil, connection_index: 0) ⇒ Object

Publishes a message to the specified redis channel.

Parameters:

  • message (RMessage::Message)

    the message

  • channel (String, Integer, Symbol) (defaults to: @channel)

    the channel

  • connection_index (Integer) (defaults to: 0)

    the index of the connection to Redis within the CONNECTION_POOL



13
14
15
16
# File 'lib/rmessage/publisher.rb', line 13

def publish(message, channel: @channel, connection: nil, connection_index: 0)
  redis_connection = connection || RMessage::CONNECTION_POOL[connection_index]
  redis_connection.publish(channel, message.build)
end