Class Qpid::Messaging::Message
In: qpid/ruby/lib/qpid_messaging/message.rb
Parent: Object

A Message represents an routable piece of information.

Methods

Public Class methods

Creates a Message.

Options

Examples

  # create a simple message and sends it
  message = Qpid::Messaging::Message.new :content => "This is a message."
  sender.send message

Public Instance methods

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]

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"

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.

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

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}

Returns the content‘s size in bytes.

Returns the content type for the Message.

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

Examples

  # send base64 encoded data in a mesage
  msg = Qpid::Messaging::Message.new :content = "UXBpZCBSdWxlcyEK"
  msg.content_type = "application/base64"

Returns the correlation id of the Message.

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

Returns the durability for the Message.

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)

Returns the message id.

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.message_id = SecureRandom.uuid

Returns the priority for the Message.

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

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.

Returns whether the Message has been marked as redelivered.

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

Examples

  # processed is a collection of messages already received
  msg.redelivered = true if processed.include? msg.message_id

Returns the reply to address for the Message.

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"

Returns the subject of the Message.

Sets the subject for the Message.

Options

Returns the time-to-live in milliseconds.

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

Returns the user id for the Message.

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

[Validate]