Class: EZMQ::Publisher

Inherits:
Socket
  • Object
show all
Defined in:
lib/ezmq/publish.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

#connect, #listen, #receive

Constructor Details

- (Publisher) initialize(mode = :bind, **options)

Creates a new Publisher socket.

Parameters:

  • mode (:bind, :connect) (defaults to: :bind)

    (:bind) a mode for the socket.

  • options (Hash)

    optional parameters.

See Also:



15
16
17
# File 'lib/ezmq/publish.rb', line 15

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

Instance Method Details

- (Fixnum) send(message = '', topic: '', **options)

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.

  • options (Hash)

    optional parameters.

Options Hash (**options):

  • encode (lambda)

    how to encode the message.

Returns:

  • (Fixnum)

    the size of the message.



28
29
30
31
# File 'lib/ezmq/publish.rb', line 28

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