Obtaining a reference to the ConnectionFactory and Destination through JNDI.

Enterprise Java
Guarantee Inter-Enterprise Message Delivery Using JMS
Gopalan Suresh Raj
Listing 1. Obtaining a reference to the ConnectionFactory and Destination through JNDI.


//  Create the InitialContext Object used for looking up
//  JMS administered objects on the Messaging Server
//  located on the default host.
javax.naming.Context initialCtx = new javax.naming.InitialContext();
initialCtx.bind ();

// Lookup Connection Factory
  javax.jms.TopicConnectionFactory  factory =
 (javax.jms.TopicConnectionFactory)initialCtx.lookup("primaryCF");

// Lookup the Destination Topic
Topic topic = (Topic)initialCtx.lookup ("Nasdaq_Topic");