Java Service to Get Outstanding Events Count from UM Channel (Applicable for Publishable DocType only)

This is a simple Java Service to get the outstanding events count from the UM Channel (Publishable Doc Type) and the same can be enhanced to get the outstanding events count for queue/topic. Make sure to import the below jars into your java project for compilation.

\UniversalMessaging\lib\nAdminAPI.jar

\UniversalMessaging\lib\nClient.jar

Input:

realmURL (eg., nsp://localhost:9001)
channelName (eg., Default:pubDoc)

==================================================================================================================

Output:

outstandingEvents

==================================================================================================================

import com.wm.data.*;
import com.wm.util.Values;
import com.wm.app.b2b.server.Service;
import com.wm.app.b2b.server.ServiceException;
import com.pcbsys.nirvana.client.nIllegalArgumentException;
import com.pcbsys.nirvana.client.nSessionAttributes;
import com.pcbsys.nirvana.nAdminAPI.nAdminIllegalArgumentException;
import com.pcbsys.nirvana.nAdminAPI.nBaseAdminException;
import com.pcbsys.nirvana.nAdminAPI.nLeafNode;
import com.pcbsys.nirvana.nAdminAPI.nNode;
import com.pcbsys.nirvana.nAdminAPI.nRealmNode;

public static final void getOEvents(IData pipeline) throws ServiceException {
// pipeline
IDataCursor pipelineCursor = pipeline.getCursor();
String realmURL = IDataUtil.getString( pipelineCursor, "realmURL" );
String channelName = IDataUtil.getString( pipelineCursor, "channelName" );
channelName=channelName.replace(":", "/");
String channelNS = "wm/is/" + channelName;
String outstandingEvents="";
 
 
nSessionAttributes nsa = null;
try {
nsa = new nSessionAttributes(realmURL);
} catch (nIllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// get the root realm node from the realm admin
nRealmNode realmNode = null;
try {
realmNode = new nRealmNode(nsa);
} catch (nBaseAdminException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
 
 
      realmNode.waitForEntireNameSpace();
      
      try {
  nLeafNode leafNode = (nLeafNode) realmNode.findNode(channelNS);
  try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
      long osEvents=leafNode.getCurrentNumberOfEvents();
       outstandingEvents = Long.toString(osEvents);
 
} catch (nAdminIllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
 
IDataUtil.put( pipelineCursor, "outstandingEvents", outstandingEvents );
pipelineCursor.destroy();
 
}
 

==================================================================================================================

Let me know if you have any questions.