import javax.jms.*;
import javax.naming.*;
public class Browser {
public static void main( String[] args ) {
Connection connection = null;
...
try {
java.util.Hashtable env = new java.util.Hashtable( );
env.put ( javax.naming.Context.INITIAL_CONTEXT_FACTORY ,
"com.fujitsu.interstage.j2ee.jndi.InitialContextFactoryForClient" );
InitialContext initialContext = new InitialContext(env); /* 1 */
ConnectionFactory connectionFactory = (ConnectionFactory)
initialContext.lookup("java:comp/env/jms/ConnectionFactory"); /* 2 */
Queue queue = (Queue)initialContext.lookup("java:comp/env/jms/Queue"); /* 3 */
connection = connectionFactory.createConnection(); /* 4 */
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); /* 5 */
QueueBrowser queueBrowser = session.createBrowser(queue); /* 6 */
connection.start(); /* 7 */
java.util.Enumeration e = queueBrowser.getEnumeration(); /* 8 */
Message message;
while ( e.hasMoreElements() ) {
message = (Message)e.nextElement(); /* 9 */
...
}
queueBrowser.close(); /* 10 */
} catch( Exception e ) {
...
}
finally {
if( null != connection ) {
try {
connection.close(); /* 11 */
}
catch( Exception e ) {
...
}
}
}
}
} |