Class: Qpid::Messaging::Message
- Inherits:
-
Object
- Object
- Qpid::Messaging::Message
- Defined in:
- lib/qpid_messaging/message.rb
Overview
A Message
represents an routable piece of information.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Returns the value for the named property.
-
#[]=(key, value) ⇒ Object
Assigns a value to the named property.
-
#content ⇒ Object
Returns the content of the
Message
. -
#content=(content) ⇒ Object
Sets the content for the
Message
. -
#content_object ⇒ Object
Returns the content of the
Message
. -
#content_object=(content) ⇒ Object
Sets the message content.
-
#content_size ⇒ Object
Returns the content’s size in bytes.
-
#content_type ⇒ Object
Returns the content type for the
Message
. -
#content_type=(content_type) ⇒ Object
Sets the content type for the
Message
. -
#correlation_id ⇒ Object
Returns the correlation id of the
Message
. -
#correlation_id=(correlation_id) ⇒ Object
Sets the correlation id of the
Message
. -
#durable ⇒ Object
Returns the durability for the
Message
. -
#durable=(durable) ⇒ Object
Sets the durability of the
Message
. -
#initialize(args = {}) ⇒ Message
constructor
Creates a
Message
. -
#message_id ⇒ Object
Returns the message id.
-
#message_id=(message_id) ⇒ Object
Sets the message id.
-
#message_impl ⇒ Object
:nodoc:.
-
#priority ⇒ Object
Returns the priority for the
Message
. -
#priority=(priority) ⇒ Object
Sets the priority of the
Message
. -
#properties ⇒ Object
Returns all named properties.
-
#redelivered ⇒ Object
Returns whether the
Message
has been marked as redelivered. -
#redelivered=(redelivered) ⇒ Object
This is a hint to the messaging infrastructure that if de-duplication is required, that this message should be examined to determine if it is a duplicate.
-
#reply_to ⇒ Object
Returns the reply to address for the
Message
. -
#reply_to=(address) ⇒ Object
Sets the reply-to address.
-
#subject ⇒ Object
Returns the subject of the
Message
. -
#subject=(subject) ⇒ Object
Sets the subject for the
Message
. -
#ttl ⇒ Object
Returns the time-to-live in milliseconds.
-
#ttl=(duration) ⇒ Object
Sets the time-to-live in milliseconds.
-
#user_id ⇒ Object
Returns the user id for the
Message
. -
#user_id=(user_id) ⇒ Object
Sets the user id for the
Message
.
Constructor Details
#initialize(args = {}) ⇒ Message
39 40 41 42 43 44 |
# File 'lib/qpid_messaging/message.rb', line 39 def initialize(args = {}) @message_impl = (args[:impl] if args[:impl]) || nil @message_impl = Cqpid::Message.new if @message_impl.nil? args = {} if args.nil? self.content_object = args[:content] if args[:content] end |
Instance Method Details
#[](key) ⇒ Object
Returns the value for the named property.
Options
-
name
- the property name
Examples
# use of message properties to mark a message as digitally signed
verify(msg) if msg[:signed]
262 |
# File 'lib/qpid_messaging/message.rb', line 262 def [](key); self.properties[key.to_s]; end |
#[]=(key, value) ⇒ Object
Assigns a value to the named property.
A property’s name or value, if a symbol, will be converted to a string representation. However, you will still be able to access them using a symbol for the name.
Options
-
name
- the property name -
value
- the property value
Examples
# set the signed attribute on a message and then retrieve it
msg[:signed] = true # sets "signed" => true
puts "It's signed" if msg["signed"] # outputs "It's signed"
281 282 283 284 |
# File 'lib/qpid_messaging/message.rb', line 281 def []=(key, value) @message_impl.setProperty(key.to_s, Qpid::Messaging.stringify(value)) end |
#content ⇒ Object
Returns the content of the Message
.
Content is automatically decoded based on the specified content type. If the content type is application-specific, then no decoding is performed and the content is returnedas a String
representation.
For example, if an array of integers are sent, then the receiver will find the message content to be an array of String objects, where each String is a representation of the sent integer value.
329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/qpid_messaging/message.rb', line 329 def content if @content.nil? @content = @message_impl.getContent # decode the content is necessary if it # has an encoded content type if ["amqp/list", "amqp/map"].include? @message_impl.getContentType @content = Qpid::Messaging.decode(self, @message_impl.getContentType) end end @content end |
#content=(content) ⇒ Object
Sets the content for the Message
.
Content is automatically encoded for Array and Hash types. Other types need to set their own content types (via content_type) in order to specify how recipients should process the content.
Options
-
content
- the content
Examples
# set a simple content for a message
msg.content = "This is a simple message."
# sets content that is automatically encoded
msg.content = {:foo => :bar}
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/qpid_messaging/message.rb', line 303 def content=(content) content_type = nil @content = Qpid::Messaging.stringify(content) case @content when Hash content_type = "amqp/map" when Array content_type = "amqp/list" end if content_type.nil? @message_impl.setContent @content else Qpid::Messaging.encode @content, self, content_type end end |
#content_object ⇒ Object
Returns the content of the Message
.
366 367 368 |
# File 'lib/qpid_messaging/message.rb', line 366 def content_object @message_impl.getContentObject() end |
#content_object=(content) ⇒ Object
Sets the message content.
Options
-
content
- the content
Examples
# set a simple content for a message
msg.content_object = "This is a simple message."
# sets content that is automatically encoded
msg.content_object = {:foo => :bar}
360 361 362 |
# File 'lib/qpid_messaging/message.rb', line 360 def content_object=(content) @message_impl.setContentObject(Qpid::Messaging.stringify(content)) end |
#content_size ⇒ Object
Returns the content’s size in bytes.
345 |
# File 'lib/qpid_messaging/message.rb', line 345 def content_size; @message_impl.getContentSize; end |
#content_type ⇒ Object
Returns the content type for the Message
.
111 |
# File 'lib/qpid_messaging/message.rb', line 111 def content_type; @message_impl.getContentType; end |
#content_type=(content_type) ⇒ Object
Sets the content type for the Message
.
This should be set by the sending application and indicates to the recipients of the message how to interpret or decode the content.
By default, only dictionaries and maps are automatically given a content type. If this content type is replaced then retrieving the content will not behave correctly.
Options
-
content_type
- the content type
Examples
# send base64 encoded data in a mesage
msg = Qpid::Messaging::Message.new :content = "UXBpZCBSdWxlcyEK"
msg.content_type = "application/base64"
108 |
# File 'lib/qpid_messaging/message.rb', line 108 def content_type=(content_type); @message_impl.setContentType content_type; end |
#correlation_id ⇒ Object
Returns the correlation id of the Message
.
171 |
# File 'lib/qpid_messaging/message.rb', line 171 def correlation_id; @message_impl.getCorrelationId; end |
#correlation_id=(correlation_id) ⇒ Object
Sets the correlation id of the Message
.
The correlation id can be used as part of a protocol for message exchange patterns; e.g., a request-response pattern might require the correlation id of the request and the response to match, or it might use the message id of the request as the correlation id on the response.
NOTE: If the id is not a String
then the id is setup using the object’s string representation.
Options
-
id
- the id
168 |
# File 'lib/qpid_messaging/message.rb', line 168 def correlation_id=(correlation_id); @message_impl.setCorrelationId correlation_id; end |
#durable ⇒ Object
Returns the durability for the Message
.
224 |
# File 'lib/qpid_messaging/message.rb', line 224 def durable; @message_impl.getDurable; end |
#durable=(durable) ⇒ Object
Sets the durability of the Message
.
This is a hint to the messaging infrastructure that the message should be persisted or otherwise stored. This helps to ensure that the message is not lost due to failures or a shutdown.
Options
-
durable
- the durability flag (def. false)
221 |
# File 'lib/qpid_messaging/message.rb', line 221 def durable=(durable); @message_impl.setDurable durable; end |
#message_id ⇒ Object
Returns the message id.
131 |
# File 'lib/qpid_messaging/message.rb', line 131 def ; @message_impl.getMessageId; end |
#message_id=(message_id) ⇒ Object
Sets the message id.
NOTE: this field must be a UUID type currently. A non-UUID value will be converted to a zero UUID, though a blank ID will be left untouched.
Options
-
id
- the id
Examples
# this example only works in Ruby >= 1.9, for 1.8 use a UUID library
require 'SecureRandom'
msg. = SecureRandom.uuid
128 |
# File 'lib/qpid_messaging/message.rb', line 128 def (); @message_impl.setMessageId .to_s; end |
#message_impl ⇒ Object
:nodoc:
46 47 48 |
# File 'lib/qpid_messaging/message.rb', line 46 def # :nodoc: @message_impl end |
#priority ⇒ Object
Returns the priority for the Message
.
189 |
# File 'lib/qpid_messaging/message.rb', line 189 def priority; @message_impl.getPriority; end |
#priority=(priority) ⇒ Object
Sets the priority of the Message
.
This may be used by the messaging infrastructure to prioritize delivery of messages with higher priority.
NOTE: If the priority is not an integer type then it is set using the object’s integer representation. If the integer value is greater than 8-bits then only the first 8-bits are used.
Options
-
priority
- the priority
186 |
# File 'lib/qpid_messaging/message.rb', line 186 def priority=(priority); @message_impl.setPriority priority; end |
#properties ⇒ Object
Returns all named properties.
NOTE: It is recommended to use the []= method for retrieving and setting properties. Using this method may result in non-deterministic behavior.
249 |
# File 'lib/qpid_messaging/message.rb', line 249 def properties; @message_impl.getProperties; end |
#redelivered ⇒ Object
Returns whether the Message
has been marked as redelivered.
242 |
# File 'lib/qpid_messaging/message.rb', line 242 def redelivered; @message_impl.getRedelivered; end |
#redelivered=(redelivered) ⇒ Object
This is a hint to the messaging infrastructure that if de-duplication is required, that this message should be examined to determine if it is a duplicate.
Options
-
redelivered
- sets the redelivered state (def. false)
Examples
# processed is a collection of messages already received
msg.redelivered = true if processed.include? msg.
239 |
# File 'lib/qpid_messaging/message.rb', line 239 def redelivered=(redelivered); @message_impl.setRedelivered redelivered; end |
#reply_to ⇒ Object
Returns the reply to address for the Message
.
73 74 75 76 77 |
# File 'lib/qpid_messaging/message.rb', line 73 def reply_to address_impl = @message_impl.getReplyTo # only return an address if a reply to was specified Qpid::Messaging::Address.new(nil, address_impl) if address_impl end |
#reply_to=(address) ⇒ Object
Sets the reply-to address.
The address can either be an instance of Address or else and address string.
Options
-
address
- the address
Examples
# set replies using an Address
msg.reply_to = Qpid:Messaging::Address.new "my-responses"
# set replies using an address string
msg.reply_to = "my-feed/responses"
66 67 68 69 70 |
# File 'lib/qpid_messaging/message.rb', line 66 def reply_to=(address) address = Qpid::Messaging::Address.new "#{address}" if !address.is_a? Qpid::Messaging::Address @message_impl.setReplyTo address.address_impl end |
#subject ⇒ Object
Returns the subject of the Message
.
87 |
# File 'lib/qpid_messaging/message.rb', line 87 def subject; @message_impl.getSubject; end |
#subject=(subject) ⇒ Object
Sets the subject for the Message
.
Options
-
subject
- the subject
84 |
# File 'lib/qpid_messaging/message.rb', line 84 def subject=(subject); @message_impl.setSubject subject; end |
#ttl ⇒ Object
Returns the time-to-live in milliseconds.
209 |
# File 'lib/qpid_messaging/message.rb', line 209 def ttl; Qpid::Messaging::Duration.new @message_impl.getTtl.getMilliseconds; end |
#ttl=(duration) ⇒ Object
Sets the time-to-live in milliseconds.
This can be used by the messaging infrastructure to discard messages that are no longer of relevance.
Options
-
duration
- the number of milliseconds
200 201 202 203 204 205 206 |
# File 'lib/qpid_messaging/message.rb', line 200 def ttl=(duration) if duration.is_a? Qpid::Messaging::Duration @message_impl.setTtl duration.duration_impl else @message_impl.setTtl Cqpid::Duration.new duration.to_i end end |
#user_id ⇒ Object
Returns the user id for the Message
.
151 |
# File 'lib/qpid_messaging/message.rb', line 151 def user_id; @message_impl.getUserId; end |
#user_id=(user_id) ⇒ Object
Sets the user id for the Message
.
This should in general be the user-id which was used when authenticating the connection itself, as the messaging infrastructure will verify this.
See Qpid::Messaging::Connection.authenticated_username
NOTE: If the id is not a String
then the id is set using the object’s string representation.
Options
-
id
- the id
148 |
# File 'lib/qpid_messaging/message.rb', line 148 def user_id=(user_id); @message_impl.setUserId user_id; end |