7 Replies Latest reply on Jun 24, 2014 11:39 AM by Mickaël PURET

    removeMessages :: Not a HornetQ Destination

    Mickaël PURET Newbie

      Hello

       

      I'm blocked on method to clear a JMS queue. Could you help me ?

       

      Thanks.

       

      Mickaël

       

      Logs :

      16:07:38,625 INFO  [stdout] (http--127.0.0.1-8080-1) Start clearing MyQueue

      16:07:38,641 INFO  [stdout] (http--127.0.0.1-8080-1) //!!!!\\ createQueue

      16:07:38,672 INFO  [stdout] (http--127.0.0.1-8080-1) //!!!!\\ queueSession

      16:07:38,765 INFO  [stdout] (http--127.0.0.1-8080-1) //!!!!\\ requestor

      16:07:38,765 INFO  [stdout] (http--127.0.0.1-8080-1) Error during clearing MyQueue : javax.jms.InvalidDestinationException: Not a HornetQ Destination:HornetQQueue[hornetq.management]

      Code :

       

      @Stateless
      public class MyQueueService {
      
          @Resource(mappedName = "java:/ConnectionFactory")
          private QueueConnectionFactory cf;
      
          @Resource(mappedName = "java:jboss/jms/queue/MyQueue")
          private Queue MyQueue;
      
          public void ClearMyQueue()
          {
      
              System.out.println("Start clearing MyQueue");
              Queue managementQueue = null;
              QueueRequestor requestor = null;
              QueueConnection queueConnection = null;
              QueueSession queueSession = null;
             
              try {
      
                  System.out.println("//!!!!\\\\ createQueue");
                  managementQueue = HornetQJMSClient.createQueue("hornetq.management");
                  queueConnection = cf.createQueueConnection();
                  System.out.println("//!!!!\\\\ queueSession");
                  queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
                  System.out.println("//!!!!\\\\ requestor");
                  requestor = new QueueRequestor(queueSession, managementQueue);
                  System.out.println("//!!!!\\\\ start");
                  queueConnection.start();
                  System.out.println("//!!!!\\\\ message");
                  Message message = session.createMessage();
                  System.out.println("//!!!!\\\\ JMSManagementHelper");
                  JMSManagementHelper.putOperationInvocation(message, MyQueue.getQueueName(), "removeMessages","*");
                  System.out.println("//!!!!\\\\ reply");
                  Message reply = requestor.request(message);
                  System.out.println("//!!!!\\\\ success");
                  boolean success = JMSManagementHelper.hasOperationSucceeded(reply);
                  if(!success)  System.out.println("Error during clearing MyQueue : operation faill");
                  System.out.println("//!!!!\\\\ END");
      
              } catch (Exception exc) {
                  System.out.println("Error during clearing MyQueue : " + exc);
              } finally
              {
                  if (queueConnection != null) {
                      try {
                          queueConnection.close();
                      } catch (JMSException e) {
                          System.out.println("Error during closing connection" + e);
                      }
                  }
              }
              System.out.println("End clearing MyQueue");
          }
      }
      
      

      standalone configuration :

       

      <subsystem xmlns="urn:jboss:domain:messaging:1.1">
        <hornetq-server>
            <clustered>true</clustered>
            <persistence-enabled>true</persistence-enabled>
            <cluster-user>clusteruser</cluster-user>
            <cluster-password>cluster-secret</cluster-password>
            <journal-file-size>102400</journal-file-size>
            <journal-min-files>2</journal-min-files>
      
            <connectors>
                <netty-connector name="netty" socket-binding="messaging"/>
                <netty-connector name="netty-throughput" socket-binding="messaging-throughput">
                    <param key="batch-delay" value="50"/>
                </netty-connector>
                <in-vm-connector name="in-vm" server-id="0"/>
            </connectors>
      
            <acceptors>
                <netty-acceptor name="netty" socket-binding="messaging"/>
                <netty-acceptor name="netty-throughput" socket-binding="messaging-throughput">
                    <param key="batch-delay" value="50"/>
                    <param key="direct-deliver" value="false"/>
                </netty-acceptor>
                <in-vm-acceptor name="in-vm" server-id="0"/>
            </acceptors>
      
            <broadcast-groups>
                <broadcast-group name="bg-group1">
                    <group-address>231.7.7.7</group-address>
                    <group-port>9876</group-port>
                    <broadcast-period>1000</broadcast-period>
                    <connector-ref>
                        netty
                    </connector-ref>
                </broadcast-group>
            </broadcast-groups>
      
            <discovery-groups>
                <discovery-group name="dg-group1">
                    <group-address>231.7.7.7</group-address>
                    <group-port>9876</group-port>
                    <refresh-timeout>10000</refresh-timeout>
                </discovery-group>
            </discovery-groups>
      
            <cluster-connections>
                <cluster-connection name="my-cluster">
                    <address>jms</address>
                    <connector-ref>netty</connector-ref>
                    <discovery-group-ref discovery-group-name="dg-group1"/>
                </cluster-connection>
            </cluster-connections>
      
            <security-settings>
                <security-setting match="#">
                    <permission type="send" roles="guest"/>
                    <permission type="consume" roles="guest"/>
                    <permission type="createNonDurableQueue" roles="guest"/>
                    <permission type="deleteNonDurableQueue" roles="guest"/>
                </security-setting>
                <security-setting match="jms.queue.hornetq.management">
                    <permission type="manage" roles="guest"/>
                </security-setting>
            </security-settings>
      
            <address-settings>
                <address-setting match="jms.queue.MyQueue">
                    <redelivery-delay>30000</redelivery-delay>
                    <max-delivery-attempts>15</max-delivery-attempts>
                    <redistribution-delay>0</redistribution-delay>
                </address-setting>
                <address-setting match="#">
                    <dead-letter-address>jms.queue.DLQ</dead-letter-address>
                    <expiry-address>jms.queue.ExpiryQueue</expiry-address>
                    <redelivery-delay>0</redelivery-delay>
                    <max-size-bytes>10485760</max-size-bytes>
                    <address-full-policy>BLOCK</address-full-policy>
                    <message-counter-history-day-limit>10</message-counter-history-day-limit>
                    <redistribution-delay>0</redistribution-delay>
                </address-setting>
            </address-settings>
      
            <jms-connection-factories>
                <connection-factory name="InVmConnectionFactory">
                    <connectors>
                        <connector-ref connector-name="in-vm"/>
                    </connectors>
                    <entries>
                        <entry name="java:/ConnectionFactory"/>
                    </entries>
                </connection-factory>
                <connection-factory name="RemoteConnectionFactory">
                    <connectors>
                        <connector-ref connector-name="netty"/>
                    </connectors>
                    <entries>
                        <entry name="RemoteConnectionFactory"/>
                        <entry name="java:jboss/exported/jms/RemoteConnectionFactory"/>
                    </entries>
                </connection-factory>
                <pooled-connection-factory name="hornetq-ra">
                    <transaction mode="xa"/>
                    <connectors>
                        <connector-ref connector-name="in-vm"/>
                    </connectors>
                    <entries>
                        <entry name="java:/JmsXA"/>
                    </entries>
                </pooled-connection-factory>
            </jms-connection-factories>
      
            <jms-destinations>
                <jms-queue name="MyQueue">
                    <entry name="java:jboss/jms/queue/MyQueue"/>
                    <durable>true</durable>
                </jms-queue>
            </jms-destinations>
        </hornetq-server>
      </subsystem>