8 Replies Latest reply on Aug 29, 2008 11:17 AM by Jeff Mesnil

    Management operation over JBM 2 Core API

    Jeff Mesnil Master

      In addition to be able to manage JBM2 using JMX, it must be possible to manage a JBM server by sending "management" messages using its core API .

      I've some working code to do that in my local box.
      The idea is that the user creates a temporary queue that he will use to send management messages.

      SimpleString mngmntQueue = new SimpleString("admin.MyOwnAdminQueue");
      clientSession.addDestination(mngmntQueue, false, true);
      clientSession.createQueue(mngmntQueue, mngmntQueue, null, false, true);
      


      He then create such management messages using the ClientSession:

      ClientMessage msg = clientSession.createManagementAttributesMessage(
       ManagementServiceImpl.getQueueObjectName(queue, queue),
       "MessageCount", "Durable");
      


      The semantics are the same than JMX: the message above means "retrieve attributes MessageCount and Durable on the Queue identified by the ObjectName".

      He then sends the message:

      producer.send(msg);
      


      After that, he consumes a message on the *same* temporary queue:

      ClientMessage m = consumer.receive(5000);
      


      The message he received then contains the value of the attributes:

      ManagementHelper helper = new ManagementHelper(m.getBody());
      System.out.println("MessageCount=" + helper.getProperty("MessageCount"));
      System.out.println("Durable=" + helper.getProperty("Durable"));
      


      It works almost the same to invoke a management operation:

      message = clientSession.createManagementOperationMessage(
       ManagementServiceImpl.getQueueObjectName(queue, queue),
       "listAllMessages");
      producer.send(msg);
      ...
      m = consumer.receive(5000);
      ...
      helper = new ManagementHelper(m.getBody());
      System.out.println("operation succeeded? " + mngmntHelper.hasOperationSucceeded());
      if (!helper.hasOperationSucceeded())
      {
       System.out.println("exception: " + helper.getOperationExceptionMessage());
      }
      else
      {
       TabularData msgs = (TabularData) helper.getTabularDataProperty("listAllMessages");
       MessageInfo[] infos = MessageInfo.from(msgs);
       for (MessageInfo info : infos)
       {
       System.out.println(info);
       }
      }
      


      The result of an operation is available has a property identified by the name of the operation "listAllMessages" above.
      Additionally, we must check if the operation has succeeded and if not, we have a exception message to report to the user.

      The implementation is straightforward: the "so-called" management messages are simple ClientMessages using well known headers
      to identify management attributes and operations (+ 1 header to flag the message as a management message).

      When the message is routed by the PostOffice on the server, we check if it is flagged as a management message.
      If that's the case, we pass it to the ManagementService.
      This service will invoke management operations and fetch attributes and put the values in the message.
      Then the message continues to be routed as any other message.

      To sum up:
      - management operations over JBM 2 core API uses JMX semantics
      - on the server, they're intercepted and processed by the management service, then routed normally
      - the user workflow is to create a temp queue, create management messages, send them, consume them and process the results

      The advantage of this implementation is that it is simple and not intrusive.
      The disadvantage is that the management code will be brittle since a lot is done by reflection: you've to double-check
      the ObjectNames you use, the attributes spelling, the types required by the management operation.
      Besides to know what can be done on the management side, you have to look at our MBeans to check the available attributes and operations.

      I still need to add support for notifications but i'll save that for another post on the dev forum


        • 1. Re: Management operation over JBM 2 Core API
          Tim Fox Master

          I would suggest a slight change to the way this works.

          We could have some kind of special "hard coded" management address, (there's no actual real queue bound there).

          You then send a management message to that address, in the management message you send, you add a header "REPLY_DESTINATION" (or whatever).

          The server processes the request and sends reply back to REPLY_DESTINATION.

          Being able to specify REPLY_DESTINATION is more flexible since it allows you to say, send responses to global queue or topic where they are processed by some other consumers.

          • 2. Re: Management operation over JBM 2 Core API
            Jeff Mesnil Master

            i agree with your suggestion, it'll make the management code more flexible.

            I still need to write some unit tests before committing.
            Once I'm done with that, the only remaining task wrt to management will be to be able to subscribe to a management topic to receive notifications.

            • 3. Re: Management operation over JBM 2 Core API
              Tim Fox Master

               

              "jmesnil" wrote:

              Once I'm done with that, the only remaining task wrt to management will be to be able to subscribe to a management topic to receive notifications.


              What about, the current add/delete queue/address methods on the transport? Are these necessary now we can do that through management?

              • 4. Re: Management operation over JBM 2 Core API
                Jeff Mesnil Master

                 

                "timfox" wrote:

                What about, the current add/delete queue/address methods on the transport? Are these necessary now we can do that through management?


                Yes, we still need them to create the destination and the (temp) queue which is used to receive the management messages

                • 5. Re: Management operation over JBM 2 Core API
                  Tim Fox Master

                   

                  "jmesnil" wrote:

                  Yes, we still need them to create the destination and the (temp) queue which is used to receive the management messages


                  Seems a bit odd.

                  If we have a standard management destination this shouldn't be necessary surely?

                  Also the SessionBindingQueryRequest/Response and SessionBindingQueryRequest/Response should be defunct now, right?

                  • 6. Re: Management operation over JBM 2 Core API
                    Jeff Mesnil Master

                     

                    "timfox" wrote:
                    "jmesnil" wrote:

                    Yes, we still need them to create the destination and the (temp) queue which is used to receive the management messages


                    Seems a bit odd.

                    If we have a standard management destination this shouldn't be necessary surely?


                    The management clients will send management messages to this standard management messages.

                    However, it needs to be able to consume the replies.
                    My idea was that he still would have to create a temp queue and a destination used as the "reply-to" of the management messages.




                    • 7. Re: Management operation over JBM 2 Core API
                      Tim Fox Master

                       

                      "jmesnil" wrote:


                      The management clients will send management messages to this standard management messages.

                      However, it needs to be able to consume the replies.
                      My idea was that he still would have to create a temp queue and a destination used as the "reply-to" of the management messages.




                      if I send a management message to admin destination "create Temp Queue", and also specify that destination as the reply for the management message, then surely it will create that destination, then send the reply back there.

                      So you can still consume the replies, no need for extra create/delete queue methods?

                      • 8. Re: Management operation over JBM 2 Core API
                        Jeff Mesnil Master

                         

                        "timfox" wrote:
                        "jmesnil" wrote:


                        The management clients will send management messages to this standard management messages.

                        However, it needs to be able to consume the replies.
                        My idea was that he still would have to create a temp queue and a destination used as the "reply-to" of the management messages.




                        if I send a management message to admin destination "create Temp Queue", and also specify that destination as the reply for the management message, then surely it will create that destination, then send the reply back there.

                        So you can still consume the replies, no need for extra create/delete queue methods?


                        Sure you can, but I find this more convoluted than having a explicit create/delete queue methods.
                        Besides, creating temp queues is done in many messaging patterns and I'd prefer to keep a method to do that as part of our core API without relying on management API.