WLDF generating JMS Message notifications

This post describes a simple usage of how we can leverage the WLDF functionality with JMS feature. This post would show how WLDF can generate notifications in the form of JMS messages and sends it to message Queue which can be consumed by the JMS consumer.

Before starting the configuration , we would require a JMS Queue setup. Follow the below link to create one.

https://weblogic-wonders.com/weblogic/2010/11/30/weblogic-jms-feature-using-a-queue/

1. Login into the WebLogic Administration Console and navigate to Diagnostic → Diagnostic Module.

Create a WLDF (Diagnostic) module.


2. Click on the created WLDF module.

NOTE: There are two types o RunTime MBeans.  DomainRuntime Mbean and ServerRuntime Mbean.

DomainRuntime Mbean provides access to the Domain Wide configuration and is available only for the Admin Server.

When connecting to Managed Server, the root would be ServerRuntime MBean and DomainRuntime Mbean is not available

The below post depicts the access to DomainRuntime Mbean.

Navigate to the ‘Create Metrics’ → New → Specify the Metric Collection Properties details by selecting on which type of Mbean you want to configure the Metrics. → Select DomainRuntime

3. Select the Mbean you want to collect metrics for. For demo we would select ‘weblogic.management.runtime.JVMRuntimeMBean’ → Specify which attribute of the Mbean you want to monitor. For instance select ‘HeapSizeMax’.

4. Select the server instance which you want to monitor. Click finish and the collection metrics is created.

5. Now create Watch and Notifications.

The Watch and Notification system can be used to create automated monitors that observe specific diagnostic state and send notifications based on configured rules.

Watch:- It is basically used to monitor the Mbean attributes.

Notifications: There are the events which are triggered based on the values set in the watch. There can be different kind of alerts like SNMP alerts, JMS Messages, JMX notifications etc.

We would be selecting JMS Messages from the notifiers list.

6. Specify the Queue JNDI name and the Connection Factory JNDI name which would be notified when the Watch events are triggered.

7. Once the notification is created. Create a watch to monitor the attributes of the Mbean.

8. Click on the ‘Add Expressions’ to specify the rules for the watch. There can be a set of rules monitoring different attributes.


Here we would monitor the HeapSizeMax attribute of ‘weblogic.management.runtime.JVMRuntimeMBean for demo.

9. Select DomainRuntime from the drop down → Click next and select ”weblogic.management.runtime.JVMRuntimeMBean’ from the drop down list → Select the instance of the server from the drop down list.

10.Select the attribute , you want to monitor. For example HeapSizeMax and specify a value for that rule. Click Next.

Note: Click on combine tab, if you want to have a set of rules for the watch expression.

11. Select ‘Use an automatic reset alarm’ that would reset the notification alarms automatically.

12. Select the JMS Notifier from the left side list so that we can associate the Notifier with the watch created, click finish.

13. Target the WLDF to any of the servers whose MBeans are monitored.

Note: The default polling interval of the Mbean attribute is ‘300000’ milliseconds. We can reconfigure it as per our requirements.

13. Now check the server logs or the server console and you can see the alerts being triggered.

14. Compile and execute the below QueueReceiver.java program to receive the notifications in the form of JMS Messages and listening to queue ‘Queue’.

*****************************************************************************

 

import java.util.Hashtable;

import javax.jms.*;

import javax.naming.Context;

import javax.naming.InitialContext;

import javax.naming.NamingException;

public class QueueReceive implements MessageListener

{

public final static String JNDI_FACTORY=”weblogic.jndi.WLInitialContextFactory”;

public final static String JMS_FACTORY=”CF1″;

public final static String QUEUE=”Queue1″;

private QueueConnectionFactory qconFactory;

private QueueConnection qcon;

private QueueSession qsession;

private QueueReceiver qreceiver;

private Queue queue;

private boolean quit = false;

public void onMessage(Message msg)

{

try {

String msgText;

if (msg instanceof TextMessage) {

msgText = ((TextMessage)msg).getText();

} else {

msgText = msg.toString();

}

System.out.println(“Message Received: “+ msgText );

if (msgText.equalsIgnoreCase(“quit”)) {

synchronized(this) {

quit = true;

this.notifyAll(); // Notify main thread to quit

}

}

} catch (JMSException jmse) {

System.err.println(“An exception occurred: “+jmse.getMessage());

}

}

public void init(Context ctx, String queueName)

throws NamingException, JMSException

{

qconFactory = (QueueConnectionFactory) ctx.lookup(JMS_FACTORY);

qcon = qconFactory.createQueueConnection();

qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

queue = (Queue) ctx.lookup(queueName);

qreceiver = qsession.createReceiver(queue);

qreceiver.setMessageListener(this);

qcon.start();

}

public void close()throws JMSException

{

qreceiver.close();

qsession.close();

qcon.close();

}

public static void main(String[] args) throws Exception {

if (args.length != 1) {

System.out.println(“Usage: java examples.jms.queue.QueueReceive WebLogicURL”);

return;

}

InitialContext ic = getInitialContext(args[0]);

QueueReceive qr = new QueueReceive();

qr.init(ic, QUEUE);

System.out.println(“JMS Ready To Receive Messages (To quit, send a ”quit” message).”);

synchronized(qr) {

while (! qr.quit) {

try {

qr.wait();

} catch (InterruptedException ie) {}

}

}

qr.close();

}

private static InitialContext getInitialContext(String url)

throws NamingException

{

Hashtable<String,String> env = new Hashtable<String,String>();

env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);

env.put(Context.PROVIDER_URL, url);

return new InitialContext(env);

}}

 

*****************************************************************************

Below image shows that the JMS QueueReceiver program is reading the WLDF notifications.

You can put your own business logic inside the QueueReceiver.java’s onMessage() method to specify the business requirements.

Do let us know, if you run into any issues configuring the same.  🙂

Best Regards


6 comments

  1. Hi,

    I am trying to create a metirci on domain runtime and i am getting an error on the console:

    Create operation failed – no Metric Collection created.
    java.lang.NullPointerException

    Could you please help?

  2. Hi Shawn,

    This might occur when after a server reboot you try to create WLDF Harvester. This error occurs because the console is attempting to query the Harvester (Its a component of the WebLogic Diagnostic Framework (WLDF)which gathers metrics from attributes) for the set of MBeans that are available on the server’s DomainRuntime MBeanServeer before the Harvester has finished initializing.

    This occurs only if both (a) the Harvester is not yet initialized and (b) the first Watch created in a WLDF module is being configured for an MBean in the DomainRuntime namespace.

    This is not a serious error.

    Workaround

    Cancel the Watch creation attempt and retry. The NullPointerException error should not occur again.

    Please let me know, how it goes.

    If you experience further issues, enable the below debug flags from Admin Console.

    Click on the Server –> Debug Tab –> Expand WebLogic debug tree –> Diagnostics –> Harvester.

    Click on the Server –> Debug Tab –> Expand WebLogic debug tree –> Diagnostics –> Watch.

    Best Regards,
    Anandraj.

  3. how to get email alerts using the same thing ? Also, this is one rule…is there a guide where i can setup different ruls for ex. get notified when server shuts down or the db connection times out or the application hangs and so on

    1. You can refer the below link for more details.

      https://weblogic-wonders.com/weblogic/2009/12/01/configuration-wldf-mail-notification-for-runtime-mbean/

      You need to set rules on the Mbeans you want to monitor.
      For Ex: For server shutdown you need to access the ServerLifecycleMbean properties like ServerState etc.

      Mbeans could be Runtime or Configuration types.

      The below link provides a list of Mbeans available and their properties that can be accessed using WLDF.

      http://download.oracle.com/docs/cd/E13222_01/wls/docs103/wlsmbeanref/core/index.html

      Regards,
      Anandraj

  4. Very helpful post. I am able to follow these steps successfully. however facing challenge in one of the scenario.

    I need to monitor a cluster. and if CPU utilization goes beyond 80% for any managed server I need a JMS notification. however I am not able to create JMS queue accessible to entire cluster. I tried using migratable target in JMS server. but in WLDF target doesn’t recognize that queue.

    e.g. If I have managed_server_1 & managed_server_2 in a cluster_1.
    while creating JMS server I mention managed_server_1 (migratable) option.
    Next I created a conn factory & JMS queue with JMS server target and subdeployment.

    now in WLDF I select target as cluster_1. Everything works well for managed_server_1. but as soon as I add managed_server_2 in the rule I start getting “NameNotFoundException” for Queue & Connection factory.

    Appreciate if you can provide some guidance on this.

Comments are closed.