class EZMQ::Publisher

Publish socket that broadcasts messages with an optional topic.

Public Class Methods

new(mode = :bind, **options) click to toggle source

Creates a new Publisher socket.

@param [:bind, :connect] mode (:bind) a mode for the socket. @param [Hash] options optional parameters. @see EZMQ::Socket EZMQ::Socket for optional parameters.

@return [Publisher] a new instance of Publisher.

Calls superclass method EZMQ::Socket::new
# File lib/ezmq/publish.rb, line 15
def initialize(mode = :bind, **options)
  super mode, ZMQ::PUB, options
end

Public Instance Methods

send(message, topic: '', **options) click to toggle source

Sends a message on the socket, with an optional topic.

@param [String] message the message to send. @param [String] topic an optional topic for the message. @param [Hash] options optional parameters. @option options [lambda] encode how to encode the message.

@return [Fixnum] the size of the message.

# File lib/ezmq/publish.rb, line 28
def send(message, topic: '', **options)
  message = "#{ topic } #{ (options[:encode] || @encode).call message }"
  @socket.send_string message
end