Context myContext = new InitialContext();
Topic stockTopic = (Topic) myContext.lookup("StockTopic");
TopicConnectionFactory myFactory =
(TopicConnectionFactory)myContext.lookup("MyProvider");
TopicConnection myConnection = myFactory.createTopicConnection();
TopicSession mySession =
myConnection.createTopicSession(false,
Session.AUTO_ACKNOWLEDGE);
TopicSubscriber mySubscriber =
mySession.createSubscriber(stockTopic);
StockListener myListener;
mySubscriber.setMessageListener(myListener);
...
class StockListener implements MessageListener {
void onMessage(Message stockQuote) {
String stockName = stockQuote.getString("Name");
Double stockValue = stockQuote.getString("Value");
...