Repository: wso2/product-microgateway
Issue: Set Application ID instead of UUID for throttle event.

### Description:

There are two IDs associated with application; an incremental ID and a UUID. It is required to use incremental ID rather than UUID, as it is the approach taken by the synapse gateway. This is required to have the deployment pattern where synapse gateway and choreo connect both runs connecting to a single TM instance. 

### Steps to reproduce:
add log publisher for throttle request stream in apim (navigate to /carbon)
Enable global throttling in CC
Invoke.

### Affected Product Version:
choreo-connect-beta

### Environment details (with versions):
- OS:
- Client:
- Env (Docker/K8s):

---
### Optional Fields
#### Related Issues:
<!-- Any related issues from this/other repositories-->

#### Suggested Labels:
<!--Only to be used by non-members-->

#### Suggested Assignees:
<!--Only to be used by non-members-->


Changed files:
enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/security/jwt/APIKeyAuthenticator.java
enforcer-parent/commons/src/main/java/org/wso2/choreo/connect/enforcer/commons/model/AuthenticationContext.java
enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/websocket/MetadataConstants.java
enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/throttle/ThrottleFilter.java
enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/throttle/ThrottleDataHolder.java
enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/analytics/ChoreoFaultAnalyticsProvider.java
enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/websocket/WebSocketThrottleFilter.java
enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/analytics/AnalyticsFilter.java
enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/analytics/ChoreoAnalyticsProvider.java
enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/util/FilterUtils.java
enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/security/KeyValidator.java
enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/constants/MetadataConstants.java
enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/dto/APIKeyValidationInfoDTO.java
enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/server/WebSocketHandler.java
enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/websocket/WebSocketMetaDataFilter.java
enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/security/jwt/JWTAuthenticator.java

diff --git a/enforcer-parent/commons/src/main/java/org/wso2/choreo/connect/enforcer/commons/model/AuthenticationContext.java b/enforcer-parent/commons/src/main/java/org/wso2/choreo/connect/enforcer/commons/model/AuthenticationContext.java
index 514eed52e..c5a78403e 100644
--- a/enforcer-parent/commons/src/main/java/org/wso2/choreo/connect/enforcer/commons/model/AuthenticationContext.java
+++ b/enforcer-parent/commons/src/main/java/org/wso2/choreo/connect/enforcer/commons/model/AuthenticationContext.java
@@ -31,7 +31,8 @@ public class AuthenticationContext {
     private String apiKey;
     private String keyType;
     private String callerToken;
-    private String applicationId;
+    private int applicationId;
+    private String applicationUUID;
     private String applicationName;
     private String consumerKey;
     private String subscriber;
@@ -51,9 +52,9 @@ public class AuthenticationContext {
     public static final String UNKNOWN_VALUE = "__unknown__";
 
     public AuthenticationContext() {
-        this.applicationId = UNKNOWN_VALUE;
         this.apiPublisher = UNKNOWN_VALUE;
-        this.applicationId = UNKNOWN_VALUE;
+        this.applicationUUID = UNKNOWN_VALUE;
+        this.applicationId = -1;
         this.applicationName = UNKNOWN_VALUE;
         this.applicationTier = "Unlimited";
         this.consumerKey = UNKNOWN_VALUE;
@@ -190,15 +191,15 @@ public class AuthenticationContext {
     }
 
     /**
-     * Get the application UUID for the matched application.
+     * Get the application ID for the matched application.
      *
      * @return
      */
-    public String getApplicationId() {
+    public int getApplicationId() {
         return applicationId;
     }
 
-    public void setApplicationId(String applicationId) {
+    public void setApplicationId(int applicationId) {
         this.applicationId = applicationId;
     }
 
@@ -370,4 +371,12 @@ public class AuthenticationContext {
     public void setRawToken(String rawToken) {
         this.rawToken = rawToken;
     }
+
+    public String getApplicationUUID() {
+        return applicationUUID;
+    }
+
+    public void setApplicationUUID(String applicationUUID) {
+        this.applicationUUID = applicationUUID;
+    }
 }
diff --git a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/analytics/AnalyticsFilter.java b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/analytics/AnalyticsFilter.java
index a700334c2..376cfec06 100644
--- a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/analytics/AnalyticsFilter.java
+++ b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/analytics/AnalyticsFilter.java
@@ -127,8 +127,8 @@ public class AnalyticsFilter {
             // Default Value would be PRODUCTION
             requestContext.addMetadataToMap(MetadataConstants.APP_KEY_TYPE_KEY,
                     authContext.getKeyType() == null ? APIConstants.API_KEY_TYPE_PRODUCTION : authContext.getKeyType());
-            requestContext.addMetadataToMap(MetadataConstants.APP_ID_KEY,
-                    AnalyticsUtils.setDefaultIfNull(authContext.getApplicationId()));
+            requestContext.addMetadataToMap(MetadataConstants.APP_UUID_KEY,
+                    AnalyticsUtils.setDefaultIfNull(authContext.getApplicationUUID()));
             requestContext.addMetadataToMap(MetadataConstants.APP_NAME_KEY,
                     AnalyticsUtils.setDefaultIfNull(authContext.getApplicationName()));
             requestContext.addMetadataToMap(MetadataConstants.APP_OWNER_KEY,
diff --git a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/analytics/ChoreoAnalyticsProvider.java b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/analytics/ChoreoAnalyticsProvider.java
index 634187304..9c8a794a0 100644
--- a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/analytics/ChoreoAnalyticsProvider.java
+++ b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/analytics/ChoreoAnalyticsProvider.java
@@ -124,7 +124,7 @@ public class ChoreoAnalyticsProvider implements AnalyticsDataProvider {
         application.setApplicationOwner(getValueAsString(fieldsMap, MetadataConstants.APP_OWNER_KEY));
         application.setApplicationName(getValueAsString(fieldsMap, MetadataConstants.APP_NAME_KEY));
         application.setKeyType(getValueAsString(fieldsMap, MetadataConstants.APP_KEY_TYPE_KEY));
-        application.setApplicationId(getValueAsString(fieldsMap, MetadataConstants.APP_ID_KEY));
+        application.setApplicationId(getValueAsString(fieldsMap, MetadataConstants.APP_UUID_KEY));
         return application;
     }
 
diff --git a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/analytics/ChoreoFaultAnalyticsProvider.java b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/analytics/ChoreoFaultAnalyticsProvider.java
index 21d80ad34..c0277e119 100644
--- a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/analytics/ChoreoFaultAnalyticsProvider.java
+++ b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/analytics/ChoreoFaultAnalyticsProvider.java
@@ -59,7 +59,7 @@ public class ChoreoFaultAnalyticsProvider implements AnalyticsDataProvider {
     @Override
     public boolean isAnonymous() {
         return requestContext.getAuthenticationContext() == null ||
-                StringUtils.isEmpty(requestContext.getAuthenticationContext().getApplicationId());
+                StringUtils.isEmpty(requestContext.getAuthenticationContext().getApplicationUUID());
     }
 
     @Override
@@ -118,7 +118,7 @@ public class ChoreoFaultAnalyticsProvider implements AnalyticsDataProvider {
         // Default Value would be PRODUCTION
         application.setKeyType(
                 authContext.getKeyType() == null ? APIConstants.API_KEY_TYPE_PRODUCTION : authContext.getKeyType());
-        application.setApplicationId(AnalyticsUtils.setDefaultIfNull(authContext.getApplicationId()));
+        application.setApplicationId(AnalyticsUtils.setDefaultIfNull(authContext.getApplicationUUID()));
         application.setApplicationOwner(AnalyticsUtils.setDefaultIfNull(authContext.getSubscriber()));
         application.setApplicationName(AnalyticsUtils.setDefaultIfNull(authContext.getApplicationName()));
         return application;
diff --git a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/constants/MetadataConstants.java b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/constants/MetadataConstants.java
index d6a5c69dc..d63b58f3a 100644
--- a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/constants/MetadataConstants.java
+++ b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/constants/MetadataConstants.java
@@ -34,6 +34,7 @@ public class MetadataConstants {
     public static final String API_ORGANIZATION_ID = WSO2_METADATA_PREFIX + "api-organization-id";
 
     public static final String APP_ID_KEY = WSO2_METADATA_PREFIX + "application-id";
+    public static final String APP_UUID_KEY = WSO2_METADATA_PREFIX + "application-uuid";
     public static final String APP_KEY_TYPE_KEY = WSO2_METADATA_PREFIX + "application-key-type";
     public static final String APP_NAME_KEY = WSO2_METADATA_PREFIX + "application-name";
     public static final String APP_OWNER_KEY = WSO2_METADATA_PREFIX + "application-owner";
diff --git a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/dto/APIKeyValidationInfoDTO.java b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/dto/APIKeyValidationInfoDTO.java
index 4930db085..455b29b3e 100644
--- a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/dto/APIKeyValidationInfoDTO.java
+++ b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/dto/APIKeyValidationInfoDTO.java
@@ -42,7 +42,7 @@ public class APIKeyValidationInfoDTO implements Serializable {
     private String userType;
     private String endUserToken;
     private String endUserName;
-    private String applicationId;
+    private int applicationId;
     private String applicationName;
     private String applicationTier;
     //use this to pass key validation status
@@ -140,11 +140,11 @@ public class APIKeyValidationInfoDTO implements Serializable {
         this.endUserName = endUserName;
     }
 
-    public String getApplicationId() {
+    public int getApplicationId() {
         return applicationId;
     }
 
-    public void setApplicationId(String applicationId) {
+    public void setApplicationId(int applicationId) {
         this.applicationId = applicationId;
     }
 
diff --git a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/security/KeyValidator.java b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/security/KeyValidator.java
index e44e95359..776e9c310 100644
--- a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/security/KeyValidator.java
+++ b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/security/KeyValidator.java
@@ -281,7 +281,8 @@ public class KeyValidator {
         }
         infoDTO.setTier(sub.getPolicyId());
         infoDTO.setSubscriber(app.getSubName());
-        infoDTO.setApplicationId(app.getUUID());
+        infoDTO.setApplicationId(app.getId());
+        infoDTO.setApplicationUUID(app.getUUID());
         infoDTO.setApiName(api.getApiName());
         infoDTO.setApiVersion(api.getApiVersion());
         infoDTO.setApiPublisher(api.getApiProvider());
diff --git a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/security/jwt/APIKeyAuthenticator.java b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/security/jwt/APIKeyAuthenticator.java
index f71c6390c..746a2e049 100644
--- a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/security/jwt/APIKeyAuthenticator.java
+++ b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/security/jwt/APIKeyAuthenticator.java
@@ -273,7 +273,9 @@ public class APIKeyAuthenticator extends APIKeyHandler {
             validationInfoDTO.setType(APIConstants.API_KEY_TYPE_PRODUCTION);
         }
         if (app != null) {
-            validationInfoDTO.setApplicationId(app.getAsString(APIConstants.JwtTokenConstants.APPLICATION_ID));
+            validationInfoDTO.setApplicationId(app.getAsNumber(APIConstants.JwtTokenConstants.APPLICATION_ID)
+                    .intValue());
+            validationInfoDTO.setApplicationUUID(app.getAsString(APIConstants.JwtTokenConstants.APPLICATION_UUID));
             validationInfoDTO.setApplicationName(app.getAsString(APIConstants.JwtTokenConstants.APPLICATION_NAME));
             validationInfoDTO.setApplicationTier(app.getAsString(APIConstants.JwtTokenConstants.APPLICATION_TIER));
             validationInfoDTO.setSubscriber(app.getAsString(APIConstants.JwtTokenConstants.APPLICATION_OWNER));
diff --git a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/security/jwt/JWTAuthenticator.java b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/security/jwt/JWTAuthenticator.java
index 8d92efd37..a5263c0eb 100644
--- a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/security/jwt/JWTAuthenticator.java
+++ b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/security/jwt/JWTAuthenticator.java
@@ -324,7 +324,8 @@ public class JWTAuthenticator implements Authenticator {
                                                                 String kmReference) {
         String applicationRef = APIConstants.ANONYMOUS_PREFIX + kmReference;
         apiKeyValidationInfoDTO.setApplicationName(applicationRef);
-        apiKeyValidationInfoDTO.setApplicationId(
+        apiKeyValidationInfoDTO.setApplicationId(-1);
+        apiKeyValidationInfoDTO.setApplicationUUID(
                 UUID.nameUUIDFromBytes(
                         applicationRef.getBytes(StandardCharsets.UTF_8)).toString());
         apiKeyValidationInfoDTO.setApplicationTier(APIConstants.UNLIMITED_TIER);
@@ -453,7 +454,8 @@ public class JWTAuthenticator implements Authenticator {
             JSONObject app = payload.getJSONObjectClaim(APIConstants.JwtTokenConstants.APPLICATION);
             if (app != null) {
                 validationInfo.setApplicationUUID(app.getAsString(APIConstants.JwtTokenConstants.APPLICATION_UUID));
-                validationInfo.setApplicationId(app.getAsString(APIConstants.JwtTokenConstants.APPLICATION_ID));
+                validationInfo.setApplicationId(app.getAsNumber(APIConstants.JwtTokenConstants.APPLICATION_ID)
+                        .intValue());
                 validationInfo.setApplicationName(app.getAsString(APIConstants.JwtTokenConstants.APPLICATION_NAME));
                 validationInfo.setApplicationTier(app.getAsString(APIConstants.JwtTokenConstants.APPLICATION_TIER));
                 validationInfo.setSubscriber(app.getAsString(APIConstants.JwtTokenConstants.APPLICATION_OWNER));
diff --git a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/server/WebSocketHandler.java b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/server/WebSocketHandler.java
index 5f46712cc..fc50ad820 100644
--- a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/server/WebSocketHandler.java
+++ b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/server/WebSocketHandler.java
@@ -18,6 +18,7 @@
 package org.wso2.choreo.connect.enforcer.server;
 
 import io.opentelemetry.context.Scope;
+import org.apache.commons.lang.StringUtils;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.ThreadContext;
@@ -105,7 +106,11 @@ public class WebSocketHandler implements RequestHandler<WebSocketFrameRequest, W
         String apiKey = extAuthMetadata.get(MetadataConstants.API_KEY);
         String keyType = extAuthMetadata.get(MetadataConstants.KEY_TYPE);
         String callerToken = extAuthMetadata.get(MetadataConstants.CALLER_TOKEN);
-        String applicationId = extAuthMetadata.get(MetadataConstants.APP_ID);
+        int applicationId = -1;
+        if (!StringUtils.isEmpty(extAuthMetadata.get(MetadataConstants.APP_ID))) {
+            applicationId = Integer.parseInt(extAuthMetadata.get(MetadataConstants.APP_ID));
+        }
+
         String applicationName = extAuthMetadata.get(MetadataConstants.APP_NAME);
         String consumerKey = extAuthMetadata.get(MetadataConstants.CONSUMER_KEY);
         String subscriber = extAuthMetadata.get(MetadataConstants.SUBSCRIBER);
diff --git a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/throttle/ThrottleDataHolder.java b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/throttle/ThrottleDataHolder.java
index 81a3750f3..8652e7098 100644
--- a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/throttle/ThrottleDataHolder.java
+++ b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/throttle/ThrottleDataHolder.java
@@ -387,7 +387,7 @@ public class ThrottleDataHolder {
      * @return throttle {@link Decision}
      */
     public Decision isThrottledByCustomPolicy(String userID, String resourceKey, String apiContext, String apiVersion,
-                                             String appTenant, String apiTenant, String appId, String clientIp) {
+                                             String appTenant, String apiTenant, int appId, String clientIp) {
         Decision decision = new Decision();
         if (keyTemplates.size() > 0) {
             for (String key : keyTemplates.keySet()) {
@@ -397,7 +397,7 @@ public class ThrottleDataHolder {
                 key = key.replaceAll("\\\\$apiVersion", apiVersion);
                 key = key.replaceAll("\\\\$appTenant", appTenant);
                 key = key.replaceAll("\\\\$apiTenant", apiTenant);
-                key = key.replaceAll("\\\\$appId", appId);
+                key = key.replaceAll("\\\\$appId", String.valueOf(appId));
 
                 if (clientIp != null) {
                     key = key.replaceAll("\\\\$clientIp", FilterUtils.ipToBigInteger(clientIp).toString());
diff --git a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/throttle/ThrottleFilter.java b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/throttle/ThrottleFilter.java
index f7ca83c3e..19f1a7abf 100644
--- a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/throttle/ThrottleFilter.java
+++ b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/throttle/ThrottleFilter.java
@@ -122,7 +122,7 @@ public class ThrottleFilter implements Filter {
                 APIConfig api = reqContext.getMatchedAPI();
                 String apiContext = api.getBasePath();
                 String apiVersion = api.getVersion();
-                String appId = authContext.getApplicationId();
+                int appId = authContext.getApplicationId();
                 String apiTier = getApiTier(api);
                 String apiThrottleKey = getApiThrottleKey(apiContext, apiVersion);
                 String resourceTier = getResourceTier(reqContext.getMatchedResourcePath());
@@ -202,7 +202,7 @@ public class ThrottleFilter implements Filter {
                 }
 
                 // Checking Application level throttling
-                String appThrottleKey = appId + ':' + authorizedUser;
+                String appThrottleKey = appId + ":" + authorizedUser;
                 Decision appDecision = checkAppLevelThrottled(appThrottleKey, appTier);
                 if (appDecision.isThrottled()) {
                     log.debug("Setting application throttle out response");
@@ -307,11 +307,11 @@ public class ThrottleFilter implements Filter {
         }
 
         throttleEvent.put(ThrottleEventConstants.MESSAGE_ID, requestContext.getRequestID());
-        throttleEvent.put(ThrottleEventConstants.APP_KEY, authContext.getApplicationId() + ':' + authorizedUser);
+        throttleEvent.put(ThrottleEventConstants.APP_KEY, authContext.getApplicationId() + ":" + authorizedUser);
         throttleEvent.put(ThrottleEventConstants.APP_TIER, authContext.getApplicationTier());
         throttleEvent.put(ThrottleEventConstants.API_KEY, apiContext);
         throttleEvent.put(ThrottleEventConstants.API_TIER, apiTier);
-        throttleEvent.put(ThrottleEventConstants.SUBSCRIPTION_KEY, authContext.getApplicationId() + ':' +
+        throttleEvent.put(ThrottleEventConstants.SUBSCRIPTION_KEY, authContext.getApplicationId() + ":" +
                 apiContext);
         throttleEvent.put(ThrottleEventConstants.SUBSCRIPTION_TIER, authContext.getTier());
         throttleEvent.put(ThrottleEventConstants.RESOURCE_KEY, resourceKey);
@@ -322,7 +322,7 @@ public class ThrottleFilter implements Filter {
         throttleEvent.put(ThrottleEventConstants.API_VERSION, apiVersion);
         throttleEvent.put(ThrottleEventConstants.APP_TENANT, authContext.getSubscriberTenantDomain());
         throttleEvent.put(ThrottleEventConstants.API_TENANT, tenantDomain);
-        throttleEvent.put(ThrottleEventConstants.APP_ID, authContext.getApplicationId());
+        throttleEvent.put(ThrottleEventConstants.APP_ID, String.valueOf(authContext.getApplicationId()));
         throttleEvent.put(ThrottleEventConstants.API_NAME, apiName);
         throttleEvent.put(ThrottleEventConstants.PROPERTIES, getProperties(requestContext).toString());
         return throttleEvent;
@@ -346,8 +346,8 @@ public class ThrottleFilter implements Filter {
         return apiThrottleKey;
     }
 
-    private String getSubscriptionThrottleKey(String appId, String apiContext, String apiVersion) {
-        String subThrottleKey = appId + ':' + apiContext;
+    private String getSubscriptionThrottleKey(int appId, String apiContext, String apiVersion) {
+        String subThrottleKey = appId + ":" + apiContext;
         if (!apiVersion.isBlank()) {
             subThrottleKey += ':' + apiVersion;
         }
diff --git a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/util/FilterUtils.java b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/util/FilterUtils.java
index b463d006d..b5a97aae3 100644
--- a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/util/FilterUtils.java
+++ b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/util/FilterUtils.java
@@ -200,7 +200,8 @@ public class FilterUtils {
         }
         // Setting end user as anonymous
         authContext.setUsername(APIConstants.END_USER_ANONYMOUS);
-        authContext.setApplicationId(clientIP);
+        // TODO: (VirajSalaka) clientIP for applicationUUID?
+        authContext.setApplicationUUID(clientIP);
         authContext.setApplicationName(null);
         authContext.setApplicationTier(APIConstants.UNLIMITED_TIER);
         authContext.setSubscriber(APIConstants.END_USER_ANONYMOUS);
@@ -229,6 +230,7 @@ public class FilterUtils {
         if (apiKeyValidationInfoDTO != null) {
             authContext.setKeyType(apiKeyValidationInfoDTO.getType());
             authContext.setApplicationId(apiKeyValidationInfoDTO.getApplicationId());
+            authContext.setApplicationUUID(apiKeyValidationInfoDTO.getApplicationUUID());
             authContext.setApplicationName(apiKeyValidationInfoDTO.getApplicationName());
             authContext.setApplicationTier(apiKeyValidationInfoDTO.getApplicationTier());
             authContext.setSubscriber(apiKeyValidationInfoDTO.getSubscriber());
@@ -328,7 +330,7 @@ public class FilterUtils {
             authContext.setApiUUID(apiUUID);
         }
         authContext.setApplicationName(APIConstants.JwtTokenConstants.INTERNAL_KEY_APP_NAME);
-        authContext.setApplicationId(UUID.nameUUIDFromBytes(APIConstants.JwtTokenConstants.INTERNAL_KEY_APP_NAME.
+        authContext.setApplicationUUID(UUID.nameUUIDFromBytes(APIConstants.JwtTokenConstants.INTERNAL_KEY_APP_NAME.
                 getBytes(StandardCharsets.UTF_8)).toString());
         authContext.setApplicationTier(APIConstants.UNLIMITED_TIER);
         authContext.setSubscriber(APIConstants.JwtTokenConstants.INTERNAL_KEY_APP_NAME);
@@ -368,7 +370,7 @@ public class FilterUtils {
             }
         }
         if (apiKeyValidationInfoDTO != null) {
-            jwtInfoDto.setApplicationId(apiKeyValidationInfoDTO.getApplicationId());
+            jwtInfoDto.setApplicationId(apiKeyValidationInfoDTO.getApplicationUUID());
             jwtInfoDto.setApplicationName(apiKeyValidationInfoDTO.getApplicationName());
             jwtInfoDto.setApplicationTier(apiKeyValidationInfoDTO.getApplicationTier());
             jwtInfoDto.setKeyType(apiKeyValidationInfoDTO.getType());
diff --git a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/websocket/MetadataConstants.java b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/websocket/MetadataConstants.java
index 1766047a5..139724b49 100644
--- a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/websocket/MetadataConstants.java
+++ b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/websocket/MetadataConstants.java
@@ -30,6 +30,7 @@ public class MetadataConstants {
     public static final String KEY_TYPE = "keyType";
     public static final String CALLER_TOKEN = "callerToken";
     public static final String APP_ID = "applicationId";
+    public static final String APP_UUID = "applicationUUID";
     public static final String APP_NAME = "applicationName";
     public static final String CONSUMER_KEY = "consumerKey";
     public static final String SUBSCRIBER = "subscriber";
diff --git a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/websocket/WebSocketMetaDataFilter.java b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/websocket/WebSocketMetaDataFilter.java
index eb3641d56..a4a292f1c 100644
--- a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/websocket/WebSocketMetaDataFilter.java
+++ b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/websocket/WebSocketMetaDataFilter.java
@@ -84,7 +84,10 @@ public class WebSocketMetaDataFilter implements Filter {
             requestContext.addMetadataToMap(MetadataConstants.CALLER_TOKEN,
                     getNullableStringValue(authenticationContext.getCallerToken()));
             requestContext.addMetadataToMap(MetadataConstants.APP_ID,
-                    getNullableStringValue(authenticationContext.getApplicationId()));
+                    String.valueOf(authenticationContext.getApplicationId()));
+            // Unused but added to maintain the consistancy
+            requestContext.addMetadataToMap(MetadataConstants.APP_UUID,
+                    String.valueOf(authenticationContext.getApplicationUUID()));
             requestContext.addMetadataToMap(MetadataConstants.APP_NAME,
                     getNullableStringValue(authenticationContext.getApplicationName()));
             requestContext.addMetadataToMap(MetadataConstants.CONSUMER_KEY,
diff --git a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/websocket/WebSocketThrottleFilter.java b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/websocket/WebSocketThrottleFilter.java
index c867bcd8c..763996124 100644
--- a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/websocket/WebSocketThrottleFilter.java
+++ b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/websocket/WebSocketThrottleFilter.java
@@ -97,7 +97,7 @@ public class WebSocketThrottleFilter implements Filter {
             APIConfig api = requestContext.getMatchedAPI();
             String apiContext = api.getBasePath();
             String apiVersion = api.getVersion();
-            String appId = authContext.getApplicationId();
+            int appId = authContext.getApplicationId();
             String apiTier = getApiTier(api);
             String apiThrottleKey = getApiThrottleKey(apiContext, apiVersion);
             String subTier = authContext.getTier();
@@ -164,7 +164,7 @@ public class WebSocketThrottleFilter implements Filter {
             }
 
             // Checking Application level throttling
-            String appThrottleKey = appId + ':' + authorizedUser;
+            String appThrottleKey = appId + ":" + authorizedUser;
             Decision appDecision = checkAppLevelThrottled(appThrottleKey, appTier);
             if (appDecision.isThrottled()) {
                 log.debug("Setting application throttle out response");
@@ -196,7 +196,7 @@ public class WebSocketThrottleFilter implements Filter {
         return apiThrottleKey;
     }
 
-    private String getSubscriptionThrottleKey(String appId, String apiContext, String apiVersion) {
+    private String getSubscriptionThrottleKey(int appId, String apiContext, String apiVersion) {
         String subThrottleKey = appId + ':' + apiContext;
         if (!apiVersion.isBlank()) {
             subThrottleKey += ':' + apiVersion;
@@ -237,11 +237,11 @@ public class WebSocketThrottleFilter implements Filter {
         }
 
         throttleEvent.put(ThrottleEventConstants.MESSAGE_ID, requestContext.getRequestID());
-        throttleEvent.put(ThrottleEventConstants.APP_KEY, authContext.getApplicationId() + ':' + authorizedUser);
+        throttleEvent.put(ThrottleEventConstants.APP_KEY, authContext.getApplicationId() + ":" + authorizedUser);
         throttleEvent.put(ThrottleEventConstants.APP_TIER, authContext.getApplicationTier());
         throttleEvent.put(ThrottleEventConstants.API_KEY, apiContext);
         throttleEvent.put(ThrottleEventConstants.API_TIER, apiTier);
-        throttleEvent.put(ThrottleEventConstants.SUBSCRIPTION_KEY, authContext.getApplicationId() + ':' +
+        throttleEvent.put(ThrottleEventConstants.SUBSCRIPTION_KEY, authContext.getApplicationId() + ":" +
                 apiContext);
         throttleEvent.put(ThrottleEventConstants.SUBSCRIPTION_TIER, authContext.getTier());
         // TODO: (Praminda) should publish with tenant domain?
@@ -250,7 +250,7 @@ public class WebSocketThrottleFilter implements Filter {
         throttleEvent.put(ThrottleEventConstants.API_VERSION, apiVersion);
         throttleEvent.put(ThrottleEventConstants.APP_TENANT, authContext.getSubscriberTenantDomain());
         throttleEvent.put(ThrottleEventConstants.API_TENANT, tenantDomain);
-        throttleEvent.put(ThrottleEventConstants.APP_ID, authContext.getApplicationId());
+        throttleEvent.put(ThrottleEventConstants.APP_ID, String.valueOf(authContext.getApplicationId()));
         throttleEvent.put(ThrottleEventConstants.API_NAME, apiName);
         throttleEvent.put(ThrottleEventConstants.PROPERTIES, getProperties(requestContext).toString());
         return throttleEvent;