O'Reilly - Java Message Service
O'Reilly - Java Message Service
O'Reilly - Java Message Service
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
publisher.publish(message);<br />
...<br />
// A message consumer reads the properties<br />
String name = (String)message.getObjectProperty("username");<br />
Double limit = (Double)message.setObjectProperty("Limit");<br />
Boolean isApproved = (Boolean)message.setObjectProperty("IsApproved");<br />
C.3 Read-Only Properties<br />
<strong>Java</strong> <strong>Message</strong> <strong>Service</strong><br />
Once a message is produced (sent), its properties become read-only; the properties cannot<br />
be changed. While consumers can read the properties using the property accessor methods<br />
(getProperty( )), they cannot modify the properties using any of the mutator<br />
methods (setProperty( )). If the consumer attempts to set a property, the mutator<br />
method throws a javax.jms.<strong>Message</strong>NotWriteableException.<br />
Once a message is received, the only way its properties can be changed is by clearing out<br />
all the properties using the clearProperties( ) method. This removes all the properties<br />
from the message so that new ones can be added. Individual properties cannot be modified<br />
or removed once a message is sent.<br />
C.4 Property Value Conversion<br />
The JMS specification defines rules for conversion of property values, so that, for<br />
example, a property value of type int can be read as a long:<br />
<strong>Message</strong> message = topicSession.create<strong>Message</strong>( );<br />
// Set the property "Age" as an int value<br />
message.setIntProperty("Age", 72);<br />
...<br />
// Read the property "Age" as a long is legal<br />
long age = message.getLongProperty("Age");<br />
The conversion rules are fairly simple, as shown in Table C.1. A property value can be set<br />
as one primitive type or String, and read as one of the other value types.<br />
Table C.1. Property Type Conversions<br />
<strong>Message</strong>.setProperty( ) <strong>Message</strong>.getProperty( )<br />
boolean boolean, String<br />
byte byte, short, int, long, String<br />
short short, int, long, String<br />
int int, long, String<br />
long long, String<br />
float float, double, String<br />
double double, String<br />
String<br />
String, boolean, byte, short, int, long, float,<br />
double<br />
169