From 939c00c2995e46fa71ce13962892962a4b9c4391 Mon Sep 17 00:00:00 2001 From: dashevchenko Date: Mon, 10 Apr 2023 16:55:20 +0300 Subject: [PATCH] added validation for max value of wsQueueMessagesPerSession --- .../server/controller/plugin/TbWebSocketHandler.java | 9 +++++---- application/src/main/resources/thingsboard.yml | 2 +- .../default-tenant-profile-configuration.component.html | 2 +- ui-ngx/src/app/shared/models/tenant.model.ts | 2 +- ui-ngx/src/assets/locale/locale.constant-en_US.json | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/controller/plugin/TbWebSocketHandler.java b/application/src/main/java/org/thingsboard/server/controller/plugin/TbWebSocketHandler.java index 88bdf0f709..4eceebd98a 100644 --- a/application/src/main/java/org/thingsboard/server/controller/plugin/TbWebSocketHandler.java +++ b/application/src/main/java/org/thingsboard/server/controller/plugin/TbWebSocketHandler.java @@ -84,8 +84,8 @@ public class TbWebSocketHandler extends TextWebSocketHandler implements WebSocke private long sendTimeout; @Value("${server.ws.ping_timeout:30000}") private long pingTimeout; - @Value("${server.ws.default_queue_messages_per_session:1000}") - private int wsQueueMessagesPerSession; + @Value("${server.ws.max_queue_messages_per_session:1000}") + private int wsMaxQueueMessagesPerSession; private final ConcurrentMap blacklistedSessions = new ConcurrentHashMap<>(); private final ConcurrentMap perSessionUpdateLimits = new ConcurrentHashMap<>(); @@ -146,8 +146,9 @@ public class TbWebSocketHandler extends TextWebSocketHandler implements WebSocke } var tenantProfileConfiguration = getTenantProfileConfiguration(sessionRef); internalSessionMap.put(internalSessionId, new SessionMetaData(session, sessionRef, - tenantProfileConfiguration != null && tenantProfileConfiguration.getWsMsgQueueLimitPerSession() > 0 ? - tenantProfileConfiguration.getWsMsgQueueLimitPerSession() : wsQueueMessagesPerSession)); + tenantProfileConfiguration != null && tenantProfileConfiguration.getWsMsgQueueLimitPerSession() > 0 && + tenantProfileConfiguration.getWsMsgQueueLimitPerSession() < wsMaxQueueMessagesPerSession ? + tenantProfileConfiguration.getWsMsgQueueLimitPerSession() : wsMaxQueueMessagesPerSession)); externalSessionMap.put(externalSessionId, internalSessionId); processInWebSocketService(sessionRef, SessionEvent.onEstablished()); diff --git a/application/src/main/resources/thingsboard.yml b/application/src/main/resources/thingsboard.yml index a4c82aac99..4c673d27e2 100644 --- a/application/src/main/resources/thingsboard.yml +++ b/application/src/main/resources/thingsboard.yml @@ -65,7 +65,7 @@ server: max_per_user: "${TB_SERVER_WS_DYNAMIC_PAGE_LINK_MAX_PER_USER:10}" max_entities_per_data_subscription: "${TB_SERVER_WS_MAX_ENTITIES_PER_DATA_SUBSCRIPTION:10000}" max_entities_per_alarm_subscription: "${TB_SERVER_WS_MAX_ENTITIES_PER_ALARM_SUBSCRIPTION:10000}" - default_queue_messages_per_session: "${TB_SERVER_WS_DEFAULT_QUEUE_MESSAGES_PER_SESSION:1000}" + max_queue_messages_per_session: "${TB_SERVER_WS_DEFAULT_QUEUE_MESSAGES_PER_SESSION:1000}" rest: server_side_rpc: # Minimum value of the server side RPC timeout. May override value provided in the REST API call. diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.html b/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.html index 47b75783ae..efa6ef7e13 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.html +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.html @@ -411,7 +411,7 @@ {{ 'tenant-profile.too-small-value-one' | translate}} - {{ 'tenant-profile.value-will-be-dropped-to-default' | translate}} + {{ 'tenant-profile.queue-size-is-limited-by-system-configuration' | translate}}
diff --git a/ui-ngx/src/app/shared/models/tenant.model.ts b/ui-ngx/src/app/shared/models/tenant.model.ts index a3bf7ca869..95e0314a52 100644 --- a/ui-ngx/src/app/shared/models/tenant.model.ts +++ b/ui-ngx/src/app/shared/models/tenant.model.ts @@ -111,7 +111,7 @@ export function createTenantProfileConfiguration(type: TenantProfileType): Tenan maxWsSessionsPerCustomer: 0, maxWsSessionsPerRegularUser: 0, maxWsSessionsPerPublicUser: 0, - wsMsgQueueLimitPerSession: 1000, + wsMsgQueueLimitPerSession: 0, maxWsSubscriptionsPerTenant: 0, maxWsSubscriptionsPerCustomer: 0, maxWsSubscriptionsPerRegularUser: 0, diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 8c97a63d13..07924831c3 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -3576,7 +3576,7 @@ "incorrect-pattern-for-rate-limits": "The format is comma separated pairs of capacity and period (in seconds) with a colon between, e.g. 100:1,2000:60", "too-small-value-zero": "The value must be bigger than 0", "too-small-value-one": "The value must be bigger than 1", - "value-will-be-dropped-to-default": "0 value will be dropped to default", + "queue-size-is-limited-by-system-configuration": "The size of the queue is also limited by the system configuration.", "cassandra-tenant-limits-configuration": "Cassandra query for tenant", "ws-limit-max-sessions-per-tenant": "Sessions per tenant maximum number", "ws-limit-max-sessions-per-customer": "Sessions per customer maximum number",