Class: AMQP::Client::Message
- Inherits:
-
Object
- Object
- AMQP::Client::Message
- Defined in:
- lib/amqp/client/message.rb
Overview
A message delivered from the broker
Defined Under Namespace
Classes: DeliveryInfo
Instance Attribute Summary collapse
-
#body ⇒ String
The message body.
-
#channel ⇒ Connection::Channel
readonly
The channel the message was deliviered to.
-
#consumer_tag ⇒ String?
readonly
The tag of the consumer the message was deliviered to.
-
#delivery_tag ⇒ Integer
readonly
The delivery tag of the message, used for acknowledge or reject the message.
-
#exchange ⇒ String
readonly
Name of the exchange the message was published to.
- #exchange_name ⇒ String readonly deprecated Deprecated.
-
#properties ⇒ Properties
Message properties.
-
#redelivered ⇒ Boolean
readonly
True if the message have been delivered before.
-
#routing_key ⇒ String
readonly
The routing key the message was published with.
Message coding collapse
-
#decode ⇒ String
Decode the message body based on content_encoding.
-
#parse ⇒ Object
Parse the message body based on content_type and content_encoding.
Instance Method Summary collapse
-
#ack ⇒ nil
Acknowledge the message.
- #delivery_info ⇒ Object
-
#reject(requeue: false) ⇒ nil
Reject the message.
Instance Attribute Details
#body ⇒ String
The message body
54 55 56 |
# File 'lib/amqp/client/message.rb', line 54 def body @body end |
#channel ⇒ Connection::Channel (readonly)
The channel the message was deliviered to
25 26 27 |
# File 'lib/amqp/client/message.rb', line 25 def channel @channel end |
#consumer_tag ⇒ String? (readonly)
The tag of the consumer the message was deliviered to
30 31 32 |
# File 'lib/amqp/client/message.rb', line 30 def consumer_tag @consumer_tag end |
#delivery_tag ⇒ Integer (readonly)
The delivery tag of the message, used for acknowledge or reject the message
34 35 36 |
# File 'lib/amqp/client/message.rb', line 34 def delivery_tag @delivery_tag end |
#exchange ⇒ String (readonly)
Name of the exchange the message was published to
38 39 40 |
# File 'lib/amqp/client/message.rb', line 38 def exchange @exchange end |
#exchange_name ⇒ String (readonly)
92 93 94 |
# File 'lib/amqp/client/message.rb', line 92 def exchange_name @exchange end |
#properties ⇒ Properties
Message properties
50 51 52 |
# File 'lib/amqp/client/message.rb', line 50 def properties @properties end |
#redelivered ⇒ Boolean (readonly)
True if the message have been delivered before
46 47 48 |
# File 'lib/amqp/client/message.rb', line 46 def redelivered @redelivered end |
#routing_key ⇒ String (readonly)
The routing key the message was published with
42 43 44 |
# File 'lib/amqp/client/message.rb', line 42 def routing_key @routing_key end |
Instance Method Details
#ack ⇒ nil
Acknowledge the message
69 70 71 72 73 74 75 |
# File 'lib/amqp/client/message.rb', line 69 def ack return if @ack_or_reject_sent @channel.basic_ack(@delivery_tag) @ack_or_reject_sent = true nil end |
#decode ⇒ String
Decode the message body based on content_encoding
122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/amqp/client/message.rb', line 122 def decode registry = @channel.connection.codec_registry strict = @channel.connection.strict_coding ce = @properties&.content_encoding coder = registry&.find_coder(ce) return coder.decode(@body, @properties) if coder is_unsupported = ce && ce != "" raise Error::UnsupportedContentEncoding, ce if is_unsupported && strict @body end |
#delivery_info ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/amqp/client/message.rb', line 56 def delivery_info @delivery_info ||= DeliveryInfo.new( consumer_tag:, delivery_tag:, redelivered:, exchange:, routing_key:, channel: ) end |
#parse ⇒ Object
Parse the message body based on content_type and content_encoding
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/amqp/client/message.rb', line 102 def parse return @parsed unless @parsed.nil? registry = @channel.connection.codec_registry strict = @channel.connection.strict_coding decoded = decode ct = @properties&.content_type parser = registry&.find_parser(ct) return @parsed = parser.parse(decoded, @properties) if parser is_unsupported = ct && ct != "" && ct != "text/plain" raise Error::UnsupportedContentType, ct if is_unsupported && strict @parsed = decoded end |
#reject(requeue: false) ⇒ nil
Reject the message
80 81 82 83 84 85 86 |
# File 'lib/amqp/client/message.rb', line 80 def reject(requeue: false) return if @ack_or_reject_sent @channel.basic_reject(@delivery_tag, requeue:) @ack_or_reject_sent = true nil end |