Version 1

    From JBoss Messaging Forum "Programmaticaly create queue"


    1. Get MBeanServer Connection
      JMXServiceURL u = new JMXServiceURL(
      JMXConnector c = JMXConnectorFactory.connect(u);     
      beanServerConnection = c.getMBeanServerConnection();

    2. Deploy a queue with servieName
      ObjectName objName = new ObjectName(
      beanServerConnection.invoke(objName, "deployQueue",
                              new Object[] { serviceName, null },
                              new String[] { "java.lang.String",
                                             "java.lang.String" });

      more configuration about ServerPeer, such as attribute and operations could be founed at JBoss Messaging User Guide

    3. Undeploy a queue
      beanServerConnection.invoke(objName, "undeployQueue",
                              new Object[] { serviceName },
                              new String[] { "java.lang.String" });

    4. Customize security to queues which created using the MBean

      you should define a  element first, such as following example:

          <role name="guest" read="true" write="true" create="true"/>
          <role name="publisher" read="true" write="true" create="false"/>
          <role name="durpublisher" read="true" write="true" create="true"/>

      then use setAttribute:

      Element element = stringToElement(security);
      Attribute attr = new Attribute("SecurityConfig", element);
      ObjectName queueName = new ObjectName(
        "jboss.messaging.destination:service=Queue,name=" + serviceName);
      beanServerConnection.setAttribute(objName, attr);
      More configuration about destination could be founded at Configuration Destinations