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.
import javax.jms.TopicConnectionFactory;<br />
import javax.jms.QueueConnectionFactory;<br />
import javax.jms.Topic;<br />
import javax.jms.Queue;<br />
import javax.jms.Session;<br />
import javax.jms.Stream<strong>Message</strong>;<br />
import javax.jms.Text<strong>Message</strong>;<br />
public class QRetailer implements javax.jms.<strong>Message</strong>Listener {<br />
private javax.jms.QueueConnection qConnect = null;<br />
private javax.jms.QueueSession qSession = null;<br />
private javax.jms.QueueSender qSender = null;<br />
private javax.jms.TopicConnection tConnect = null;<br />
private javax.jms.TopicSession tSession = null;<br />
private javax.jms.Topic hotDealsTopic = null;<br />
private javax.jms.TopicSubscriber tsubscriber = null;<br />
private static boolean useJNDI = false;<br />
private static String uname = null;<br />
public QRetailer( String broker, String username, String password){<br />
try {<br />
TopicConnectionFactory tFactory = null;<br />
QueueConnectionFactory qFactory = null;<br />
InitialContext jndi = null;<br />
uname = username;<br />
Properties env = new Properties( );<br />
// ... specify the JNDI properties specific to the vendor<br />
jndi = new InitialContext(env);<br />
tFactory =<br />
(TopicConnectionFactory)jndi.lookup(broker);<br />
qFactory =<br />
(QueueConnectionFactory)jndi.lookup(broker);<br />
tConnect =<br />
tFactory.createTopicConnection (username, password);<br />
qConnect =<br />
qFactory.createQueueConnection (username, password);<br />
tConnect.setClientID(username);<br />
qConnect.setClientID(username);<br />
tSession =<br />
tConnect.createTopicSession(false,<br />
Session.AUTO_ACKNOWLEDGE);<br />
qSession =<br />
qConnect.createQueueSession(false,<br />
javax.jms.Session.AUTO_ACKNOWLEDGE);<br />
hotDealsTopic = (Topic)jndi.lookup("Hot Deals");<br />
tsubscriber =<br />
tSession.createDurableSubscriber(hotDealsTopic,<br />
"Hot Deals Subscription");<br />
tsubscriber.set<strong>Message</strong>Listener(this);<br />
tConnect.start( );<br />
} catch (javax.jms.JMSException jmse){<br />
jmse.printStackTrace( );<br />
System.exit(1);<br />
} catch (javax.naming.NamingException jne){<br />
jne.printStackTrace( ); System.exit(1);<br />
}<br />
}<br />
public void on<strong>Message</strong>(javax.jms.<strong>Message</strong> a<strong>Message</strong>){<br />
try {<br />
autoBuy(a<strong>Message</strong>);<br />
<strong>Java</strong> <strong>Message</strong> <strong>Service</strong><br />
72