O'Reilly - Java Message Service
O'Reilly - Java Message Service
O'Reilly - Java Message Service
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
...<br />
...<br />
<br />
<br />
Hot Deals Topic<br />
jms/HotDeals<br />
javax.jms.Topic<br />
<br />
<strong>Java</strong> <strong>Message</strong> <strong>Service</strong><br />
When the component is deployed, the J2EE vendor tools generate code to translate the<br />
JNDI ENC resource references into JMS-administered objects. This translation is done<br />
when the bean is deployed using administration tools.<br />
Any J2EE component can access JMS connection factories and destinations using the<br />
JNDI ENC. As an example, the Wholesaler client can be rewritten as a stateless session<br />
bean that uses the JNDI ENC to obtain a JMS connection factory and destination:<br />
public class WholesalerBean implements javax.ejb.SessionBean{<br />
}<br />
...<br />
public void setSessionContext(SessionContext cntx){<br />
try {<br />
InitialContext jndiEnc = new InitialContext( );<br />
TopicConnectionFactory factory = (TopicConnectionFactory)<br />
jndiEnc.lookup("java:comp/env/jms/broker");<br />
connect = factory.createTopicConnection (username, password);<br />
session =<br />
connect.createTopicSession(false,Session.AUTO_ACKNOWLEDGE);<br />
hotDealsTopic=(Topic)<br />
jndiEnc.lookup("java:comp/env/jms/HotDeals");<br />
publisher = session.createPublisher(hotDealsTopic);<br />
...<br />
}<br />
...<br />
}<br />
public void publishPriceQuotes(String dealDesc, String username,<br />
String itemDesc, float oldPrice,<br />
float newPrice){<br />
try {<br />
javax.jms.Stream<strong>Message</strong> message =<br />
session.createStream<strong>Message</strong>( );<br />
message.writeString(dealDesc);<br />
...<br />
publisher.publish(<br />
message,<br />
javax.jms.DeliveryMode.PERSISTENT,<br />
javax.jms.<strong>Message</strong>.DEFAULT_PRIORITY,<br />
1800000);<br />
} catch ( javax.jms.JMSException jmse ){<br />
jmse.printStackTrace( );<br />
}<br />
}<br />
...<br />
127