Class: EZMQ::Publisher

Inherits:
Socket
  • Object
show all
Defined in:
lib/ezmq.rb

Overview

Publish socket that broadcasts messages with an optional topic.

Instance Attribute Summary

Attributes inherited from Socket

#context, #decode, #encode, #socket

Instance Method Summary (collapse)

Methods inherited from Socket

#bind, #connect, #receive

Constructor Details

- (Publisher) initialize(**options)

Creates a new Publisher socket.

Parameters:

  • options (Hash)

    optional parameters

See Also:



153
154
155
# File 'lib/ezmq.rb', line 153

def initialize(**options)
  super :bind, ZMQ::PUB, options
end

Instance Method Details

- (Fixnum) send(message = '', topic: '', encode: @encode)

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

Parameters:

  • message (String) (defaults to: '')

    the message to send.

  • topic (String)

    an optional topic for the message.

  • encode (lambda)

    how to encode the message.

Returns:

  • (Fixnum)

    the size of the message.



165
166
167
# File 'lib/ezmq.rb', line 165

def send(message = '', topic: '', encode: @encode)
  @socket.send_string "#{ topic } #{ encode.call message }"
end