Sha256: 8e613dff64498daf123665fac9666e84e0eec13c91006308d71fac49e4416f60
Contents?: true
Size: 1.01 KB
Versions: 7
Compression:
Stored size: 1.01 KB
Contents
require_relative 'socket' # Syntactic sugar for 0MQ, because Ruby shouldn't feel like C. module EZMQ # Publish socket that broadcasts messages with an optional topic. class Publisher < EZMQ::Socket # Creates a new Publisher socket. # # @param [Hash] options optional parameters. # @see EZMQ::Socket EZMQ::Socket for optional parameters. # # @return [Publisher] a new instance of Publisher. # def initialize(**options) super :bind, ZMQ::PUB, options end # 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. # def send(message = '', topic: '', **options) message = "#{ topic } #{ (options[:encode] || @encode).call message }" @socket.send_string message end end end
Version data entries
7 entries across 7 versions & 1 rubygems