6 Replies Latest reply on Apr 29, 2009 12:02 AM by maxogm

    JBoss 5.0.1, how to create new topic

    maxogm

      Hello...
      I need to create new topic in Jboss 5.0.1 from java applications. Did someone know how to do this.

      In Jboss 4.0.1sp1 I do this using next method in Java:

      private void createTopic(String topicName) throws NamingException, InstanceNotFoundException, MBeanException, ReflectionException, IOException {
       Properties props = new Properties();
       props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
       props.put(Context.PROVIDER_URL, "jnp://localhost:1099");
      
       InitialContext iniCtx = new InitialContext(props);
      
       try{
       iniCtx.lookup("topic/" + topicName + "");
       }catch (NameNotFoundException e) {
       ObjectName destinationManager = ObjectNameFactory.create("jboss.mq:service=DestinationManager");
       RMIAdaptor server = null;
       server = (RMIAdaptor) iniCtx.lookup("jmx/invoker/RMIAdaptor");
       server.invoke(destinationManager, "createTopic", new Object[] { topicName, "topic/" + topicName }, new String[] {
       String.class.getName(), String.class.getName() });
       }
       }
      
      


      I try to modificate previous code to work with Jboss 5.0.1GA, but I not success. Sorry on very bad English.

        • 1. Re: JBoss 5.0.1, how to create new topic
          gaohoward
          • 2. Re: JBoss 5.0.1, how to create new topic
            maxogm

            OK, I saw that...
            But I dont known how to use ServerPeer to deploy topic.
            If someone has an example.

            Thanks

            • 3. Re: JBoss 5.0.1, how to create new topic
              gaohoward

              You can have a look at the JBM examples source, especially this file:

              examples/common/src/org/jboss/example/jms/common/Util.java
              the deployQueue() method.

              • 4. Re: JBoss 5.0.1, how to create new topic
                maxogm

                I try that example yesterday, and always I got

                Unable to find operation createQueue(java.lang.String,java.lang.String)
                


                This is my example:
                package com.jboss.test;
                
                import java.util.Properties;
                
                import javax.management.MBeanServerConnection;
                import javax.management.ObjectName;
                import javax.naming.Context;
                import javax.naming.InitialContext;
                import javax.naming.NameNotFoundException;
                
                
                public class MakeQueue {
                
                 public static void main(String[] args) throws Exception {
                
                 Properties props = new Properties();
                 props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
                 props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");
                 props.put(Context.PROVIDER_URL, "jnp://localhost:1100");
                
                 InitialContext iniCtx = new InitialContext(props);
                
                 try{
                 iniCtx.lookup("queue/test");
                 }catch (NameNotFoundException e) {
                
                
                 MBeanServerConnection mBeanServer = lookupMBeanServerProxy(iniCtx);
                
                 ObjectName serverObjectName = new ObjectName("jboss.messaging:service=ServerPeer");
                
                 String queueName = "test";
                
                 mBeanServer.invoke(serverObjectName, "createQueue",
                 new Object[] {queueName, "queue/test"},
                 new String[] {"java.lang.String", "java.lang.String"});
                
                 }
                 }
                
                 private static MBeanServerConnection lookupMBeanServerProxy(InitialContext ic) throws Exception
                 {
                 if (ic == null)
                 {
                 ic = new InitialContext();
                 }
                 return (MBeanServerConnection)ic.lookup("jmx/invoker/RMIAdaptor");
                 }
                
                }
                


                In build path I include all jar from JBoss 5.0.1/client and jboss-messaging.jar

                • 5. Re: JBoss 5.0.1, how to create new topic
                  gaohoward

                  Sorry, the operation name should be 'deployQueue', not 'createQueue'.

                  • 6. Re: JBoss 5.0.1, how to create new topic
                    maxogm

                    Works

                    Thanks