Skip to Content

This blog describes how to send automated notifications (after the June-10-2018 update) in case the JMS resources are critical or exhausted using an integration flow.

Automated Notification for Critical or Exhausted JMS Resources

As mentioned in the blog ‘JMS Resources and Size Limits’ only limited resources are available on the JMS broker. To get notified as soon as the resources get critical is required to take early actions to avoid runtime issues.

Scenario Description

To enable the notification we use the OData APIs for JMS queue monitoring in an integration flow.. These APIs can be consumed via https://<tmnUrl>/api/v1 where <tmn> is the address of the tenant management node. Here we will use the API for the JMS broker monitoring via https://<tmnUrl>/api/v1/JmsBrokers(‘Broker1’) . Note that those APIs are only available after the June-10-2018 update!

Overall scenario looks like this:

The flow is triggered by a timer, fetches the JMS Resource data via OData adapter, evaluates the JMS resource status in a script and send a notification mail if the resources are critical or exhausted.

Let’s create the flow.

Create Integration Flow with Timer Start Event and OData Receiver

Create an integration flow with Start Timer Event. Using Request-Reply step call OData APIs to fetch details of the JMS broker via OData receiver channel. Below find the configuration of OData Receiver channel:

Note, that you need to use Operation Read(Get) and enter JmsBrokers(‘Broker1’) as Resource Path.

Read JMS Resources into Properties in Content Modifier

In a Content Modifier step you now read all the JMS resources via XPath into properties:

Create the following properties:

Transactions: XPath to /JmsBrokers/JmsBroker/IsTransactedSessionsHigh

Providers: XPath to /JmsBrokers/JmsBroker/IsProducersHigh

Consumers: XPath to /JmsBrokers/JmsBroker/IsConsumersHigh

Capacity: XPath to /JmsBrokers/JmsBroker/Capacity

MaxCapacity: XPath to /JmsBrokers/JmsBroker/MaxCapacity

Queues: XPath to /JmsBrokers/JmsBroker/QueueNumber

MaxQueues: XPath to /JmsBrokers/JmsBroker/MaxQueueNumber

Evaluate Overall JMS Resource Status via Groovy Script

In a Groovy Script we now calculate the overall JMS resource status. Use the following script code:

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;

def Message processData(Message message) {
    // Get Properties
       map = message.getProperties();
       BigDecimal MaxCapacity = new BigDecimal(map.get("MaxCapacity"));
       BigDecimal Capacity = new BigDecimal(map.get("Capacity"));
       BigDecimal PercentCapacity = Capacity * 100 / MaxCapacity;
       BigDecimal CriticalLimit = MaxCapacity / 100 * 80;
       BigDecimal ExhaustedLimit = MaxCapacity / 100 * 98;       
       MaxQueueNumber = new BigDecimal(map.get("MaxQueues"));
       BigDecimal QueueNumber = new BigDecimal(map.get("Queues"));
       BigDecimal CriticalLimitQueues = MaxQueueNumber - 1;
       
       if (Capacity >= ExhaustedLimit) {
          CapacityStatus = "Exhausted";
       }
       else if (Capacity >= CriticalLimit) {
          CapacityStatus = "Critical";
       }
       else {
          CapacityStatus = "OK";
       }   
       
       if (QueueNumber >= CriticalLimitQueues) {
          QueueStatus = "Critical";
       }
       else {
          QueueStatus = "OK";
       }  
   
       int Consumers = new Integer(map.get("Consumers"));
       if (Consumers == 1) {
         ConsumerStatus = "Critical";
       }
       else {
         ConsumerStatus = "OK";
       }
       
       int Providers = new Integer(map.get("Providers"));
       if (Providers == 1) {
         ProviderStatus = "Critical";
       }
       else {
         ProviderStatus = "OK";
       }
       
       int Transactions = new Integer(map.get("Transactions"));
       if (Transactions == 1) {
         TransactionStatus = "Critical";
       }
       else {
         TransactionStatus = "OK";
       }   
      
      message.setProperty("PercentCapacity", PercentCapacity);
      message.setProperty("CapacityStatus", CapacityStatus);
      message.setProperty("QueueStatus", QueueStatus);
      message.setProperty("ConsumerStatus", ConsumerStatus);
      message.setProperty("ProviderStatus", ProviderStatus);
      message.setProperty("TransactionStatus", TransactionStatus);

       if (Capacity >= ExhaustedLimit)  {
         message.setProperty("JMSStatus", "Exhausted");
       }  
       else if ((CapacityStatus == "Critical") || (QueueStatus == "Critical") ||(ConsumerStatus == "Critical") || (ProviderStatus == "Critical") || (TransactionStatus == "Critical")) {
         message.setProperty("JMSStatus", "Critical");
        } 
       else {
         message.setProperty("JMSStatus", "OK");
       }
       return message;

}

Check JMS Status in Router

In a Router step check the JMS Status and route to the mail receiver in case the JMS resources are critical or exhausted:

Define Non-XML Expression ${property.JMSStatus} = ‘OK’ for the branch going to the End event. Default branch is the branch to the Mail receiver which is executed if the status is not ‘OK’.

Configure Mail Receiver

Now we configure the Mail receiver channel sending out the notification. Configure the mail server and authentication you want to use. In the Mail Attributes define the mail receiver and sender mail address and the Mail Subject and Mail Body:

Subject: JMS Ressources ${property.JMSStatus}

Mail Body:

The JMS Resources on the Cloud Integration tenant are ${property.JMSStatus}.
Overall Queue Capacity Status: ${property.CapacityStatus} (${property.PercentCapacity} Percent)Queues Status: ${property.QueueStatus} (${property.Queues} / ${property.MaxQueues} )
Transactions Status: ${property.TransactionStatus}
Consumer Connections Status: ${property.ConsumerStatus}
Provider Connections Status: ${property.ProviderStatus}

Deploy and Run the Integration Flow

Configure the Timer start event to run the flow every day or any other interval that suits your requirements. Deploy the integration flow.

Now you will get a Email as soon as the JMS resources get critical.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply