7 Replies Latest reply on May 19, 2014 10:16 AM by Justin Bertram

    destroyTopic using MBeanServer, Error:cannot delete topic , it has consumers

    Alex Don Newbie

      Hello,

       

      I'm implementing a chat using HornetQ , JMS.  I want to implement the deleting a subscriber in a Topic, e.g. in my scenario: when an owner of the chat group deletes a participant, the owner sends an request to MessageDrivenBean and the MessageDrivenBean should delete this subscriber in Topic. I have not found the function on MBeanServer using the jconsole to drop a subcriber, there are only the functions: deploy, destroy, listConsumers etc. Therefore I want to implement it so, that the MessageDrivenBean destroy firstly the Topic (mBeanServer.invoke(on, "destroyTopic" , new Object[] { topicName }, new String[] { "java.lang.String" }); ) and deploy a new Topic and notify the subcribers, that they should consume from new Topic. I've got an error:

       

      Caused by: HornetQException cannot delete topic  it has consumers

       

      How can I implement my scenario? Is is possible, that the Server drop a subscriber?

       

      Thanks in advance

       

      Cheers,

      Alex

        • 1. Re: destroyTopic using MBeanServer, Error:cannot delete topic , it has consumers
          Justin Bertram Master

          The destroyTopic method is overloaded.  Try using the one that takes a String and a boolean.  The boolean indicates whether or not the consumers should be removed before the topic is destroyed.

          • 2. Re: destroyTopic using MBeanServer, Error:cannot delete topic , it has consumers
            Alex Don Newbie

            Unfortunately, it doesn't work. I tried to do it so, as it is shown in JavaDocs :

             

            The countMatches operation can be invoked as follows:

                      String[] myPatterns = ...;

                      int count = (Integer) mbeanServerConnection.invoke( objectName, "countMatches", new Object[] {myPatterns, true}, new String[] {String[].class.getName(), boolean.class.getName()});

             

             

             

            Here is my code with some variants:

             

            ....

            mBeanServer = (MBeanServer) javax.management.MBeanServerFactory

              .findMBeanServer(null).iterator().next();

                 try {

                           on = ObjectNameBuilder.DEFAULT.getJMSServerObjectName();

                           mBeanServer.invoke(on, "destroyTopic" , new Object[] { topicName, true }, new String[] {"java.lang.String" });

                           v.2//mBeanServer.invoke(on, "destroyTopic" , new Object[] { topicName, true }, new String[] {"java.lang.String" , boolean.class.getName()});                                          ERROR: javax.management.ReflectionException:    Signature    mismatch for operation destroyTopic: (java.lang.String, java.lang.Boolean) should be (java.lang.String)

                            v.3//mBeanServer.invoke(on, "destroyTopic" , new Object[] { topicName, true }, new String[] {"java.lang.String" ,"java.lang.Boolean"}); ERROR: smth, like too many parameters

             

                     } catch (Exception e) {

                             e.printStackTrace();

                      }

            ...

             

            No one of variant works. How can I invoke destroyTopic, which takes these two parameter : String and boolean? Thx!

             

             

            BTW: Question 2: I actually want to implement a client on Android using Hornetq, but it is not possible, as Android has no javax.* packages.  I've read a lot of about it and found a solution to repackage android's packages. but it is not a good idea. Do you know maybe, wich other tools is it better to use? Maybe ActiveMQ in JBoos, as Android can send messages to Queue in ActiveMQ? Would be nice, if you gave me some tipp.

            • 3. Re: destroyTopic using MBeanServer, Error:cannot delete topic , it has consumers
              Justin Bertram Master

              What version of HornetQ are you using?  You'll need to be on at least 2.4.1.Final to get access to org.hornetq.api.jms.management.JMSServerControl.destroyTopic(java.lang.String, boolean) as it wasn't in earlier versions.

               

              Also, if you want to use HornetQ from a mobile client try looking at either our REST or STOMP stuff in the documentation.

              1 of 1 people found this helpful
              • 4. Re: destroyTopic using MBeanServer, Error:cannot delete topic , it has consumers
                Alex Don Newbie

                Thanks for the helpful answer, I updated the hornetq to version 2.4.1 and can see now the function.

                 

                Regarding using HornetQ from a mobile client your tip brought me a bit forward.

                According to this page I installed the enviroment and Bootstrapped the HornetQ Along with REST including configuration so far.

                 

                Before I had a MessagDriveBean in a ejb-module, where I receive a message and processed it:


                @MessageDriven(name = "MessageMDBSample", activationConfig = {

                       @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),

                       @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/test"),

                       @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") })

                 

                public class QueueListenerMDB implements MessageListener {

                            @Resource(mappedName = "java:/JmsXA")

                            ConnectionFactory connectionFactory;

                 

                            private Session session;

                            Connection conn;

                            MBeanServer mBeanServer;

                            ObjectName on;

                            Queue replyDest;

                 

                       public void onMessage(Message message) {

                                        try {

                                                     // message processing, as involve creating new Queue at runtime : mBeanServer.invoke(on, "createTopic", new Object[] { TopicName },

                                                     //         new String[] { "java.lang.String" }); and so on

                                      } catch (JMSException e) {

                                                     e.printStackTrace();

                                      }

                       }

                }

                 

                I set up the REST in web-module in order to get a .war file and here it is not possible to have MDB.

                Is it possible to process the message using REST on the same way , as it is in ejb with MDB? Do the messages come on anyplace on the server, so that it would be possible to read it and for example create a new queue or topic at runtime, send responce to the client and other operations?

                • 6. Re: destroyTopic using MBeanServer, Error:cannot delete topic , it has consumers
                  Alex Don Newbie

                  Thanks for the tip. I tried it before, the difficulty is with REST, that a Listener on Client is not provided.It should be implemented with a repeated pull function. In my case, i.e. a chat, it is'n efficiently.

                  I will look for a solution.