Module: OMQ::QoS::LifecycleExt

Defined in:
lib/omq/qos/lifecycle_ext.rb

Overview

Prepended onto OMQ::Engine::ConnectionLifecycle so that the Protocol::ZMTP::Connection is built with this socket's QoS metadata, and the peer's QoS properties are validated after the handshake.

Instance Method Summary collapse

Instance Method Details

#handshake!(io, as_server:) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/omq/qos/lifecycle_ext.rb', line 11

def handshake!(io, as_server:)
  transition!(:handshaking)
  conn_class =
    if @transport.respond_to?(:connection_class)
      @transport.connection_class
    else
      Protocol::ZMTP::Connection
    end
  conn = conn_class.new io,
    socket_type:      @engine.socket_type.to_s,
    identity:         @engine.options.identity,
    as_server:        as_server,
    mechanism:        @engine.options.mechanism&.dup,
    max_message_size: @engine.options.max_message_size,
    **QoS.(@engine.options)

  Async::Task.current.with_timeout(handshake_timeout) do
    conn.handshake!
  end

  QoS.validate_handshake!(@engine.options, conn)

  OMQ::Engine::Heartbeat.start(@barrier, conn, @engine.options)
  ready!(conn)
  @conn
rescue Protocol::ZMTP::Error, *OMQ::CONNECTION_LOST, Async::TimeoutError => error
  @engine.emit_monitor_event :handshake_failed,
    endpoint: @endpoint, detail: { error: error }

  conn&.close

  tear_down!(reconnect: true)
  raise
end