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

#initialize(**options) ⇒ Publisher

Creates a new Publisher socket.



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

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

Instance Method Details

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

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

Options Hash (**options):

  • encode (lambda)

    how to encode the message.



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

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