7 Replies Latest reply on Mar 12, 2012 2:23 PM by marklevesque

    Dynamic Topic creation under JBoss6

      Hello,

      I can't find info on creating topics dynamically under hornetQ / JBoss7 other than vague reference to JMSDestinationManager (which I can't find any good docs on). Any one have a link to some good relevant docs or, even better, some example code for creating topics dynamically?

      Thanks.

      Mark

        • 1. Re: Dynamic Topic creation under JBoss6
          ataylor

          JMSServerControl.createTopic(.....), see the management section in the user manual

          • 2. Re: Dynamic Topic creation under JBoss6

            Thanks Andy,

            That's got me started in the right direction. But I'm kind of spinning my wheels on the management javadocs which seem to only describe abstract interfaces. Can you point me to a good starting point in the docs or a good example code listing?

            Many thanks.

            • 3. Re: Dynamic Topic creation under JBoss6
              ataylor

              take a look at one of the management examples, just replace the control object with the one you want

              • 4. Re: Dynamic Topic creation under JBoss6

                Hi Andy,

                 

                I see "src/org/hornetq/jms/example/ManagementExample.java" which uses the management API to interface to the existing "exampleQueue" called out in "server0/hornetq-jms.xml", but I can't find any examples of using the management API to actually create a queue/topic dynamically. Is there an example of that in the hornetQ 2.2.5 examples?

                 

                Thanks,

                Mark

                • 5. Re: Dynamic Topic creation under JBoss6
                  ataylor

                  Yes, you can just change that example to look up the JMSServerControl object instead of the queue and call which ever method you want. Saying that ive just noticed that you are using JBosss 7 which means you should probably use the AS7 Management API, take a look at https://github.com/jbossas/jboss-as/blob/master/testsuite/integration/smoke/src/test/java/org/jboss/as/test/smoke/embedded/demos/client/messaging/MessagingClientTestCase.java

                  • 6. Re: Dynamic Topic creation under JBoss6
                    tuxilla

                    The link is broken

                    • 7. Re: Dynamic Topic creation under JBoss6

                      I was able to do what I wanted (create dynamic topic in Jboss6) by the following method:

                       

                      // required inports

                      import javax.jms.QueueRequestor;

                      import javax.jms.QueueConnectionFactory;

                      import javax.jms.QueueConnection;

                      import org.hornetq.api.jms.HornetQJMSClient;

                      import org.hornetq.api.jms.management.JMSManagementHelper;

                       

                      // dynamic topic creation code

                      String jndiName = "newTopic";

                      QueueConnectionFactory connectionFactory = (QueueConnectionFactory) jmsContext.lookup("/ConnectionFactory");

                      QueueConnection connection = connectionFactory.createQueueConnection();

                      Queue managementQueue = HornetQJMSClient.createQueue("hornetq.management");

                      QueueSession session = (QueueSession) connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

                      connection.start();

                      Message m = session.createMessage();

                      JMSManagementHelper.putOperationInvocation(m, "jms.server", "createTopic", jndiName);

                      QueueRequestor requestor = new QueueRequestor(session, managementQueue);

                      Message reply = requestor.request(m);

                      logInfo("result of topic creation request for <" + jndiName + ">= " + JMSManagementHelper.hasOperationSucceeded(reply));

                       

                      For this to work, you must allow the user running the code to have 'manage' privileges in "jboss-6.1.0.Final/server/default/deploy/hornetq/hornetq-configuration.xml".

                      Or you can do what I did as a temporary measure and just disable security as follows in "hornetq-configuration.xml":

                       

                      <!-- Removed to allow creation of dynamic topics

                         <security-settings>

                            <security-setting match="#">

                               <permission type="createNonDurableQueue" roles="guest"/>

                               <permission type="deleteNonDurableQueue" roles="guest"/>

                               <permission type="consume" roles="guest"/>

                               <permission type="send" roles="guest"/>

                            </security-setting>

                         </security-settings>

                      -->

                       

                         <security-enabled>false</security-enabled>