Module: OMQ::QoS::ErrorCodes

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

Overview

NACK error codes and exception mapping for QoS 3.

Receiver side: applications raise one of these exceptions from the block passed to #receive; the mapped error code travels back to the sender in a NACK command.

Sender side: NACK payloads are decoded into NackInfo (attached to DeadLetter#error when the NACK is terminal or retries are exhausted).

The high bit (+0x80+) of the error code byte is the retryable flag (see RFC §163–196). Senders MUST respect this flag for unknown codes.

Constant Summary collapse

CODE_TIMEOUT =

retryable

0x81
CODE_BAD_INPUT =

terminal

0x02
CODE_INTERNAL =

retryable

0x83
CODE_OVERLOADED =

retryable

0x84
CODE_REJECTED =

terminal

0x05
RETRYABLE_BIT =
0x80
MAX_MSG_BYTES =
65_535

Class Method Summary collapse

Class Method Details

.exception_to_payload(exc) ⇒ Array(Integer, String)

Maps an exception to a NACK code + truncated UTF-8 message suitable for the wire.

Parameters:

  • exc (Exception)

Returns:

  • (Array(Integer, String))

    [code, message bytes]



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/omq/qos/error_codes.rb', line 42

def self.exception_to_payload(exc)
  code =
    case exc
    when TimeoutError    then CODE_TIMEOUT
    when BadInputError   then CODE_BAD_INPUT
    when OverloadedError then CODE_OVERLOADED
    when RejectedError   then CODE_REJECTED
    else                      CODE_INTERNAL
    end

  msg = (exc.message || "").b
  msg = msg.byteslice(0, MAX_MSG_BYTES) if msg.bytesize > MAX_MSG_BYTES
  [code, msg]
end

.retryable?(code) ⇒ Boolean

Parameters:

  • code (Integer)

Returns:

  • (Boolean)


32
33
34
# File 'lib/omq/qos/error_codes.rb', line 32

def self.retryable?(code)
  (code & RETRYABLE_BIT) != 0
end