5 Replies Latest reply on Jan 7, 2004 2:29 PM by Adrian Brock

    Dynamic topic creation in a client app.

    Steve Jenkings Newbie

      I'm trying to run a client to the JBoss server (3.0.3) using only the MQ part of the server and I'd like the client to be able to dynamically create topics.

      Once I get so far as to have a TopicSession object I should in theory be able to call the createTopic(topicName) method, however, this throws an exception within the server like...

      javax.jms.JMSException: This destination does not exist !
      at JMSDestinationManager.createTopic(JMSDestinationManager.java:702)
      etc.

      The only way I can actually make this method call successfully is to call createTopic(topicName) where topicName is the name of a topic that already exists within the server; e.g. testTopic.

      I've looked at the code and cannot see how it is possible for this method to ever successfully create a new topic. Can anyone offer any advice please?

        • 1. Re: Dynamic topic creation in a client app.
          Terry Rosenbaum Newbie

          The JMS spec says that topic and queue
          creation (except for TemporaryTopic and
          TemporaryQueue) is outside the scope
          of the spec. Creation of "permanent"
          topics and queues is an administrative
          task. I'm pretty sure that there are JBoss
          ways to perform such administrative tasks
          from your program, but I can't tell you how
          to do it (because I don't know how myself:).
          The createTopic method allows you to create
          an object representing an already-existing Topic
          only. You can create a TemporaryTopic using the
          JMS API -- perhaps that will suffice for your needs.

          • 2. Re: Dynamic topic creation in a client app.
            Thomas J. Harris Newbie


            import javax.jms.*;
            import javax.management.*;
            import javax.naming.*;
            import org.jboss.jmx.adaptor.rmi.*;

            ... From class members ...

            private InitialContext _jndiContext = null;

            ...

            ... From constructor ...
            Hashtable env = new Hashtable();
            env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
            env.put(Context.PROVIDER_URL, "jnp://192.168.2.2:1099/");
            _jndiContext = new InitialContext(env);
            ...

            private Topic getOrCreateTopic(String name) throws EventTransportException {
            Topic endResult = null;
            System.out.println("EventTransportJBossJMSImpl: Trying to acquire topic '" + name + "'...");
            try {
            try {
            endResult = (Topic)_jndiContext.lookup("topic/" + name);
            System.out.println("EventTransportJBossJMSImpl: Found existing topic '" + name + "'.");
            return endResult;
            } catch(NamingException ne) {
            System.out.println("EventTransportJBossJMSImpl: Creating new topic '" + name + "'...");
            RMIAdaptor jmxAccess = (RMIAdaptor)_jndiContext.lookup("jmx/rmi/RMIAdaptor");
            ObjectName objName = new ObjectName("jboss.mq:service=DestinationManager");
            String[] signature = {"java.lang.String"};
            Object[] arguments = {name};
            Object result = jmxAccess.invoke(objName, "createTopic", arguments, signature);
            endResult = (Topic)_jndiContext.lookup("topic/" + name);
            System.out.println("EventTransportJBossJMSImpl: New topic '" + name + "' was created.");
            return endResult;
            }
            } catch(Exception e) {
            throw new EventTransportException(e);
            }
            }

            • 3. Re: Dynamic topic creation in a client app.
              Thomas J. Harris Newbie


              import javax.jms.*;
              import javax.management.*;
              import javax.naming.*;
              import org.jboss.jmx.adaptor.rmi.*;

              ... From class members ...

              private InitialContext _jndiContext = null;

              ...

              ... From constructor ...
              Hashtable env = new Hashtable();
              env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
              env.put(Context.PROVIDER_URL, "jnp://192.168.2.2:1099/");
              _jndiContext = new InitialContext(env);
              ...

              private Topic getOrCreateTopic(String name) throws EventTransportException {
              Topic endResult = null;
              System.out.println("EventTransportJBossJMSImpl: Trying to acquire topic '" + name + "'...");
              try {
              try {
              endResult = (Topic)_jndiContext.lookup("topic/" + name);
              System.out.println("EventTransportJBossJMSImpl: Found existing topic '" + name + "'.");
              return endResult;
              } catch(NamingException ne) {
              System.out.println("EventTransportJBossJMSImpl: Creating new topic '" + name + "'...");
              RMIAdaptor jmxAccess = (RMIAdaptor)_jndiContext.lookup("jmx/rmi/RMIAdaptor");
              ObjectName objName = new ObjectName("jboss.mq:service=DestinationManager");
              String[] signature = {"java.lang.String"};
              Object[] arguments = {name};
              Object result = jmxAccess.invoke(objName, "createTopic", arguments, signature);
              endResult = (Topic)_jndiContext.lookup("topic/" + name);
              System.out.println("EventTransportJBossJMSImpl: New topic '" + name + "' was created.");
              return endResult;
              }
              } catch(Exception e) {
              throw new EventTransportException(e);
              }
              }

              • 4. Re: Dynamic topic creation in a client app.
                Mark Newbie

                This is exactly what I need. However when I try the solution given by tharrisx I get a "NameNotFoundException: jmx not bound"

                Do I need to do something to make the lookup of jmx/rmi/RMIAdapter to work?

                Is there some step I need to do prior to the given example to bind JMX?

                Any help would be greatly appreciated.

                • 5. Re: Dynamic topic creation in a client app.
                  Adrian Brock Master

                  It might not be bound at the location given in 3.0.3

                  I wouldn't recommend using jbossmq in 3.0.3 there are too many
                  memory leaks in that version.

                  Use 3.0.8

                  Regards,
                  Adrian