Module: javaxjavax.jms::Message

Defined in:
lib/jms/javax_jms_message.rb

Overview

Extend JMS Message Interface with Ruby methods

A Message is the item that can be put on a queue, or obtained from a queue.

A Message consists of 3 major parts:

- Header
  Accessible as attributes of the Message class
- Properties
  Accessible via [] and []= methods
- Data
  The actual data portion of the message
  See the specific message types for details on how to access the data
  portion of the message

For further help on javax.jms.Message

http://download.oracle.com/javaee/6/api/index.html?javax/jms/Message.html

Interface javax.jms.Message

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object

Get the value of a property



222
223
224
# File 'lib/jms/javax_jms_message.rb', line 222

def [](key)
  getObjectProperty key.to_s
end

#[]=(key, value) ⇒ Object

Set a property



227
228
229
# File 'lib/jms/javax_jms_message.rb', line 227

def []=(key, value)
  setObjectProperty(key.to_s, value)
end

#attributesObject

Return the attributes (header fields) of the message as a Hash



204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/jms/javax_jms_message.rb', line 204

def attributes
  {
    :jms_correlation_id => jms_correlation_id,
    :jms_delivery_mode => jms_delivery_mode,
    :jms_destination => jms_destination,
    :jms_expiration => jms_expiration,
    :jms_message_id => jms_message_id,
    :jms_priority => jms_priority,
    :jms_redelivered => jms_redelivered?,
    :jms_reply_to => jms_reply_to,
    :jms_timestamp => jms_timestamp,
    :jms_type => jms_type,
  }
end

#include?(key) ⇒ Boolean

Does message include specified property?

Returns:

  • (Boolean)


232
233
234
235
# File 'lib/jms/javax_jms_message.rb', line 232

def include?(key)
  # Ensure a Ruby true is returned
  property_exists key == true
end

#inspectObject



260
261
262
# File 'lib/jms/javax_jms_message.rb', line 260

def inspect
  "#{self.class.name}: #{data}\nAttributes: #{attributes.inspect}\nProperties: #{properties.inspect}"
end

#jms_correlation_idObject

Returns the Message correlation ID as a String The resulting string may contain nulls



98
99
100
# File 'lib/jms/javax_jms_message.rb', line 98

def jms_correlation_id
  String.from_java_bytes(getJMSCorrelationIDAsBytes) if getJMSCorrelationIDAsBytes
end

#jms_correlation_id=(correlation_id) ⇒ Object

Set the Message correlation ID

correlation_id: String

Also supports embedded nulls within the correlation id



105
106
107
# File 'lib/jms/javax_jms_message.rb', line 105

def jms_correlation_id=(correlation_id)
  setJMSCorrelationIDAsBytes(correlation_id.nil? ? nil : correlation_id.to_java_bytes)
end

#jms_delivery_modeObject

Return the JMS Delivery Mode as a symbol

:persistent
:non_persistent
other: Value from javax.jms.DeliveryMode


63
64
65
66
67
68
69
70
71
72
# File 'lib/jms/javax_jms_message.rb', line 63

def jms_delivery_mode
  case getJMSDeliveryMode
  when javax.jms.DeliveryMode::PERSISTENT
    :persistent
  when javax.jms.DeliveryMode::NON_PERSISTENT
    :non_persistent
  else
    getJMSDeliveryMode
  end
end

#jms_delivery_mode=(mode) ⇒ Object

Set the JMS Delivery Mode Valid values for mode

:persistent
:non_persistent
other: Any constant from javax.jms.DeliveryMode


79
80
81
82
83
84
85
86
87
88
89
# File 'lib/jms/javax_jms_message.rb', line 79

def jms_delivery_mode=(mode)
  val = case mode
  when :persistent
    javax.jms.DeliveryMode::PERSISTENT
  when :non_persistent
    javax.jms.DeliveryMode::NON_PERSISTENT
  else
    mode
  end
  self.setJMSDeliveryMode(val)
end

#jms_destinationObject

Returns the Message Destination

Instance of javax.jms.Destination


111
112
113
# File 'lib/jms/javax_jms_message.rb', line 111

def jms_destination
  getJMSDestination
end

#jms_destination=(destination) ⇒ Object

Set the Message Destination

jms_destination: Must be an instance of javax.jms.Destination


117
118
119
# File 'lib/jms/javax_jms_message.rb', line 117

def jms_destination=(destination)
  setJMSDestination(destination)
end

#jms_expirationObject

Return the message expiration value as an Integer



122
123
124
# File 'lib/jms/javax_jms_message.rb', line 122

def jms_expiration
  getJMSExpiration
end

#jms_expiration=(expiration) ⇒ Object

Set the Message expiration value

expiration: Integer


128
129
130
# File 'lib/jms/javax_jms_message.rb', line 128

def jms_expiration=(expiration)
  setJMSExpiration(expiration)
end

#jms_message_idObject

Returns the Message ID as a String The resulting string may contain embedded nulls



134
135
136
# File 'lib/jms/javax_jms_message.rb', line 134

def jms_message_id
  getJMSMessageID
end

#jms_message_id=(message_id) ⇒ Object

Set the Message correlation ID

message_id: String

Also supports nulls within the message id



141
142
143
# File 'lib/jms/javax_jms_message.rb', line 141

def jms_message_id=(message_id)
  setJMSMessageID(message_id)
end

#jms_priorityObject

Returns the Message Priority level as an Integer



146
147
148
# File 'lib/jms/javax_jms_message.rb', line 146

def jms_priority
  getJMSPriority
end

#jms_priority=(priority) ⇒ Object

Set the Message priority level

priority: Integer


152
153
154
# File 'lib/jms/javax_jms_message.rb', line 152

def jms_priority=(priority)
  setJMSPriority(priority)
end

#jms_redelivered=(bool) ⇒ Object

Set whether the Message was redelivered

bool: Boolean


163
164
165
# File 'lib/jms/javax_jms_message.rb', line 163

def jms_redelivered=(bool)
  setJMSPriority(bool)
end

#jms_redelivered?Boolean

Indicates whether the Message was redelivered?

Returns:

  • (Boolean)


157
158
159
# File 'lib/jms/javax_jms_message.rb', line 157

def jms_redelivered?
  getJMSRedelivered
end

#jms_reply_toObject

Returns the Message reply to Destination

Instance of javax.jms.Destination


169
170
171
# File 'lib/jms/javax_jms_message.rb', line 169

def jms_reply_to
  getJMSReplyTo
end

#jms_reply_to=(reply_to) ⇒ Object

Set the Message reply to Destination

reply_to: Must be an instance of javax.jms.Destination


175
176
177
# File 'lib/jms/javax_jms_message.rb', line 175

def jms_reply_to=(reply_to)
  setJMSReplyTo(reply_to)
end

#jms_timestampObject

Returns the Message timestamp as Java Timestamp Integer TODO Return Ruby Time object?



181
182
183
# File 'lib/jms/javax_jms_message.rb', line 181

def jms_timestamp
  getJMSTimestamp
end

#jms_timestamp=(timestamp) ⇒ Object

Set the Message reply to Destination

timestamp: Must be an Java Timestamp Integer

TODO Support Ruby Time



188
189
190
# File 'lib/jms/javax_jms_message.rb', line 188

def jms_timestamp=(timestamp)
  setJMSTimestamp(timestamp)
end

#jms_typeObject

Returns the Message type supplied by the client when the message was sent



193
194
195
# File 'lib/jms/javax_jms_message.rb', line 193

def jms_type
  getJMSType
end

#jms_type=(type) ⇒ Object

Sets the Message type

type: String


199
200
201
# File 'lib/jms/javax_jms_message.rb', line 199

def jms_type=(type)
  setJMSType(type)
end

#persistent?Boolean

Is the message persistent?

Returns:

  • (Boolean)


92
93
94
# File 'lib/jms/javax_jms_message.rb', line 92

def persistent?
  getJMSDeliveryMode == javax.jms.DeliveryMode::PERSISTENT
end

#propertiesObject

Return Properties as a hash



238
239
240
241
242
# File 'lib/jms/javax_jms_message.rb', line 238

def properties
  h = {}
  properties_each_pair {|k,v| h[k]=v}
  h
end

#properties=(h) ⇒ Object

Set Properties from an existing hash



245
246
247
248
249
# File 'lib/jms/javax_jms_message.rb', line 245

def properties=(h)
  clear_properties
  h.each_pair {|k,v| setObjectProperty(k.to_s, v)}
  h
end

#properties_each_pair(&proc) ⇒ Object

Return each name value pair



252
253
254
255
256
257
258
# File 'lib/jms/javax_jms_message.rb', line 252

def properties_each_pair(&proc)
  enum = getPropertyNames
  while enum.has_more_elements
    key = enum.next_element
    proc.call key, getObjectProperty(key)
  end
end