Class: OMQ::ROUTER

Inherits:
Socket show all
Includes:
Readable, Writable
Defined in:
lib/omq/router_dealer.rb

Overview

ROUTER socket.

Constant Summary

Constants included from Writable

Writable::EMPTY_PART

Instance Attribute Summary

Attributes inherited from Socket

#engine, #last_tcp_port, #options

Instance Method Summary collapse

Methods included from Writable

#<<, #send, #wait_writable

Methods included from QueueWritable

#enqueue

Methods included from Readable

#receive, #wait_readable

Methods included from QueueReadable

#dequeue, #each, #wait

Methods inherited from Socket

#all_peers_gone, #attach_endpoints, bind, #bind, #close, #close_read, connect, #connect, #connection_count, #disconnect, #init_engine, #inspect, #last_endpoint, #monitor, #peer_connected, #reconnect_enabled=, #set_unbounded, #stop, #subscriber_joined, #unbind

Constructor Details

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

Returns a new instance of ROUTER.

Parameters:

  • endpoints (String, nil) (defaults to: nil)

    endpoint to bind/connect

  • linger (Integer) (defaults to: 0)

    linger period in seconds

  • backend (Symbol, nil) (defaults to: nil)

    :ruby (default) or :ffi



31
32
33
34
# File 'lib/omq/router_dealer.rb', line 31

def initialize(endpoints = nil, linger: 0, backend: nil)
  init_engine(:ROUTER, linger: linger, backend: backend)
  attach_endpoints(endpoints, default: :bind)
end

Instance Method Details

#send_to(receiver, message) ⇒ self

Sends a message to a specific peer by identity.

Parameters:

  • receiver (String)

    peer identity

  • message (String, Array<String>)

Returns:

  • (self)


43
44
45
46
# File 'lib/omq/router_dealer.rb', line 43

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