private CliFunctionResult createFunctionResult(String memberNameOrId, String durableClientId,
      String cqName) {
    try {
      CacheClientNotifier cacheClientNotifier = CacheClientNotifier.getInstance();

      if (cacheClientNotifier == null) {
        return new CliFunctionResult(memberNameOrId, CliFunctionResult.StatusState.ERROR,
            CliStrings.NO_CLIENT_FOUND);
      }

      CacheClientProxy cacheClientProxy = cacheClientNotifier.getClientProxy(durableClientId);
      // Check if the client is present or not
      if (cacheClientProxy == null) {
        return new CliFunctionResult(memberNameOrId, CliFunctionResult.StatusState.ERROR,
            CliStrings.format(CliStrings.NO_CLIENT_FOUND_WITH_CLIENT_ID, durableClientId));
      }

      if (cqName == null || cqName.isEmpty()) {
        return new CliFunctionResult(memberNameOrId, CliFunctionResult.StatusState.OK,
            Integer.toString(cacheClientNotifier.getDurableClientHAQueueSize(durableClientId)));
      }

      CqService cqService = cacheClientProxy.getCache().getCqService();
      if (cqService == null) {
        return new CliFunctionResult(memberNameOrId, CliFunctionResult.StatusState.ERROR,
            CliStrings.COUNT_DURABLE_CQ_EVENTS__NO__CQS__REGISTERED);
      }

      CqQuery cqQuery = cqService.getClientCqFromServer(cacheClientProxy.getProxyID(), cqName);
      if (cqQuery == null) {
        return new CliFunctionResult(memberNameOrId, CliFunctionResult.StatusState.ERROR,
            CliStrings.format(CliStrings.COUNT_DURABLE_CQ_EVENTS__DURABLE_CQ_NOT_FOUND,
                durableClientId, cqName));
      }

      CqQueryVsdStats cqVsdStats = ((InternalCqQuery) cqQuery).getVsdStats();

      if (cqVsdStats == null) {
        return new CliFunctionResult(memberNameOrId, CliFunctionResult.StatusState.ERROR,
            CliStrings.format(
                CliStrings.COUNT_DURABLE_CQ_EVENTS__DURABLE_CQ_STATS_NOT_FOUND,
                durableClientId, cqName));
      }

      long queueSize = cqVsdStats.getNumHAQueuedEvents();
      return new CliFunctionResult(memberNameOrId, CliFunctionResult.StatusState.OK,
          Long.toString(queueSize));
    } catch (Exception e) {
      return new CliFunctionResult(memberNameOrId, CliFunctionResult.StatusState.ERROR,
          e.getMessage());
    }
  }
Function to get subscription-queue-size
geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/functions/GetSubscriptionQueueSizeFunction.java