class Crabbit::Message

Overview

Complete AMQP 1.0 message used as a RabbitMQ Stream payload.

A message can contain header, annotations, properties, application properties, one body family, footer, and unknown described sections. Message.new creates a Data-body message; use .data, .sequence, or .value for explicit body construction.

message = Crabbit::Message.new(
  "invoice-created",
  properties: Crabbit::Properties.new(content_type: "text/plain"),
  application_properties: {
    "region" => Crabbit::AMQP::Value.wrap("eu"),
  },
)

Defined in:

crabbit/message.cr

Constructors

Instance Method Summary

Constructor Detail

def self.data(parts : Enumerable(Bytes), *, header : Header | Nil = nil, delivery_annotations : Hash(AMQP::Value, AMQP::Value) = {} of AMQP::Value => AMQP::Value, message_annotations : Hash(AMQP::Value, AMQP::Value) = {} of AMQP::Value => AMQP::Value, properties : Properties | Nil = nil, application_properties : Hash(String, AMQP::Value) = {} of String => AMQP::Value, footer : Hash(AMQP::Value, AMQP::Value) = {} of AMQP::Value => AMQP::Value, extra_sections : Array(AMQP::Value) = [] of AMQP::Value) : self #

Creates a message containing one Data section for every entry in parts.

Each byte slice is copied.


[View source]
def self.from_amqp(bytes : Bytes, *, zero_copy : Bool = false) : self #

Decodes one complete AMQP message from bytes.

Binary values are copied by default. With zero_copy, Data sections and AMQP binary values may reference bytes directly; the caller must keep that buffer alive and must not mutate it while the message is used.


[View source]
def self.new(body : Bytes | String = Bytes.empty, header : Header | Nil = nil, delivery_annotations : Hash(AMQP::Value, AMQP::Value) | Nil = nil, message_annotations : Hash(AMQP::Value, AMQP::Value) | Nil = nil, properties : Properties | Nil = nil, application_properties : Hash(String, AMQP::Value) | Nil = nil, footer : Hash(AMQP::Value, AMQP::Value) | Nil = nil) #

Creates a message with one AMQP Data section.

The body bytes are copied so later mutation of the caller's buffer does not affect the message.


[View source]
def self.sequence(values : Array(AMQP::Value), *, header : Header | Nil = nil, delivery_annotations : Hash(AMQP::Value, AMQP::Value) = {} of AMQP::Value => AMQP::Value, message_annotations : Hash(AMQP::Value, AMQP::Value) = {} of AMQP::Value => AMQP::Value, properties : Properties | Nil = nil, application_properties : Hash(String, AMQP::Value) = {} of String => AMQP::Value, footer : Hash(AMQP::Value, AMQP::Value) = {} of AMQP::Value => AMQP::Value, extra_sections : Array(AMQP::Value) = [] of AMQP::Value) : self #

Creates a message containing a single AMQP Sequence section.


[View source]
def self.value(value : AMQP::Value, *, header : Header | Nil = nil, delivery_annotations : Hash(AMQP::Value, AMQP::Value) = {} of AMQP::Value => AMQP::Value, message_annotations : Hash(AMQP::Value, AMQP::Value) = {} of AMQP::Value => AMQP::Value, properties : Properties | Nil = nil, application_properties : Hash(String, AMQP::Value) = {} of String => AMQP::Value, footer : Hash(AMQP::Value, AMQP::Value) = {} of AMQP::Value => AMQP::Value, extra_sections : Array(AMQP::Value) = [] of AMQP::Value) : self #

Creates a message containing a single AMQP Value section.


[View source]

Instance Method Detail

def application_properties : Hash(String, AMQP::Value) #

Returns the mutable application-properties map, creating it when absent.


[View source]
def body : Bytes #

Returns the logical Data body as bytes.

A single Data part is returned without copying. Multiple parts are joined into a new slice. Non-Data messages return Bytes.empty.


[View source]
def body_kind : BodyKind #

Returns the encoded body family.


[View source]
def data : Array(Bytes) #

Returns the mutable list of AMQP Data section payloads.


[View source]
def delivery_annotations : Hash(AMQP::Value, AMQP::Value) #

Returns the mutable delivery-annotations map, creating it when absent.


[View source]
def extra_sections : Array(AMQP::Value) #

Returns unknown described sections preserved during decoding.

Values added here are encoded after the standard message sections.


[View source]
def footer : Hash(AMQP::Value, AMQP::Value) #

Returns the mutable footer map, creating it when absent.


[View source]
def header : Header | Nil #

Returns the optional AMQP header.


[View source]
def message_annotations : Hash(AMQP::Value, AMQP::Value) #

Returns the mutable message-annotations map, creating it when absent.


[View source]
def properties : Properties | Nil #

Returns the optional AMQP properties section.


[View source]
def sequences : Array(Array(AMQP::Value)) #

Returns the mutable list of AMQP Sequence section values.


[View source]
def to_amqp(io : IO) : Nil #

Encodes the complete message directly into io.

This overload avoids allocating an intermediate encoded Bytes buffer.


[View source]
def to_amqp : Bytes #

Encodes the complete message to a newly allocated AMQP byte slice.


[View source]
def value : AMQP::Value | Nil #

Returns the AMQP Value body, or nil for Data and Sequence bodies.


[View source]