class Qpid::Proton::Message
A Message represents an addressable quantity of data.
Message Body¶ ↑
The message body can be set using the body= method. The message will then attempt to determine how exactly to encode the content.
Examples¶ ↑
To create a message for sending:
# send a simple text message msg = Qpid::Proton::Message.new msg.body = "STATE: update" # send a binary chunk of data data = File.binread("/home/qpid/binfile.tar.gz") msg = Qpid::Proton::Message.new msg.body = Qpid::Proton::BinaryString.new(data)
Public Class Methods
Creates a new Message
instance.
# File lib/qpid_proton/message.rb, line 124 def initialize @impl = Cproton.pn_message ObjectSpace.define_finalizer(self, self.class.finalize!(@impl)) @properties = {} @instructions = {} @annotations = {} @body = nil end
Public Instance Methods
Retrieves the value for the specified property name. If not found, then it returns nil.
# File lib/qpid_proton/message.rb, line 562 def [](name) @properties[name] end
Returns the destination address.
# File lib/qpid_proton/message.rb, line 335 def address Cproton.pn_message_get_address(@impl) end
Returns the annotations for this message.
# File lib/qpid_proton/message.rb, line 586 def annotations @annotations end
Assigns annotations to this message.
# File lib/qpid_proton/message.rb, line 592 def annotations=(annotations) @annotations = annotations end
Returns the body property of the message.
# File lib/qpid_proton/message.rb, line 598 def body @body end
Assigns a new value to the body of the message.
# File lib/qpid_proton/message.rb, line 604 def body=(body) @body = body end
Clears the state of the Message
. This allows a single instance
of Message
to be reused.
# File lib/qpid_proton/message.rb, line 157 def clear Cproton.pn_message_clear(@impl) @properties.clear unless @properties.nil? @instructions.clear unless @instructions.nil? @annotations.clear unless @annotations.nil? @body = nil end
Returns the content encoding type.
# File lib/qpid_proton/message.rb, line 442 def content_encoding Cproton.pn_message_get_content_encoding(@impl) end
Returns the content type
# File lib/qpid_proton/message.rb, line 426 def content_type Cproton.pn_message_get_content_type(@impl) end
Sets the content type.
Options¶ ↑
-
#content_type - the content type
# File lib/qpid_proton/message.rb, line 420 def content_type=(content_type) Cproton.pn_message_set_content_type(@impl, content_type) end
Returns the correlation id.
# File lib/qpid_proton/message.rb, line 383 def correlation_id Cproton.pn_message_get_correlation_id(@impl) end
Returns the creation time.
# File lib/qpid_proton/message.rb, line 478 def creation_time Cproton.pn_message_get_creation_time(@impl) end
Sets the creation time.
Options¶ ↑
-
time - the creation time
# File lib/qpid_proton/message.rb, line 470 def creation_time=(time) raise TypeError.new("invalid time: #{time}") if time.nil? raise ArgumentError.new("time cannot be negative") if time < 0 Cproton.pn_message_set_creation_time(@impl, time) end
Deletes the named property.
# File lib/qpid_proton/message.rb, line 568 def delete_property(name) @properties.delete(name) end
Returns the delivery count for the message.
This is the number of delivery attempts for the given message.
# File lib/qpid_proton/message.rb, line 280 def delivery_count Cproton.pn_message_get_delivery_count(@impl) end
Sets the delivery count for the message.
See ::delivery_count for more details.
Options¶ ↑
-
count - the delivery count
# File lib/qpid_proton/message.rb, line 269 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.pn_message_set_delivery_count(@impl, count.floor) end
Returns the durable property.
The durable property indicates that the emessage should be held durably by any intermediaries taking responsibility for the message.
Examples¶ ↑
msg = Qpid::Proton::Message.new msg.durable = true
# File lib/qpid_proton/message.rb, line 206 def durable Cproton.pn_message_is_durable(@impl) end
Encodes the message.
# File lib/qpid_proton/message.rb, line 84 def encode pre_encode size = 16 loop do error, data = Cproton::pn_message_encode(@impl, size) if error == Qpid::Proton::Error::OVERFLOW size *= 2 else check(error) return data end end end
Returns the most recent error number.
# File lib/qpid_proton/message.rb, line 167 def errno Cproton.pn_message_errno(@impl) end
Returns the most recent error message.
# File lib/qpid_proton/message.rb, line 173 def error Cproton.pn_error_text(Cproton.pn_message_error(@impl)) end
Returns whether there is currently an error reported.
# File lib/qpid_proton/message.rb, line 179 def error? !Cproton.pn_message_errno(@impl).zero? end
Returns the expiration time.
# File lib/qpid_proton/message.rb, line 460 def expires Cproton.pn_message_get_expiry_time(@impl) end
Sets the expiration time.
Options¶ ↑
-
time - the expiry time
# File lib/qpid_proton/message.rb, line 452 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.pn_message_set_expiry_time(@impl, time) end
Sets whether this is the first time the message was acquired.
See ::first_acquirer? for more details.
Options¶ ↑
-
state - true if claiming the message
# File lib/qpid_proton/message.rb, line 256 def first_acquirer=(state) raise TypeError.new("invalid state: #{state}") if state.nil? || !([TrueClass, FalseClass].include?(state.class)) Cproton.pn_message_set_first_acquirer(@impl, state) end
Returns whether this is the first acquirer.
# File lib/qpid_proton/message.rb, line 287 def first_acquirer? Cproton.pn_message_is_first_acquirer(@impl) end
Sets the message format.
See MessageFormat for more details on formats.
Warning: This method has been deprecated.
Options¶ ↑
-
format - the format
# File lib/qpid_proton/message.rb, line 397 def format=(format) raise TypeError.new("invalid message format: #{format}") if (format.nil? || !format.kind_of?(Qpid::Proton::MessageFormat)) Cproton.pn_message_set_format(@impl, format.value) end
Returns the group id.
# File lib/qpid_proton/message.rb, line 494 def group_id Cproton.pn_message_get_group_id(@impl) end
Returns the group sequence number.
# File lib/qpid_proton/message.rb, line 511 def group_sequence Cproton.pn_message_get_group_sequence(@impl) end
Returns the message id.
# File lib/qpid_proton/message.rb, line 303 def id Cproton.pn_message_get_id(@impl) end
Returns the instructions for this message.
# File lib/qpid_proton/message.rb, line 574 def instructions @instructions end
Assigns instructions to this message.
# File lib/qpid_proton/message.rb, line 580 def instructions=(instr) @instructions = instr end
Returns the priority.
# File lib/qpid_proton/message.rb, line 226 def priority Cproton.pn_message_get_priority(@impl) end
Sets the priority.
NOTE:
Priority values are limited to the range [0,255].
Options¶ ↑
-
priority - the priority value
# File lib/qpid_proton/message.rb, line 218 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.pn_message_set_priority(@impl, priority.floor) end
Replaces the entire set of properties with the specified hash.
# File lib/qpid_proton/message.rb, line 544 def properties=(properties) @properties = properties end
Returns the reply-to address
# File lib/qpid_proton/message.rb, line 367 def reply_to Cproton.pn_message_get_reply_to(@impl) end
Returns the reply-to group id.
# File lib/qpid_proton/message.rb, line 527 def reply_to_group_id Cproton.pn_message_get_reply_to_group_id(@impl) end
Returns the subject
# File lib/qpid_proton/message.rb, line 351 def subject Cproton.pn_message_get_subject(@impl) end
# File lib/qpid_proton/message.rb, line 133 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
Returns the time-to-live, in milliseconds.
# File lib/qpid_proton/message.rb, line 244 def ttl Cproton.pn_message_get_ttl(@impl) end
Sets the time-to-live for the message.
Options¶ ↑
-
time - the time in milliseconds
# File lib/qpid_proton/message.rb, line 236 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.pn_message_set_ttl(@impl, time.floor) end
Returns the user id.
# File lib/qpid_proton/message.rb, line 319 def user_id Cproton.pn_message_get_user_id(@impl) end