March 2002
Intermediate to advanced
320 pages
8h 58m
English
At this point, handling messaging from the client perspective is a
piece of cake. It’s simply a matter of connecting to
the messaging service (through your application
server’s messaging middleware) and listening to a
specific Topic or Queue. To
ensure that you can get some sample code up and running to see how
this works, I’ve included Example 9-5, a simple listener class.
Example 9-5. The JMSTester Class
package com.forethought.client; import java.util.Date; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageListener; import javax.jms.ObjectMessage; import javax.jms.Session; import javax.jms.TextMessage; import javax.jms.Topic; import javax.jms.TopicConnection; import javax.jms.TopicConnectionFactory; import javax.jms.TopicSession; import javax.jms.TopicSubscriber; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; // Event bean import com.forethought.ejb.event.EventInfo; // User bean import com.forethought.ejb.user.UserInfo; public class JMSTester implements MessageListener { public JMSTester(String factoryName, String topicName) throws JMSException, NamingException { Context context = getInitialContext( ); // Get topic factory TopicConnectionFactory factory = (TopicConnectionFactory)context.lookup(factoryName); Topic topic = (Topic)context.lookup(topicName); // Connect to topic TopicConnection connection = factory.createTopicConnection( ); // Send off notification of this ...Read now
Unlock full access