Class: Qpid::Proton::Message
- Inherits:
-
Object
- Object
- Qpid::Proton::Message
- Defined in:
- lib/qpid_proton/message.rb
Overview
A Message represents an addressable quantity of data.
Examples
Class Method Summary collapse
-
.finalize!(impl) ⇒ Object
Invoked by garbage collection to clean up resources used by the underlying message implementation.
Instance Method Summary collapse
-
#[](name) ⇒ Object
Retrieves the value for the specified property name.
-
#[]=(name, value) ⇒ Object
Assigns the value given to the named property.
-
#address ⇒ Object
Returns the destination address.
-
#address=(address) ⇒ Object
Sets the destination address.
-
#annotations ⇒ Object
Returns the annotations for this message.
-
#annotations=(annotations) ⇒ Object
Assigns annotations to this message.
-
#body ⇒ Object
Returns the body property of the message.
-
#body=(body) ⇒ Object
Assigns a new value to the body of the message.
-
#clear ⇒ Object
Clears the state of the
Message
. -
#content ⇒ Object
Returns the message content.
-
#content=(content) ⇒ Object
Sets the message content.
-
#content_encoding ⇒ Object
Returns the content encoding type.
-
#content_encoding=(encoding) ⇒ Object
Sets the content encoding type.
-
#content_type ⇒ Object
Returns the content type.
-
#content_type=(content_type) ⇒ Object
Sets the content type.
-
#correlation_id ⇒ Object
Returns the correlation id.
-
#correlation_id=(id) ⇒ Object
Sets the correlation id.
-
#creation_time ⇒ Object
Returns the creation time.
-
#creation_time=(time) ⇒ Object
Sets the creation time.
-
#decode(encoded) ⇒ Object
Decodes a message from supplied AMQP data and returns the number of bytes consumed.
-
#delete_property(name) ⇒ Object
Deletes the named property.
-
#delivery_count ⇒ Object
Returns the delivery count for the message.
-
#delivery_count=(count) ⇒ Object
Sets the delivery count for the message.
-
#durable ⇒ Object
Returns the durable property.
-
#durable=(state) ⇒ Object
Sets the durable flag.
-
#encode ⇒ Object
Encodes the message.
-
#errno ⇒ Object
Returns the most recent error number.
-
#error ⇒ Object
Returns the most recent error message.
-
#error? ⇒ Boolean
Returns whether there is currently an error reported.
-
#expires ⇒ Object
Returns the expiration time.
-
#expires=(time) ⇒ Object
Sets the expiration time.
-
#first_acquirer=(state) ⇒ Object
Sets whether this is the first time the message was acquired.
-
#first_acquirer? ⇒ Boolean
Returns whether this is the first acquirer.
-
#format ⇒ Object
Returns the message format.
-
#format=(format) ⇒ Object
Sets the message format.
-
#group_id ⇒ Object
Returns the group id.
-
#group_id=(id) ⇒ Object
Sets the group id.
-
#group_sequence ⇒ Object
Returns the group sequence number.
-
#group_sequence=(seq) ⇒ Object
Sets the group sequence number.
-
#id ⇒ Object
Returns the message id.
-
#id=(id) ⇒ Object
Sets the message id.
-
#impl ⇒ Object
Returns the underlying message implementation.
-
#initialize ⇒ Message
constructor
Creates a new
Message
instance. -
#instructions ⇒ Object
Returns the instructions for this message.
-
#instructions=(instr) ⇒ Object
Assigns instructions to this message.
-
#post_decode ⇒ Object
:nodoc:.
-
#pre_encode ⇒ Object
:nodoc:.
-
#priority ⇒ Object
Returns the priority.
-
#priority=(priority) ⇒ Object
Sets the priority.
-
#properties ⇒ Object
Returns the list of property names for associated with this message.
-
#properties=(properties) ⇒ Object
Replaces the entire set of properties with the specified hash.
-
#reply_to ⇒ Object
Returns the reply-to address.
-
#reply_to=(address) ⇒ Object
Sets the reply-to address.
-
#reply_to_group_id ⇒ Object
Returns the reply-to group id.
-
#reply_to_group_id=(id) ⇒ Object
Sets the reply-to group id.
-
#subject ⇒ Object
Returns the subject.
-
#subject=(subject) ⇒ Object
Sets the subject.
- #to_s ⇒ Object
-
#ttl ⇒ Object
Returns the time-to-live, in milliseconds.
-
#ttl=(time) ⇒ Object
Sets the time-to-live for the message.
-
#user_id ⇒ Object
Returns the user id.
-
#user_id=(id) ⇒ Object
Sets the user id.
Constructor Details
Class Method Details
.finalize!(impl) ⇒ Object
Invoked by garbage collection to clean up resources used by the underlying message implementation.
127 128 129 130 131 |
# File 'lib/qpid_proton/message.rb', line 127 def self.finalize!(impl) # :nodoc: proc { Cproton.(impl) } end |
Instance Method Details
#[](name) ⇒ Object
Retrieves the value for the specified property name. If not found, then it returns nil.
554 555 556 |
# File 'lib/qpid_proton/message.rb', line 554 def [](name) @properties[name] end |
#[]=(name, value) ⇒ Object
Assigns the value given to the named property.
Arguments
-
name - the property name
-
value - the property value
547 548 549 |
# File 'lib/qpid_proton/message.rb', line 547 def []=(name, value) @properties[name] = value end |
#address ⇒ Object
Returns the destination address.
319 320 321 |
# File 'lib/qpid_proton/message.rb', line 319 def address Cproton.(@impl) end |
#address=(address) ⇒ Object
Sets the destination address.
Options
-
address - the address
313 314 315 |
# File 'lib/qpid_proton/message.rb', line 313 def address=(address) Cproton.(@impl, address) end |
#annotations ⇒ Object
Returns the annotations for this message.
578 579 580 |
# File 'lib/qpid_proton/message.rb', line 578 def annotations @annotations end |
#annotations=(annotations) ⇒ Object
Assigns annotations to this message.
584 585 586 |
# File 'lib/qpid_proton/message.rb', line 584 def annotations=(annotations) @annotations = annotations end |
#body ⇒ Object
Returns the body property of the message.
590 591 592 |
# File 'lib/qpid_proton/message.rb', line 590 def body @body end |
#body=(body) ⇒ Object
Assigns a new value to the body of the message.
596 597 598 |
# File 'lib/qpid_proton/message.rb', line 596 def body=(body) @body = body end |
#clear ⇒ Object
Clears the state of the Message
. This allows a single instance of Message
to be reused.
141 142 143 144 145 146 147 |
# File 'lib/qpid_proton/message.rb', line 141 def clear Cproton.(@impl) @properties.clear unless @properties.nil? @instructions.clear unless @instructions.nil? @annotations.clear unless @annotations.nil? @body = nil end |
#content ⇒ Object
Returns the message content.
418 419 420 |
# File 'lib/qpid_proton/message.rb', line 418 def content Cproton.(@impl, 1024)[1] end |
#content=(content) ⇒ Object
Sets the message content.
Options
-
content - the content
412 413 414 |
# File 'lib/qpid_proton/message.rb', line 412 def content=(content) Cproton.(@impl, content) end |
#content_encoding ⇒ Object
Returns the content encoding type.
434 435 436 |
# File 'lib/qpid_proton/message.rb', line 434 def content_encoding Cproton.(@impl) end |
#content_encoding=(encoding) ⇒ Object
Sets the content encoding type.
Options
-
encoding - the content encoding
428 429 430 |
# File 'lib/qpid_proton/message.rb', line 428 def content_encoding=(encoding) Cproton.(@impl, encoding) end |
#content_type ⇒ Object
Returns the content type
402 403 404 |
# File 'lib/qpid_proton/message.rb', line 402 def content_type Cproton.(@impl) end |
#content_type=(content_type) ⇒ Object
Sets the content type.
Options
-
content_type - the content type
396 397 398 |
# File 'lib/qpid_proton/message.rb', line 396 def content_type=(content_type) Cproton.(@impl, content_type) end |
#correlation_id ⇒ Object
Returns the correlation id.
367 368 369 |
# File 'lib/qpid_proton/message.rb', line 367 def correlation_id Cproton.(@impl) end |
#correlation_id=(id) ⇒ Object
Sets the correlation id.
Options
-
id - the correlation id
361 362 363 |
# File 'lib/qpid_proton/message.rb', line 361 def correlation_id=(id) Cproton.(@impl, id) end |
#creation_time ⇒ Object
Returns the creation time.
470 471 472 |
# File 'lib/qpid_proton/message.rb', line 470 def creation_time Cproton.(@impl) end |
#creation_time=(time) ⇒ Object
Sets the creation time.
Options
-
time - the creation time
462 463 464 465 466 |
# File 'lib/qpid_proton/message.rb', line 462 def creation_time=(time) raise TypeError.new("invalid time: #{time}") if time.nil? raise ArgumentError.new("time cannot be negative") if time < 0 Cproton.(@impl, time) end |
#decode(encoded) ⇒ Object
Decodes a message from supplied AMQP data and returns the number of bytes consumed.
Options
-
encoded - the encoded data
37 38 39 40 41 |
# File 'lib/qpid_proton/message.rb', line 37 def decode(encoded) check(Cproton.(@impl, encoded, encoded.length)) post_decode end |
#delete_property(name) ⇒ Object
Deletes the named property.
560 561 562 |
# File 'lib/qpid_proton/message.rb', line 560 def delete_property(name) @properties.delete(name) end |
#delivery_count ⇒ Object
Returns the delivery count for the message.
This is the number of delivery attempts for the given message.
264 265 266 |
# File 'lib/qpid_proton/message.rb', line 264 def delivery_count Cproton.(@impl) end |
#delivery_count=(count) ⇒ Object
Sets the delivery count for the message.
See ::delivery_count for more details.
Options
-
count - the delivery count
253 254 255 256 257 258 |
# File 'lib/qpid_proton/message.rb', line 253 def delivery_count=(count) raise ArgumentError.new("invalid count: #{count}") if count.nil? || !([Float, Fixnum].include?(count.class)) raise RangeError.new("count out of range: #{count}") if count < 0 Cproton.(@impl, count.floor) end |
#durable ⇒ Object
190 191 192 |
# File 'lib/qpid_proton/message.rb', line 190 def durable Cproton.(@impl) end |
#durable=(state) ⇒ Object
Sets the durable flag.
See ::durable for more details on message durability.
Options
-
state - the durable state
175 176 177 178 |
# File 'lib/qpid_proton/message.rb', line 175 def durable=(state) raise TypeError.new("state cannot be nil") if state.nil? Cproton.(@impl, state) end |
#encode ⇒ Object
Encodes the message.
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/qpid_proton/message.rb', line 68 def encode pre_encode size = 16 loop do error, data = Cproton::(@impl, size) if error == Qpid::Proton::Error::OVERFLOW size *= 2 else check(error) return data end end end |
#errno ⇒ Object
Returns the most recent error number.
151 152 153 |
# File 'lib/qpid_proton/message.rb', line 151 def errno Cproton.(@impl) end |
#error ⇒ Object
Returns the most recent error message.
157 158 159 |
# File 'lib/qpid_proton/message.rb', line 157 def error Cproton.pn_error_text(Cproton.(@impl)) end |
#error? ⇒ Boolean
Returns whether there is currently an error reported.
163 164 165 |
# File 'lib/qpid_proton/message.rb', line 163 def error? !Cproton.(@impl).zero? end |
#expires ⇒ Object
Returns the expiration time.
452 453 454 |
# File 'lib/qpid_proton/message.rb', line 452 def expires Cproton.(@impl) end |
#expires=(time) ⇒ Object
Sets the expiration time.
Options
-
time - the expiry time
444 445 446 447 448 |
# File 'lib/qpid_proton/message.rb', line 444 def expires=(time) raise TypeError.new("invalid expiry time: #{time}") if time.nil? raise ArgumentError.new("expiry time cannot be negative: #{time}") if time < 0 Cproton.(@impl, time) end |
#first_acquirer=(state) ⇒ Object
Sets whether this is the first time the message was acquired.
See ::first_acquirer? for more details.
Options
-
state - true if claiming the message
240 241 242 243 |
# File 'lib/qpid_proton/message.rb', line 240 def first_acquirer=(state) raise TypeError.new("invalid state: #{state}") if state.nil? || !([TrueClass, FalseClass].include?(state.class)) Cproton.(@impl, state) end |
#first_acquirer? ⇒ Boolean
Returns whether this is the first acquirer.
271 272 273 |
# File 'lib/qpid_proton/message.rb', line 271 def first_acquirer? Cproton.(@impl) end |
#format ⇒ Object
Returns the message format
386 387 388 |
# File 'lib/qpid_proton/message.rb', line 386 def format Qpid::Proton::MessageFormat.by_value(Cproton.(@impl)) end |
#format=(format) ⇒ Object
Sets the message format.
See MessageFormat for more details on formats.
Options
-
format - the format
379 380 381 382 |
# File 'lib/qpid_proton/message.rb', line 379 def format=(format) raise TypeError.new("invalid message format: #{format}") if (format.nil? || !format.kind_of?(Qpid::Proton::MessageFormat)) Cproton.(@impl, format.value) end |
#group_id ⇒ Object
Returns the group id.
486 487 488 |
# File 'lib/qpid_proton/message.rb', line 486 def group_id Cproton.(@impl) end |
#group_id=(id) ⇒ Object
Sets the group id.
Options
-
id - the group id
480 481 482 |
# File 'lib/qpid_proton/message.rb', line 480 def group_id=(id) Cproton.(@impl, id) end |
#group_sequence ⇒ Object
Returns the group sequence number.
503 504 505 |
# File 'lib/qpid_proton/message.rb', line 503 def group_sequence Cproton.(@impl) end |
#group_sequence=(seq) ⇒ Object
Sets the group sequence number.
Options
-
seq - the sequence number
496 497 498 499 |
# File 'lib/qpid_proton/message.rb', line 496 def group_sequence=(seq) raise TypeError.new("invalid seq: #{seq}") if seq.nil? Cproton.(@impl, seq) end |
#id ⇒ Object
Returns the message id.
287 288 289 |
# File 'lib/qpid_proton/message.rb', line 287 def id Cproton.(@impl) end |
#id=(id) ⇒ Object
Sets the message id.
Options
-
id = the id
281 282 283 |
# File 'lib/qpid_proton/message.rb', line 281 def id=(id) Cproton.(@impl, id) end |
#impl ⇒ Object
Returns the underlying message implementation.
134 135 136 |
# File 'lib/qpid_proton/message.rb', line 134 def impl # :nodoc: @impl end |
#instructions ⇒ Object
Returns the instructions for this message.
566 567 568 |
# File 'lib/qpid_proton/message.rb', line 566 def instructions @instructions end |
#instructions=(instr) ⇒ Object
Assigns instructions to this message.
572 573 574 |
# File 'lib/qpid_proton/message.rb', line 572 def instructions=(instr) @instructions = instr end |
#post_decode ⇒ Object
:nodoc:
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/qpid_proton/message.rb', line 43 def post_decode # :nodoc: # decode elements from the message @properties = {} props = Qpid::Proton::Data.new(Cproton::(@impl)) if props.next @properties = props.type.get(props) end @instructions = nil insts = Qpid::Proton::Data.new(Cproton::(@impl)) if insts.next @instructions = insts.type.get(insts) end @annotations = nil annts = Qpid::Proton::Data.new(Cproton::(@impl)) if annts.next @annotations = annts.type.get(annts) end @body = nil body = Qpid::Proton::Data.new(Cproton::(@impl)) if body.next @body = body.type.get(body) end end |
#pre_encode ⇒ Object
:nodoc:
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/qpid_proton/message.rb', line 82 def pre_encode # :nodoc: # encode elements from the message props = Qpid::Proton::Data.new(Cproton::(@impl)) props.clear Qpid::Proton::Mapping.for_class(@properties.class).put(props, @properties) unless @properties.empty? insts = Qpid::Proton::Data.new(Cproton::(@impl)) insts.clear if !@instructions.nil? mapping = Qpid::Proton::Mapping.for_class(@instructions.class) mapping.put(insts, @instructions) end annts = Qpid::Proton::Data.new(Cproton::(@impl)) annts.clear if !@annotations.nil? mapping = Qpid::Proton::Mapping.for_class(@annotations.class) mapping.put(annts, @annotations) end body = Qpid::Proton::Data.new(Cproton::(@impl)) body.clear if !@body.nil? mapping = Qpid::Proton::Mapping.for_class(@body.class) mapping.put(body, @body) end end |
#priority ⇒ Object
Returns the priority.
210 211 212 |
# File 'lib/qpid_proton/message.rb', line 210 def priority Cproton.(@impl) end |
#priority=(priority) ⇒ Object
Sets the priority.
NOTE:
Priority values are limited to the range [0,255].
Options
-
priority - the priority value
202 203 204 205 206 |
# File 'lib/qpid_proton/message.rb', line 202 def priority=(priority) raise TypeError.new("invalid priority: #{priority}") if priority.nil? || !([Float, Fixnum].include?(priority.class)) raise RangeError.new("priority out of range: #{priority}") if ((priority > 255) || (priority < 0)) Cproton.(@impl, priority.floor) end |
#properties ⇒ Object
Returns the list of property names for associated with this message.
Examples
msg.properties.each do |name|
end
530 531 532 |
# File 'lib/qpid_proton/message.rb', line 530 def properties @properties end |
#properties=(properties) ⇒ Object
Replaces the entire set of properties with the specified hash.
536 537 538 |
# File 'lib/qpid_proton/message.rb', line 536 def properties=(properties) @properties = properties end |
#reply_to ⇒ Object
Returns the reply-to address
351 352 353 |
# File 'lib/qpid_proton/message.rb', line 351 def reply_to Cproton.(@impl) end |
#reply_to=(address) ⇒ Object
Sets the reply-to address.
Options
-
address - the reply-to address
345 346 347 |
# File 'lib/qpid_proton/message.rb', line 345 def reply_to=(address) Cproton.(@impl, address) end |
#reply_to_group_id ⇒ Object
Returns the reply-to group id.
519 520 521 |
# File 'lib/qpid_proton/message.rb', line 519 def reply_to_group_id Cproton.(@impl) end |
#reply_to_group_id=(id) ⇒ Object
Sets the reply-to group id.
Options
-
id - the id
513 514 515 |
# File 'lib/qpid_proton/message.rb', line 513 def reply_to_group_id=(id) Cproton.(@impl, id) end |
#subject ⇒ Object
Returns the subject
335 336 337 |
# File 'lib/qpid_proton/message.rb', line 335 def subject Cproton.(@impl) end |
#subject=(subject) ⇒ Object
Sets the subject.
Options
-
subject - the subject
329 330 331 |
# File 'lib/qpid_proton/message.rb', line 329 def subject=(subject) Cproton.(@impl, subject) end |
#to_s ⇒ Object
117 118 119 120 121 122 123 |
# File 'lib/qpid_proton/message.rb', line 117 def to_s tmp = Cproton.pn_string("") Cproton.pn_inspect(@impl, tmp) result = Cproton.pn_string_get(tmp) Cproton.pn_free(tmp) return result end |
#ttl ⇒ Object
Returns the time-to-live, in milliseconds.
228 229 230 |
# File 'lib/qpid_proton/message.rb', line 228 def ttl Cproton.(@impl) end |
#ttl=(time) ⇒ Object
Sets the time-to-live for the message.
Options
-
time - the time in milliseconds
220 221 222 223 224 |
# File 'lib/qpid_proton/message.rb', line 220 def ttl=(time) raise TypeError.new("invalid ttl: #{time}") if time.nil? || !([Float, Fixnum].include?(time.class)) raise RangeError.new("time out of range: #{time}") if ((time < 0)) Cproton.(@impl, time.floor) end |
#user_id ⇒ Object
Returns the user id.
303 304 305 |
# File 'lib/qpid_proton/message.rb', line 303 def user_id Cproton.(@impl) end |
#user_id=(id) ⇒ Object
Sets the user id.
Options
-
id - the user id
297 298 299 |
# File 'lib/qpid_proton/message.rb', line 297 def user_id=(id) Cproton.(@impl, id) end |