Class: OMQ::SERVER

Inherits:
Socket
  • Object
show all
Includes:
Readable, SingleFrame, Writable
Defined in:
lib/omq/client_server.rb

Overview

Asynchronous server socket for the CLIENT/SERVER pattern (ZeroMQ RFC 41).

Assigns a 4-byte routing ID to each connected CLIENT and supports directed replies via #send_to.

Instance Method Summary collapse

Constructor Details

#initialize(endpoints = nil, linger: Float::INFINITY, backend: nil) ⇒ SERVER

Creates a new SERVER socket.

Parameters:

  • endpoints (String, Array<String>, nil) (defaults to: nil)

    endpoint(s) to bind to

  • linger (Numeric) (defaults to: Float::INFINITY)

    linger period in seconds (Float::INFINITY = wait forever, 0 = drop)

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

    optional transport backend



39
40
41
42
43
# File 'lib/omq/client_server.rb', line 39

def initialize(endpoints = nil, linger: Float::INFINITY, backend: nil)
  init_engine(:SERVER, backend: backend)
  @options.linger = linger
  attach_endpoints(endpoints, default: :bind)
end

Instance Method Details

#send_to(routing_id, message) ⇒ self

Sends a message to a specific peer by routing ID.

Parameters:

  • routing_id (String)

    4-byte routing ID

  • message (String)

    message body

Returns:

  • (self)


52
53
54
55
56
# File 'lib/omq/client_server.rb', line 52

def send_to(routing_id, message)
  parts = [routing_id.b.freeze, message.b.freeze]
  Reactor.run(timeout: @options.write_timeout) { @engine.enqueue_send(parts) }
  self
end