class
Crabbit::Message
- Crabbit::Message
- Reference
- Object
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.crConstructors
-
.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.
-
.from_amqp(bytes : Bytes, *, zero_copy : Bool = false) : self
Decodes one complete AMQP message from bytes.
-
.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.
-
.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.
-
.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.
Instance Method Summary
-
#application_properties : Hash(String, AMQP::Value)
Returns the mutable application-properties map, creating it when absent.
-
#body : Bytes
Returns the logical Data body as bytes.
-
#body_kind : BodyKind
Returns the encoded body family.
-
#data : Array(Bytes)
Returns the mutable list of AMQP Data section payloads.
-
#delivery_annotations : Hash(AMQP::Value, AMQP::Value)
Returns the mutable delivery-annotations map, creating it when absent.
-
#extra_sections : Array(AMQP::Value)
Returns unknown described sections preserved during decoding.
-
#footer : Hash(AMQP::Value, AMQP::Value)
Returns the mutable footer map, creating it when absent.
-
#header : Header | Nil
Returns the optional AMQP header.
-
#message_annotations : Hash(AMQP::Value, AMQP::Value)
Returns the mutable message-annotations map, creating it when absent.
-
#properties : Properties | Nil
Returns the optional AMQP properties section.
-
#sequences : Array(Array(AMQP::Value))
Returns the mutable list of AMQP Sequence section values.
-
#to_amqp(io : IO) : Nil
Encodes the complete message directly into io.
-
#to_amqp : Bytes
Encodes the complete message to a newly allocated AMQP byte slice.
-
#value : AMQP::Value | Nil
Returns the AMQP Value body, or
nilfor Data and Sequence bodies.
Constructor Detail
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.
Instance Method Detail
Returns the mutable application-properties map, creating it when absent.
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.
Returns the mutable delivery-annotations map, creating it when absent.
Returns unknown described sections preserved during decoding.
Values added here are encoded after the standard message sections.
Returns the mutable message-annotations map, creating it when absent.
Returns the mutable list of AMQP Sequence section values.
Encodes the complete message directly into io.
This overload avoids allocating an intermediate encoded Bytes buffer.