4 Replies Latest reply on Mar 9, 2013 9:22 AM by Johannes Bannhofer

    JBoss7 JMS (HornetQ) get queue names, control queues

    Johannes Bannhofer Newbie

      Hi All,

       

      I need to get all JMS queues on my JB7 and control them (pause, resume, clear).

       

      My first attempt was to access it with via JNDI and use the standard JMS interfaces, but I coulndn't find the needed functionallity there:
      
      Connection connection = null;
      Session session = null;
      
      LOG.info("ConnectionFactory: <%s>", connectionFactory);
      
      connection = connectionFactory.createConnection();
      LOG.info("Connection: <%s>", connection);
      
      session = connection.createSession(true, 0);
      session.createQueue("testx");
      

      I can only create queues there ...

       

      My second approch was to use the HornetQ APIs via JMS , in the example I tried to get the number ob messages in a queue with help of the management queue:

       

      connection = connectionFactory.createConnection();
      LOG.info("Connection: <%s>", connection);
      
      session = connection.createSession(true, 0);
      
      //            Queue managementQueue = HornetQJMSClient.createQueue("hornetq.management");
      
      Queue managementQueue = HornetQJMSClient.createQueue("hornetq.management");
      
      //        QueueRequestor requestor = new QueueRequestor((QueueSession) session, managementQueue);
      QueueRequestor requestor = new QueueRequestor((QueueSession) session, managementQueue);
      connection.start();
      Message message = session.createMessage();
      //            Message m = session.createMessage();
      //          JMSManagementHelper.putOperationInvocation(m,
      //              "jms.queue.exampleQueue",
      //              "removeMessages","*");
      message.setStringProperty("jobs_planning", "messageCount");
      

       

      This code I startet within a EJB on the server side, but there i get the following error:

       

      ERROR 15:31:35.039 ||  [219] (KiQueueTesting.java:98)        
      Error in Queue Control
      
      javax.jms.InvalidDestinationException: Not a HornetQ Destination:HornetQQueue[hornetq.management]
      
      org.hornetq.jms.client.HornetQSession.createProducer(HornetQSession.java:324)
      
      org.hornetq.jms.client.HornetQSession.createSender(HornetQSession.java:828)
      
      javax.jms.QueueRequestor.<init>(QueueRequestor.java:45)
      
      com.knapp.cardiff.queuing.KiQueueTesting.printQueueFactory(KiQueueTesting.java:76)
      
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      
      sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      
      java.lang.reflect.Method.invoke(Method.java:601)
      
      com.knapp.cardiff.core.test.server.core.tunnel.executor.KiEjbExecutor.invoke(KiEjbExecutor.java:48)
      
      com.knapp.cardiff.core.remoting.tunnel.execution.KiRemoteExecution.invoke(KiRemoteExecution.java:85)
      
      com.knapp.cardiff.core.remoting.tunnel.ws.KiRemoteTunnelWs.invoke(KiRemoteTunnelWs.java:45)
      
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      
      sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      
      java.lang.reflect.Method.invoke(Method.java:601)
      
      org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47)
      
      org.jboss.as.webservices.invocation.AbstractInvocationHandlerEJB.invoke(AbstractInvocationHandlerEJB.java:112)
      
      org.jboss.wsf.stack.cxf.JBossWSInvoker._invokeInternal(JBossWSInvoker.java:181)
      
      org.jboss.wsf.stack.cxf.JBossWSInvoker.invoke(JBossWSInvoker.java:127)
      
      org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
      
      java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
      
      java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
      
      java.util.concurrent.FutureTask.run(FutureTask.java:166)
      
      org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
      
      org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:106)
      
      org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
      
      org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
      
      org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:207)
      
      org.jboss.wsf.stack.cxf.RequestHandlerImpl.handleHttpRequest(RequestHandlerImpl.java:91)
      
      org.jboss.wsf.stack.cxf.transport.ServletHelper.callRequestHandler(ServletHelper.java:169)
      
      org.jboss.wsf.stack.cxf.CXFServletExt.invoke(CXFServletExt.java:87)
      
      org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:185)
      
      org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:108)
      
      javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
      
      org.jboss.wsf.stack.cxf.CXFServletExt.service(CXFServletExt.java:135)
      
      org.jboss.wsf.spi.deployment.WSFServlet.service(WSFServlet.java:140)
      
      javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
      
      org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
      
      org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
      
      org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
      
      org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
      
      org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)
      
      org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
      
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      
      org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)
      
      org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
      
      org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)
      
      org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)
      
      java.lang.Thread.run(Thread.java:722)
      
      

       

      I tried it according to:

      http://docs.jboss.org/hornetq/2.3.0.CR1/docs/user-manual/html/management.html#management.jms

       

       

      Can anyone please give me an example how to get all queuenames and how to connect to the hornetq management API?

       

      best regards Johannes