6 Replies Latest reply on Nov 18, 2010 4:00 PM by oscarfh

    JMX vs JMS - Do they access the same resources?

      I am still trying to learn this huge technology (glassfish). I was able to connect using JMX and was very happy with that, but I had to do the something with this connection.
      I was already able to get all the queues I have, which is very nice, but I could only get their names and attributes. I would like to get the messages that are in these lists and their content.

      I am taking a look at the Destination and Consumer classes, but it doesn't seem that I can benefit from that. But still looking.

      What I could find was a way to get this information using JMS. I would like to use JMX for that, but if JMx doesn't solve, JMS would be an "emergency solution". But one big question mark came to my mind:
      I can access a queue using JMS and get all the messages from it, but neither the admin console nor my JMX code that lists all the queues show this list.

      Why? Why am I able to access a queue using JMS and not JMX?
      Does JMX ensures that I get all the info I need or may it happen that it misses some info (as this queue)?
      Is there any way I can get the messages using JMX and not JMS?

      Thank you,

      Edit: just to make it clear, this queue that I can't see in the admin console is not "explicitly" created, it is automatically created by sending a message to it using JMS.

      Edited by: 808621 on 18/Nov/2010 2:07
        • 1. Re: JMX vs JMS - Do they access the same resources?
          Nigel Deakin-Oracle
          The purpose of Open Message Queue (GlassFish Message Queue) is to be a implementation of the Java Message Service (JMS) API. This is a standard API, part of the JavaEE platform. There are several other products (some open source, some commercial) which implement the same API.

          The JMS specification covers how to send and receive messages. However it doesn't cover management and administrative. In this area, each vendor offers its own facilities, which will vary from one vendor to another.

          Open Message Queue provides various facilities to manage and administer an Open MQ installation. This area is not standardised. There's a number of command-line tools such as imqcmd. And there's a Java API which uses JMX technology. These are all documented in the relevant user guides at http://docs.sun.com/app/docs/coll/1343.13 . But they're all intended to support the use of JMS as a way for programs to exchange messages, not offer an alternative.

          As you noticed, the JMX API doesn't allow individual messages to be queried. We have had some requests from tool builders to be able to do this, and I accept that it would be desirable, but there is currently no supported API to do this.

          However if you look at the MQ Wiki page on "Unsupported features"
          you'll find a downloadable zip containing some (non-JMX) tools to allow individual messages to be listed, deleted and replaced, which you may find of use, but I would stress that this is unsupported, even for paying customers. Please note the disclaimer at the top of that page.

          1 person found this helpful
          • 2. Re: JMX vs JMS - Do they access the same resources?
            Thanks, so I will use JMS to get the messages, I think it is better than no supported features.
            Could you please tell me then why do I access different resources when I use JMX/Admin Console and JMS?

            Here is the code of JMS that is able to read 10 messages in this queue. But it doesn't appear in the admin console or my JMX code

            ConnectionFactory connectionFactory = new com.sun.messaging.QueueConnectionFactory();

            Connection connection = connectionFactory.createConnection();
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

            Queue myQueue = session.createQueue("myQueue");

            QueueBrowser browser = session.createBrowser(myQueue);
            Enumeration msgs = browser.getEnumeration();

            if (!msgs.hasMoreElements()) {
            System.out.println("No messages in queue");
            } else {
            while (msgs.hasMoreElements()) {
            Message tempMsg = (Message) msgs.nextElement();
                 System.out.println("Message: " + tempMsg);

            Edit: the JMX code access the "Physical Destinations", maybe the JMS access the Destination Ressources? But "myQueue" is not listed there either :(

            Edited by: 808621 on 18/Nov/2010 3:55
            • 3. Re: JMX vs JMS - Do they access the same resources?
              Nigel Deakin-Oracle
              Can you be more specific? Are you saying that you can successfully use the QueueBrowser to list the messages in a queue, but that if you use the JMX API the queue appears not to exist? No, that shouldn't happen.

              There are a couple of concepts worth mentioning, which might help you work out what is happening:

              Physical destinations vs destination resources.

              *1. Physical destinations*

              A physical destination (where a "destination" can be a queue or a topic) is an entity in the MQ broker. A destination may be "auto"-created simply by sending messages to it. Auto-created destinations are deleted automatically by the broker if they are empty for more than a couple of minutes. You will see a message in the broker log when this happens.

              You can also "administratively create" a destination. This is done using "asadmin create-jmsdest" or "imqcmd create dst". "Admin"-created destinations live for ever, even if empty.

              When you use session.createQueue(queueName) or the JMX API you are referring to the physical destination name. Note incidentally that session.createQueue(queueName) doesn't actually create the queue (see the Javadocs).

              The GlassFish admin console doesn't show physical destinations.

              *2. Destination resources*

              These are entities in GlassFish's JNDI store which are looked up using JNDI and may be created using the admin console or "asadmin create-jms-resource". They must refer to the physical destination name.

              Hope this helps...

              • 4. Re: JMX vs JMS - Do they access the same resources?
                now I got a little confused, you said that Admin Console doesn't show physical destinations, but in my Admin Console I can see them. Here is a link to a print screen that I made of my admin console

                I am saying exactly that.
                I found some demos in the Sun/MessageQueue folder, onde of them is called "SenderToQueue". I used to to send messages to a queue which didn't exist (QueueA).
                I had this code that I posted before, and defined to get the messages of QueueA. I am able to browse all the messages and get their content (I can read messages that I sent on Monday).

                But when I run my JMX code to get all the Destinations, it doesn't appear.
                In Admin console I can see the same queues as my code outputs

                And that is driving me crazy for the last 2 days, because I don't know where to look anymore

                And thanks for this clarification abour resources and destinations, I had already had some ideas in my mind, but that helped clearing the concepts out!


                Edit: I am starting to wonder if I am not connecting to the wrong broker when I use the connection factory. Would that be possible?
                Edit2: Indeed, I am connecting to some wrong "endpoint". I just shut my server down, the JMX code stopped working but not the JMS-Connection factory... I will try to find out from where does connection factory gets the attributes to start the connection...

                Edit3: just to let you know, I've solved it. There was a problem with the environment, I was connectiong to one domain using JMX (the one I wanted) and to another one ( dont know where it came from) using JMS. Now I am connecting to both of them and the admin console is showing the queue and I am able to get it using my JMX code.
                Thanks for your HUGE help again!


                Edited by: 808621 on 18/Nov/2010 4:38

                Edited by: 808621 on 18/Nov/2010 4:40

                Edited by: 808621 on 18/Nov/2010 4:41

                Edited by: 808621 on 18/Nov/2010 5:46
                • 5. Re: JMX vs JMS - Do they access the same resources?
                  Nigel Deakin-Oracle
                  Now I got a little confused, you said that Admin Console doesn't show physical destinations, but in my Admin Console I can see them. Here is a link to a print screen
                  Thanks. You're perfectly correct. I should have said that the "Destination Resources" node doesn't show physical destinations. (I got confused myself there, because I am using GlassFish 3.1, which doesn't have a "Physical Destinations" node)

                  Here's something else to try: Use the imqcmd utility to ask the broker to list its destinations. This will be in a directory imq/bin under your GlassFish 2 installation. Replace 7676 with the appropriate JMS port, if different.

                  imqcmd list dst -b localhost:7676
                  Username: admin
                  Listing all the destinations on the broker specified by:

                  Host Primary Port
                  localhost 7676

                  Name Type State Producers Consumers Msgs
                  Total Wildcard Total Wildcard Count Remote UnAck Avg Size
                  mq.sys.dmq Queue RUNNING 0 - 0 - 0 0 0 0.0

                  Successfully listed destinations.
                  • 6. Re: JMX vs JMS - Do they access the same resources?
                    Thanks, at the time I am not in my workspace, so I can't do that.
                    I have solved it, actually I had 2 instances running, and I was connecting to both of them (one using JMX and other JMS), not I was able to connect to the same instance and everything is perfect :)

                    Thanks for your help again :)