Class: CZTop::Socket::ROUTER

Inherits:
CZTop::Socket show all
Includes:
Readable, Writable
Defined in:
lib/cztop/socket/router.rb

Overview

Router socket for the ZeroMQ Request-Reply Pattern.

Constant Summary

Constants included from FdWait

FdWait::FD_TIMEOUT, FdWait::JIFFY

Constants inherited from CZTop::Socket

TypeNames

Constants included from CZMQ::FFI

CZMQ::FFI::CZMQ_VERSION, CZMQ::FFI::ZFRAME_DONTWAIT, CZMQ::FFI::ZFRAME_MORE, CZMQ::FFI::ZMONITOR_FN, CZMQ::FFI::ZMQ_VERSION

Constants included from ZsockOptions

ZsockOptions::POLLIN, ZsockOptions::POLLOUT

Instance Attribute Summary

Attributes inherited from CZTop::Socket

#last_tcp_port

Attributes included from HasFFIDelegate

#ffi_delegate

Instance Method Summary collapse

Methods included from Writable

#send, #wait_writable

Methods included from FdWait

#wait_for_fd_signal, #wait_for_socket_state

Methods included from Readable

#receive, #wait_readable

Methods inherited from CZTop::Socket

bind, #bind, #close, #connect, connect, #disconnect, #inspect, #last_endpoint, #set_unbounded, #unbind

Methods included from HasFFIDelegate::ClassMethods

#ffi_delegate, #from_ffi_delegate

Methods included from ZsockOptions

#conflate=, #conflate?, #fd, #heartbeat_ivl, #heartbeat_ivl=, #heartbeat_timeout, #heartbeat_timeout=, #heartbeat_ttl, #heartbeat_ttl=, #identity, #identity=, #immediate=, #immediate?, #ipv6=, #ipv6?, #linger, #linger=, #max_msg_size, #max_msg_size=, #rcvhwm, #rcvhwm=, #readable?, #reconnect_ivl, #reconnect_ivl=, #reconnect_ivl_max, #reconnect_ivl_max=, #recv_timeout, #recv_timeout=, #router_mandatory=, #router_mandatory?, #send_timeout, #send_timeout=, #sndhwm, #sndhwm=, #tcp_keepalive, #tcp_keepalive=, #tcp_keepalive_cnt, #tcp_keepalive_cnt=, #tcp_keepalive_idle, #tcp_keepalive_idle=, #tcp_keepalive_intvl, #tcp_keepalive_intvl=, #to_io, #tos, #tos=, #writable?

Methods included from HasFFIDelegate

#attach_ffi_delegate, #from_ffi_delegate, raise_zmq_err, #to_ptr

Constructor Details

#initialize(endpoints = nil, curve: nil, linger: 0) ⇒ ROUTER

Returns a new instance of ROUTER.

Parameters:

  • endpoints (String) (defaults to: nil)

    endpoints to bind to

  • curve (Hash, nil) (defaults to: nil)

    CURVE encryption options

  • linger (Integer) (defaults to: 0)

    linger period in milliseconds (default: 0)



18
19
20
21
22
23
24
25
# File 'lib/cztop/socket/router.rb', line 18

def initialize(endpoints = nil, curve: nil, linger: 0)
  super

  attach_ffi_delegate(Zsock.new(Types::ROUTER))
  self.linger = linger
  _apply_curve(curve)
  _attach(endpoints, default: :bind)
end

Instance Method Details

#send_to(receiver, message) ⇒ Object

Send a message to a specific receiver. This is a shorthand for when you send a message to a specific receiver with no hops in between.

Parameters:

  • receiver (String)

    receiving peer's socket identity

  • message (String, Array<String>)

    the message to send



33
34
35
36
# File 'lib/cztop/socket/router.rb', line 33

def send_to(receiver, message)
  parts = message.is_a?(Array) ? message : [message]
  send([receiver, '', *parts])
end