Interview Questions

Why does JMSSession.createTopic or JMSSession.createQueue fail to create a destination in WLS JMS 6.1 (it worked in 5.1)?

BEA WebLogic Questions and Answers


(Continued from previous question...)

Why does JMSSession.createTopic or JMSSession.createQueue fail to create a destination in WLS JMS 6.1 (it worked in 5.1)?

In WLS 5.1 createTopic() or createQueue() creates the destination permanently in the database if it doesn't already exist, but does not modify the weblogic.properties file.
According to the JavaSoft JMS specification version 1.0.2 regarding createQueue() and createTopic(), they are not for creating destinations dynamically. They are used to retrieve the destination referenced by using a string name instead of using JNDI lookup. The destination has to be in your config.xml file first. This change is documented in WLS 6.0 since it behaves differently than the previous release. You can use the WLS JMS helper class (weblogic.jms.extensions.JMSHelper) or the console to create destinations at the run time (note that there was a bug in 6.0 that caused a problem when the server restarted; this is fixed in Service Pack 1). These mechanisms create the destination and also modify the configuration file.
For more information on the JMSHelper classes, see the subsection called Creating Destinations Dynamically in Programming WebLogic JMS.

The following program creates a Topic.

    import java.io.*;
    import java.util.Hashtable;
    import javax.jms.*;
    import javax.naming.*;
    import weblogic.jms.extensions.JMSHelper;


    class t {
    public final static String 
    JNDI_FACTORY="weblogic.jndi.WLInitialContextFactory";
    public final static String JMS_SERVER_NAME="TestJMSServer";
    public final static String DEST_JNDI_PREFIX="javax.destination.";


    static public void main(String [] args) throws Exception {
    try {
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
    env.put(Context.PROVIDER_URL, "t3://localhost:7001");
    Context ctx = new InitialContext(env);


    String topicName = "JMSHelperTestQueue01";
    String topicJNDI = DEST_JNDI_PREFIX + topicName;
    System.out.println("topic name=" + topicName + ", jndi=" + 
    topicJNDI);
    JMSHelper.createPermanentTopicAsync(ctx, JMS_SERVER_NAME, 
    topicName,
    topicJNDI);
    } catch (JMSException e) {
    e.printStackTrace();
          }
       }
    }

(Continued on next question...)

Other Interview Questions