1 2 Previous Next 19 Replies Latest reply on Jun 19, 2007 12:24 AM by Milind Chaudhari

    import org.jboss.mq.server.jmx.Queue

    Milind Chaudhari Newbie

      I want to monitor the queue I have the application server of Jboss 4.0.0 + versions and I want to show the status of queue that is how many transactions are pending , how many scheduled, how many recived by reciver . I know it is possible by the JMX getDepth() but I am not abl to used it as I am not that much familliar with jbossMQ and JMX APIS...


      Again there is BasicQueue class,BasicQueueParameter class , MesaageCounter class but I am not understanding how to used it as the constructor of the above classes contains 4 to 6 paramters all these are frustrating one..

      So please suggest me the soloution ..And also suggest me any Book name or diffrent links where there is some sample examples and good discriptions of how to used it........

        • 1. Re: import org.jboss.mq.server.jmx.Queue
          Jacek Kowalski Newbie

          Hello

          I have a solution for you. The key is JMX API.
          As you know there is a MBean which you can view using jboss jmx console.
          One thing we have to do is to acces that MBean. Here is some code i have written for you:


          String domain = "jboss.mq.destination";
           String service = "service=Queue";
           String name = "name=testQueue";
          
           String stringObjectName = domain + ":" + service + "," + name;
          
           MBeanServer server = MBeanServerLocator.locateJBoss();
          
           try{
           ObjectName queueObjectName = ObjectName.getInstance(stringObjectName);
          
           org.jboss.mq.server.jmx.QueueMBean queueMBean =
           (org.jboss.mq.server.jmx.QueueMBean) MBeanServerInvocationHandler.newProxyInstance(
           server,
           queueObjectName,
           org.jboss.mq.server.jmx.QueueMBean.class,
           false
           );
          
           logger.info("queue depth: " + queueMBean.getQueueDepth());
          
           }catch (Exception e){
           logger.info("cannot get depth of the queue: " + e.getMessage(),e);
           }



          When you have a proxy then you can get all queue properties by calling method: getNameOfAttribute (ex. queueMBean.getQueueDepth();)

          These three strings set up at the begining are taken from jmx-console page for MBean monitoring Queue.

          If you have any questions, just ask.

          As a reward please look at my question (Queue - I can send but cannot receive) i'm going to write right now.
          Since you are working with queues maybe you will be able to help me.

          Take care

          vitor_b


          • 2. Re: import org.jboss.mq.server.jmx.Queue
            Milind Chaudhari Newbie

            Dear Victor,

            Feel glade to see the way you reply and sorry as I am replying so late because sat. and sun. was holiday here...

            Well as ur able to send message to queue and not able to recive.So there are 2 to 3 possiblity...

            1)Might be u r usinng diffrent Queue(Queue Name) while creating the receiver .I mean you need to used the same queue name at receiver end which you used at while creating the queue sender.

            2) At the time of creating the Receiver you migth forget to do connection.start() (I mean you need to invoke the start method on the QueueConnection object above I writeen connection.start() in this connection is object of Queueconnection class)

            3)It might happen that while creating object of initialcontext.. you need to set the property like:---------------

            Hashtable env = new Hashtable();
            
             env.put (Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
            env.put(Context.PROVIDER_URL, "jnp://localhost:1099");
            env.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");
            
            ctx = new InitialContext(env);




            Inseted of localhost might be ur using the difffrent ipadress in reciver side which u have used for the sender side(Provided that you are creating the sender and receiver in diffrent java files).So used the same IpAdress in sender and receiver side...


            4)Might be you are reciving the message twice in ur code specially at the time of synchronus reciving and might at first time of receving ur not fetching and checking the contenet of message which might be ur doing at the second time so just make look on ur code so try adopt the model of asynchronus......

            5)And being it is the queue here first user(Queue receiver) available on it (Queue) will able to fetch the message so the next QueueReciver coming after the first QueueReceiver not get any messages from the queue because first QueueReceiver might be consuming the messages.....



            Well this what I am felling..hope it will work for u....

            Well I just came in the office still I havent used the code you send to me but well I dont know lot of thing in JMS,JMX and all thses stuffs I want to do all thse things I never know( I meas I never have the idea to read the mbeans like it ) the code u written for me so could u tell mesome books or links because I want to explore it lot.. And yes ,, after trying your code example I might will get some query so please help me that time....

            Thanks :)



            • 3. Re: import org.jboss.mq.server.jmx.Queue
              Jacek Kowalski Newbie

              Thanks for your reply.

              The problem with my Queue was that described in section 2. I did not call connection.start() method. My mistake.

              If we talk about books: i haven't seen any good one.
              I learned from Jboss wiki knowledgebase: http://wiki.jboss.org/wiki/Wiki.jsp?page=JBossMX

              If you have any questions just ask, but i'm not an expert, so it is possible that I won't be able to answer to your questions. Anyway, i will try :)

              Best regards

              vitor_b



              • 4. Re: import org.jboss.mq.server.jmx.Queue
                Milind Chaudhari Newbie

                Dear Victor,
                Feel happy as ur problem get solved... Well I tried the code sample which you have been written for me but I am getting problem in it.


                
                 String domain = "jboss.mq.destination";
                 String service = "service=Queue";
                 String name = "name=testQueue";
                
                 String stringObjectName = domain + ":" + service + "," + name;
                
                 MBeanServer server = MBeanServerLocator.locateJBoss();
                
                 try{
                 ObjectName queueObjectName = ObjectName.getInstance(stringObjectName);
                
                 org.jboss.mq.server.jmx.QueueMBean queueMBean =
                 (org.jboss.mq.server.jmx.QueueMBean) MBeanServerInvocationHandler.newProxyInstance(
                 server,
                 queueObjectName,
                 org.jboss.mq.server.jmx.QueueMBean.class,
                 false
                 );
                
                 logger.info("queue depth: " + queueMBean.getQueueDepth());
                
                 }catch (Exception e){
                 logger.info("cannot get depth of the queue: " + e.getMessage(),e);
                 }




                After using it I am getting the error like :-------


                java.lang.IllegalStateException: No 'jboss' MBeanServer found!
                at org.jboss.mx.util.MBeanServerLocator.locateJBoss(MBeanServerLocator.java:46)



                So do you have any idea on it

                • 5. Re: import org.jboss.mq.server.jmx.Queue
                  Jacek Kowalski Newbie

                  Hmm...

                  This line:

                  MBeanServer server = MBeanServerLocator.locateJBoss();


                  should work when calling from non-MBean, for example from EJB session bean in the same JVM.
                  I don't think that you calling it in this way.
                  I have JBoss 4.0.5 GA, but that class was available in version 3.2.7 or even earlier.

                  I tested this code before posting it and it works fine for me. My code was in stateless session bean deployed on JBoss. So try it from the same JVM.

                  Best regards

                  vitor_b


                  • 6. Re: import org.jboss.mq.server.jmx.Queue
                    Milind Chaudhari Newbie

                    yes ,, I think I am doing the mistake while using it actually I am using it fom simple pojo class.....


                    public class Sender_Count
                    {
                    
                    
                    
                    
                    
                     public static QueueConnectionFactory factory = null;
                     public static QueueConnection connection = null;
                     public static QueueSession session = null;
                     public static QueueSender sender = null;
                     public static Context ctx = null;
                     public static javax.jms.Queue queue = null;
                     public static TextMessage message = null;
                     public static ConnectionMetaData metadata = null;
                     public static Queue obj = null;
                    
                     //public static JMSQueue queue = null;
                    
                    
                     public static void main(String[] args)
                     {
                    
                     /*
                     * Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContext"); env.put(Context.PROVIDER_URL,"jnp://localhost:1099"); env.put(Context.URL_PKG_PREFIXES,"jboss.naming:org.jnp.interfaces");
                     */
                    
                    
                    
                     Hashtable env = new Hashtable();
                    
                     env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
                     env.put(Context.PROVIDER_URL, "jnp://localhost:1099");
                     env.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");
                    
                    
                    
                     try
                     {
                     ctx = new InitialContext(env);
                     factory = (QueueConnectionFactory) ctx.lookup("UIL2ConnectionFactory");
                     connection = factory.createQueueConnection();
                     session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
                     queue = (javax.jms.Queue) ctx.lookup("queue/C");
                     sender = session.createSender(queue);
                     connection.start();
                     message = session.createTextMessage();
                     message.setText("Bajirao_Mastani");
                     sender.send(message);
                    
                    
                    
                    
                    
                     String domain = "jboss.mq.destination";
                     String service = "service=Queue";
                     String name = "name=queue/C";
                    
                     String stringObjectName = domain + ":" + service + "," + name;
                    
                     MBeanServer server = MBeanServerLocator.locateJBoss();
                    
                     try{
                     ObjectName queueObjectName = ObjectName.getInstance(stringObjectName);
                    
                     org.jboss.mq.server.jmx.QueueMBean queueMBean =
                     (org.jboss.mq.server.jmx.QueueMBean) MBeanServerInvocationHandler.newProxyInstance(
                     server,
                     queueObjectName,
                     org.jboss.mq.server.jmx.QueueMBean.class,
                     false
                     );
                    
                     logger.info("queue depth: " + queueMBean.getQueueDepth());
                    
                     }catch (Exception e){
                     logger.info("cannot get depth of the queue: " + e.getMessage(),e);
                     }
                    
                    
                     }
                     catch (NamingException e)
                     {
                     e.printStackTrace();
                     }
                     catch (JMSException se)
                     {
                     se.printStackTrace();
                     }
                     catch (ClassCastException ce)
                     {
                     ce.printStackTrace();
                     }
                    
                     }
                    }
                    
                    



                    I think i am doing something wrong by calling it in above fashion from simple pojo class...Iam in trouble because of that locateJboss() so help me.

                    Thanks :)



                    • 7. Re: import org.jboss.mq.server.jmx.Queue
                      Jacek Kowalski Newbie

                      Hello

                      If you really need remote access you need to change one line in your code.
                      Change this line:

                      MBeanServer server = MBeanServerLocator.locateJBoss();


                      to this one:

                      MBeanServerConnection server = (MBeanServerConnection) ictx.lookup("jmx/invoker/RMIAdaptor");


                      That should help.

                      Best regards.

                      vitor_b

                      P.S. Do you have any experience in working with XML?

                      • 8. Re: import org.jboss.mq.server.jmx.Queue
                        Milind Chaudhari Newbie

                        yes ,, hay thanks for ur reply as I get confident from your reply because before reading your reply I did the things which you mentioned but the thing is that only the getQueueDepth is working which is nothing but the tolal number fo the messages in the queue..Other attributes like the getSchedulemessagecount(),getReceiversCount() are giving the values zero ..Still writing this reply I used all thses things only on the receivers side.. I did in the foloowing way while sending the messages and still not on the receivers side...

                        MBeanServerConnection mbean_server = null;
                         ObjectName dm = null;
                        try{
                        
                        
                         mbean_server =(MBeanServerConnection) ctx.lookup("jmx/rmi/RMIAdaptor");
                         dm = new ObjectName("jboss.mq:service=DestinationManager");
                        
                        String domain = "jboss.mq.destination";
                         String service = "service=Queue";
                         String name = "name=queue/C";
                        
                         String stringObjectName = domain + ":" + service + "," + name;
                        
                        
                        
                        
                         ObjectName queueObjectName = ObjectName.getInstance(stringObjectName);
                        
                         org.jboss.mq.server.jmx.QueueMBean queueMBean =
                         (org.jboss.mq.server.jmx.QueueMBean) MBeanServerInvocationHandler.newProxyInstance(
                         mbean_server,
                         queueObjectName,
                         org.jboss.mq.server.jmx.QueueMBean.class,
                         false
                         );
                         System.out.println("queue depth is :" + queueMBean.getQueueDepth());
                         System.out.println("getScheduledMessageCount count is :" + queueMBean.getScheduledMessageCount());
                         System.out.println("History Limit :"+queueMBean.getMessageCounterHistoryDayLimit());
                         System.out.println("MAximmum depth :"+ queueMBean.getMaxDepth());
                         System.out.println("Receiver Count is :" +queueMBean.getReceiversCount());
                         System.out.println("Redelivery Limit:"+queueMBean.getRedeliveryLimit());
                         System.out.println("Name is :"+queueMBean.getName());
                         System.out.println("queue name is :"+queueMBean.getQueueName());
                        
                        
                        


                        Again if I did the org.jboss.mq.server MessageCounter meas []= queueMBean.getMessageCounter(); then I got the exception as===
                        java.lang.reflect.UndeclaredThrowableException
                        at $Proxy1.getMessageCounter(Unknown Source)
                        at Statstic.Sender_Count.main(Sender_Count.java:220)
                        Caused by: java.io.NotSerializableException: org.jboss.mq.server.MessageCounter
                        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1054)
                        at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1224)
                        .....

                        Beside the total count of the messages in the queue I also needed how many messages are scheduled(Recived by reciver ) ,pending.If u have idea then please suggest and guide me.

                        Thanks for all your help it is pleasurabel :)


                        • 9. Re: import org.jboss.mq.server.jmx.Queue
                          Milind Chaudhari Newbie

                           

                          "milind.uc" wrote:
                          yes ,, hay thanks for ur reply as I get confidence from your reply because before reading your reply I did the things which you mentioned but the thing is that only the getQueueDepth is working which is nothing but the tolal number fo the messages in the queue..Other attributes like the getSchedulemessagecount(),getReceiversCount() are giving the values zero ..Still writing this reply I used all thses things only on the receivers side.. I did in the foloowing way while sending the messages and still not on the receivers side...

                          MBeanServerConnection mbean_server = null;
                           ObjectName dm = null;
                          try{
                          
                          
                           mbean_server =(MBeanServerConnection) ctx.lookup("jmx/rmi/RMIAdaptor");
                           dm = new ObjectName("jboss.mq:service=DestinationManager");
                          
                          String domain = "jboss.mq.destination";
                           String service = "service=Queue";
                           String name = "name=queue/C";
                          
                           String stringObjectName = domain + ":" + service + "," + name;
                          
                          
                          
                          
                           ObjectName queueObjectName = ObjectName.getInstance(stringObjectName);
                          
                           org.jboss.mq.server.jmx.QueueMBean queueMBean =
                           (org.jboss.mq.server.jmx.QueueMBean) MBeanServerInvocationHandler.newProxyInstance(
                           mbean_server,
                           queueObjectName,
                           org.jboss.mq.server.jmx.QueueMBean.class,
                           false
                           );
                           System.out.println("queue depth is :" + queueMBean.getQueueDepth());
                           System.out.println("getScheduledMessageCount count is :" + queueMBean.getScheduledMessageCount());
                           System.out.println("History Limit :"+queueMBean.getMessageCounterHistoryDayLimit());
                           System.out.println("MAximmum depth :"+ queueMBean.getMaxDepth());
                           System.out.println("Receiver Count is :" +queueMBean.getReceiversCount());
                           System.out.println("Redelivery Limit:"+queueMBean.getRedeliveryLimit());
                           System.out.println("Name is :"+queueMBean.getName());
                           System.out.println("queue name is :"+queueMBean.getQueueName());
                          
                          
                          


                          Again if I did the org.jboss.mq.server MessageCounter meas []= queueMBean.getMessageCounter(); then I got the exception as===
                          java.lang.reflect.UndeclaredThrowableException
                          at $Proxy1.getMessageCounter(Unknown Source)
                          at Statstic.Sender_Count.main(Sender_Count.java:220)
                          Caused by: java.io.NotSerializableException: org.jboss.mq.server.MessageCounter
                          at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1054)
                          at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1224)
                          .....

                          Beside the total count of the messages in the queue I also needed how many messages are scheduled(Recived by reciver ) ,pending.If u have idea then please suggest and guide me.

                          Thanks for all your help it is pleasurable :)


                          • 10. Re: import org.jboss.mq.server.jmx.Queue
                            Jacek Kowalski Newbie

                            Hello

                            It looks that reference to this object cannot be sent outside JVM in which this object lives. This is an simple object, not bean, so you cannot access it. Honestly I don't know how to do that. From inside server you could access and use that reference.

                            So... personally i would create session bean working on server, which will expose some methods. These methods would get info about yoour queue via MBean Proxy. You could create MBean proxy in ejbCreate method, and this bean could be stateless.
                            So you would lokup for that bean, call methods on it, and all logic taking info about your queue would be inside that bean methods.
                            It is heavier but I don't know the other way.

                            Best regards

                            vitor_b

                            • 11. Re: import org.jboss.mq.server.jmx.Queue
                              Milind Chaudhari Newbie

                              Well I jsut came here now I am going to try it with the ejbs lets see ,,, I tried to serialize the object also but it didnt work . And yes do you have idea that how to find the scheduled and pending message count for the particular queue. As I said that as per our meanserver methods I am getting the onlye no of messages only not how much exactlyy scheduled and pendng....

                              • 12. Re: import org.jboss.mq.server.jmx.Queue
                                Milind Chaudhari Newbie

                                 

                                "milind.uc" wrote:
                                Well I jsut came here now I am going to try it with the ejbs lets see ,,, I tried to serialize the object also but it didnt work . And yes do you have idea that how to find the scheduled and pending message count for the particular queue. As I said that as per our mbeanserver methods I am getting the onlye no of messages only not how much exactlyy scheduled and pendng....


                                • 13. Re: import org.jboss.mq.server.jmx.Queue
                                  Milind Chaudhari Newbie

                                   

                                  "milind.uc" wrote:
                                  "milind.uc" wrote:
                                  Well I jsut came here now I am going to try it with the ejbs lets see ,,, I tried to serialize the object also but it didnt work . And yes do you have idea that how to find the scheduled and pending message count for the particular queue. As I said that as per our mbeanserver methods I am getting the onlye no of messages only not how much exactlyy scheduled and pending....


                                  • 14. Re: import org.jboss.mq.server.jmx.Queue
                                    Jacek Kowalski Newbie

                                    I haven't worked with jms much, so i don't know, but i took a look at MBean attributes, this one monitoring queue, and there are two attributes which are the ones you need:

                                    ScheduledMessageCount
                                    InProcessMessageCount

                                    But i don't know how they work, you must to check them.

                                    Best regards

                                    vitor_b

                                    1 2 Previous Next