Module: OMQ::QoS::CommandClassExt

Defined in:
lib/omq/qos/zmtp/command_ext.rb

Overview

Prepended onto Protocol::ZMTP::Codec::Command's singleton class to add ACK/NACK/CLR/COMP command builders.

Instance Method Summary collapse

Instance Method Details

#ack(hash_bytes, algorithm: "x") ⇒ Object

Builds an ACK command.

Parameters:

  • hash_bytes (String)

    binary hash digest

  • algorithm (String) (defaults to: "x")

    "x" (XXH64) or "s" (SHA-1 truncated)



13
14
15
# File 'lib/omq/qos/zmtp/command_ext.rb', line 13

def ack(hash_bytes, algorithm: "x")
  new("ACK", "#{algorithm}#{hash_bytes}".b)
end

#clr(hash_bytes, algorithm: "x") ⇒ Object

Builds a CLR ("clear") command. Sent by the sender after receiving an ACK (QoS 2) or COMP (QoS 3) so the receiver may evict the digest from its dedup set immediately instead of waiting for TTL expiry.

Parameters:

  • hash_bytes (String)

    binary hash digest

  • algorithm (String) (defaults to: "x")

    "x" (XXH64) or "s" (SHA-1 truncated)



40
41
42
# File 'lib/omq/qos/zmtp/command_ext.rb', line 40

def clr(hash_bytes, algorithm: "x")
  new("CLR", "#{algorithm}#{hash_bytes}".b)
end

#comp(hash_bytes, algorithm: "x") ⇒ Object

Builds a COMP ("complete") command. Sent by the QoS 3 receiver after its application handler returns successfully.

Parameters:

  • hash_bytes (String)

    binary hash digest

  • algorithm (String) (defaults to: "x")

    "x" (XXH64) or "s" (SHA-1 truncated)



50
51
52
# File 'lib/omq/qos/zmtp/command_ext.rb', line 50

def comp(hash_bytes, algorithm: "x")
  new("COMP", "#{algorithm}#{hash_bytes}".b)
end

#nack(hash_bytes, code: 0, message: "", algorithm: "x") ⇒ Object

Builds a NACK command. The on-wire error_info payload is [1 byte code] [2 bytes big-endian message length] [message] per the omq-qos RFC §NACK command.

Parameters:

  • hash_bytes (String)

    binary hash digest

  • code (Integer) (defaults to: 0)

    error code byte (bit 7 = retryable)

  • message (String) (defaults to: "")

    UTF-8 error description (≤ 65535 bytes)

  • algorithm (String) (defaults to: "x")

    "x" (XXH64) or "s" (SHA-1 truncated)



26
27
28
29
30
# File 'lib/omq/qos/zmtp/command_ext.rb', line 26

def nack(hash_bytes, code: 0, message: "", algorithm: "x")
  msg_bytes  = message.b
  error_info = [code, msg_bytes.bytesize].pack("Cn") + msg_bytes
  new("NACK", "#{algorithm}#{hash_bytes}#{error_info}".b)
end