Sun Java System Message Queue 4.2 Developer's Guide for Java Clients

ProcedureTo Monitor Broker Metrics

  1. Create a TopicConnectionFactory object.

  2. Create a TopicConnection to the Message Queue service.

  3. Create a TopicSession.

  4. Create a metrics Topic destination object.

  5. Create a TopicSubscriber.

  6. Register as an asynchronous listener to the topic, or invoke the synchronous receive() method to wait for incoming metrics messages.

  7. Process metrics messages that are received.

    In general, you would use JNDI lookups of administered objects to make your client code provider-independent. However, the metrics-message production is specific to Message Queue, there is no compelling reason to use JNDI lookups. You can simply instantiate these administered objects directly in your client code. This is especially true for a metrics destination for which an administrator would not normally create an administered object.

    Notice that the code examples in this chapter instantiate all the relevant administered objects directly.

    You can use the following code to extract the type ( String) or timestamp (long) properties in the message header from the message:

    MapMessage mapMsg;
    * mapMsg is the metrics message received
    String type = mapMsg.getStringProperty("type");
    long timestamp = mapMsg.getLongProperty("timestamp");

    You use the appropriate get method in the class javax.jms.MapMessage to extract the name-value pairs. The get method you use depends on the value type. Three examples follow:

    long value1 = mapMsg.getLong("numMsgsIn");
    long value2 = mapMsg.getLong("numMsgsOut");
    int value3 = mapMsg.getInt("diskUtilizationRatio");