How to get the broker client queue depth(No of documents at

Hi All

We have a requirement where in we need to display the number of documents present in the broker queue at any given point in time.I need a broker API which will give this value ,since this has to be displayed to a different team.I could not find specific infomation about a client in the Broker java API.

Please help me if any you have come across something like this.

Thanks in advance

Mani

Mani,
I wrote this java service to run in the IS to monitor queue length. It returns any queues and their length if the length is greater than a threshold passed to the service. I send out an email when a queue has passed the threshold. You can change it to return all of the client queues.

I pass brokerHost, brokerName, and threshold as input
and return brokerHost, brokerName, and threshold and a document list that includes clientId, queueLength and queueByteSize

import java.io.*
import com.activesw.api.client.*

public static final void CheckQueueLength(IDataPipeline) throws ServiceException
{

IDataHashCursor pipelineCursor = pipeline.getHashCursor();

pipelineCursor.first( “brokerHost” );
String brokerHost = (String) pipelineCursor.getValue();

pipelineCursor.first( “brokerName” );
String brokerName = (String) pipelineCursor.getValue();

pipelineCursor.first( “threshold” );
String threshold = (String) pipelineCursor.getValue();

Long Long_threshold = new Long(threshold);

String clientGroup = “admin”;

BrokerEvent clientEvent;
String clientIds[];

try
{
BrokerAdminClient brokerClient = new BrokerAdminClient(brokerHost, brokerName, null, clientGroup, “Broker Stats Monitor”, null);
clientIds = brokerClient.getClientIds();
try
{

	// Count the number of clients with a queuelenght > than the threshold
	int clientCount = 0;
	for (int i = 0; i < clientIds.length; i++) 
	{
		try 
		{
			clientEvent = brokerClient.getClientStatsById(clientIds[i]);
			Long    l_queueLength = new Long(clientEvent.getLongField("queueLength"));
        	int isGreater = l_queueLength.compareTo(Long_threshold);
			if (isGreater > 0 )
    	    {
				clientCount++;
			}
		}
		catch (BrokerException ex1) 
		{
			brokerClient.destroy();
			return;
		}	
	}

	// clientGroupStats
	IData clientGroupStats[] = new IData[clientCount];
 	int clientIndex = 0;
	for (int i = 0; i < clientIds.length; i++) 
	{
		try 
		{
			clientEvent = brokerClient.getClientStatsById(clientIds[i]);
			
			Long    l_queueLength = new Long(clientEvent.getLongField("queueLength"));
	        int isGreater = l_queueLength.compareTo(Long_threshold);
			if (isGreater > 0 )
        	{
				clientGroupStats[clientIndex] = IDataFactory.create();
				IDataCursor clientGroupStatsCursor = clientGroupStats[clientIndex].getCursor();

				String  s_queueLength = l_queueLength.toString();

				Long    l_queueByteSize = new Long(clientEvent.getLongField("queueByteSize"));
				String  s_queueByteSize = l_queueByteSize.toString();

		   	    clientGroupStatsCursor.last();
				clientGroupStatsCursor.insertAfter("clientId", clientIds[i] );
				clientGroupStatsCursor.insertAfter("queueLength", s_queueLength);
				clientGroupStatsCursor.insertAfter("queueByteSize", s_queueByteSize);
				clientIndex++;
				clientGroupStatsCursor.destroy();			
			}
		} 
		catch (BrokerException ex1) 
		{
			brokerClient.destroy();
			return;
		}
	}
	// clientGroupsCursor.insertAfter("Stats", clientGroupStats);

	pipelineCursor.last();
	pipelineCursor.insertAfter("clientQueueLength", clientGroupStats);
	pipelineCursor.destroy();

	try 
	{
		brokerClient.destroy();
	}
	catch (BrokerException ex) 
	{			
		//log("error on destroy of BrokerServerClient "+ex);
		return;
	}
}
catch (BrokerException ex1) 
{
	//log("broker excception on client statsget\n"+ex1);
	brokerClient.destroy();
	return;
}

}
catch (BrokerException ex2)
{
//log(“broker excception on client statsget\n”+ex2);
return;
}

}

Thanks,
Steve

1 Like

Thanks Steve

I shall try this Java code and come back to you with the results.

Regards

Mani

I see that you are creating Broker Client each time you run this service.

Are u sure this is the best way with respect to performance? Would’nt an entry be made into the HashTable each time a client is created?

Any way to reuse a client?

I have been searching for the best way to create and reuse a client for the service i wrote for broker monitoring.

I’m guessing this is a lower version than current. Anyone ported this to v9.7?

There is no 9.7 broker version.

looking at java code, i believe Java service should work for your version too. It may through some warning for deprecated functions but it should work just fine.

Latest and last broker version is 9.6 and there is will be no major version after this. Kindly refer the broker API for 9.6

@Mani - what is the broker version are using? Have you tried executing the above java code?

We are using IS v9.7 and Broker v9.6. The problem we are seeing is with the import com.activesw.api.client.*

See attachment for details.

Hi,

this is a well known displaying issue when not using Local Service Development.

Local Designer cannot know which classes/jars are available on remote IS.

You should be able to save and compile the service on the remote server even due to this.

Or do you see any compilation error messages in the remote server log?

Regards,
Holger

1 Like

I echo with Holger, did someone execute and see the result ?

Thanks,

I’ve been searching for this solution and based on this one I’ve created mine working on 9.5 version.
As I’ve crated and I think it is much better then previous one - I would like to share with you my version:


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.sun.org.apache.bcel.internal.generic.NEW;
import java.util.ArrayList;
import COM.activesw.api.client.BrokerAdminClient;
import COM.activesw.api.client.BrokerEvent;
import COM.activesw.api.client.BrokerException;
import com.wm.data.IData;
import com.wm.data.IDataCursor;
import com.wm.data.IDataFactory;
import com.wm.data.IDataHashCursor;

public final class readLengthOfTheDocumentsInTheQueue_SVC

{

	/** 
	 * The primary method for the Java service
	 *
	 * @param pipeline
	 *            The IData pipeline
	 * @throws ServiceException
	 */
	public static final void readLengthOfTheDocumentsInTheQueue(IData pipeline)
			throws ServiceException {
		String brokerHost = IDataUtil.getString(pipeline.getCursor(), "brokerHost");
		String brokerName = IDataUtil.getString(pipeline.getCursor(), "brokerName");
		String clientGroup = "admin";
		long totalQueuesLength = 0;
		long totalQueuesSize = 0;
		
		BrokerEvent clientEvent;
		String clientIds[];
		
		try {
			BrokerAdminClient brokerClient = new BrokerAdminClient(brokerHost, brokerName, null, clientGroup, "Broker Stats Monitor", null);
			clientIds = brokerClient.getClientIds();
			ArrayList<IData> list = new ArrayList<IData>();
			for (int i = 0; i < clientIds.length; i++) {
				clientEvent = brokerClient.getClientStatsById(clientIds[i]);
				Long queueLength = new Long(clientEvent.getLongField("queueLength"));
				if (queueLength > 0) {
					IData doc = IDataFactory.create();
					Long queueByteSize = new Long(clientEvent.getLongField("queueByteSize"));
					IDataUtil.put(doc.getCursor(), "clientId", clientIds[i]);
					IDataUtil.put(doc.getCursor(), "queueLength", String.valueOf(queueLength));
					IDataUtil.put(doc.getCursor(), "queueByteSize", String.valueOf(queueByteSize));
					list.add(doc);
					totalQueuesLength += queueLength;
					totalQueuesSize += queueByteSize;
				}
			}
			
			IData[] clientGroupStats = list.toArray(new IData
[list.size()]
);
			IDataUtil.put(pipeline.getCursor(), "totalQueuesLength", String.valueOf(totalQueuesLength));		
			IDataUtil.put(pipeline.getCursor(), "totalQueuesSize", String.valueOf(totalQueuesSize));		
			IDataUtil.put(pipeline.getCursor(), "clientQueueLength", clientGroupStats);		
			try {
				brokerClient.destroy();
			} catch (BrokerException e) {
				e.printStackTrace();
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException("Exception: "+e);
		}
			
	}

Regards,
?ukasz Konkol

Thanks for Sharing this info Lukasz and it certainly helps other users! :smiley:

Cheers!
RMG