3 Replies Latest reply on May 1, 2003 9:07 AM by Adrian Brock

    Looking for example  for how to create a JMS queue from an a

    Rob Tan Newbie

      Can anyone point me to an example of how to create a queue dynamically from an application? The doc mentions using the Destination Manager's MBean createQueue method -- but there was no example for how this is actually invoked from an application.

      I tried the following but got a null pointer exception:

      try {
      new DestinationManager().createQueue ("Rich", "queue/MyDynamicQ");
      } catch (Exception e) {
      e.printStackTrace();
      }

        • 1. Re: Looking for example  for how to create a JMS queue from
          Adrian Brock Master

          You do it through the MBeanServer.

          MBeanServer server = (MBeanServer) MBeanServerFactory.findMBeanServer().get(0);
          server.invoke
          (
          new ObjectName("jboss.mq:service=DestinationManager"),
          "createQueue",
          new Object[] { "MyDynamicQ" },
          new String[] {String.class.getName() }
          );

          Regards,
          Adrian

          • 2. Re: Looking for example  for how to create a JMS queue from
            schoeto Newbie

            I tried this example and I could not get it to work. When I do any of the following I get an ArrayList with 0 elements.

            ArrayList servers = MBeanServerFactory.findMBeanServer(null);

            ArrayList servers = MBeanServerFactory.findMBeanServer("");

            or

            ArrayList servers = MBeanServerFactory.findMBeanServer((String)properties.get("java.naming.provider.url"));

            My JBoss instance is running on another machine. Do I need to use JNDI to look this up?

            here's my code:

            try {
            ArrayList servers = MBeanServerFactory.findMBeanServer();
            if (servers==null) {
            System.out.println("No MBean servers found...");
            } else {
            System.out.println("server count: "+servers.size());
            if (servers.size()>0) {
            MBeanServer server = (MBeanServer)servers.get(0);
            server.invoke (
            new ObjectName("jboss.mq:service=DestinationManager"),
            "createQueue",
            new Object[] { "MyDynamicQ" },
            new String[] {String.class.getName() }
            );
            }
            }

            Regards,
            Tony Schoenbachler

            • 3. Re: Looking for example  for how to create a JMS queue from
              Adrian Brock Master

              you need to use a jmx connector or adaptor.

              Regards,
              Adrian