'quota' capability for WebSocket API
Overview
Provides an interface for quota-based access. Does not require setup (specifying it in the 'setup' request capabilities list).
In the master domain, the list of keys for quota access is configured. Each connection can request a quota at any time, and the server reports the quota status via events.
A connection can request a quota and abandon it at any time. The system guarantees that within the configured timeouts quotas will be granted to no more than the specified number of connections.
At any time a connection can abandon the quota - either waiting for it or using it after allocation.
A connection can request several different quotas with different keys, and only one quota per specific key at a time.
Requesting a quota
[
"quota_request",
{
"qid":"16066361-dfc0-49f6-b734-9b3dda09db22",
"key": "abc",
"timeout": 30,
"expires": 10
}
]
Required request fields:
-
key- code of an existing quota access group.
Specific request fields:
-
timeout- quota waiting time in seconds. If not specified, the time from the group setting is used, or, if it is also absent, the default value of 60 seconds. -
expires- quota granting time, after which the quota is granted to other connections requesting it.
Response variants
A failure response occurs in one of the following cases:
-
The service is unavailable.
-
The key is not found in the master domain settings.
-
The allocation operation for the specified quota is already active for the connection.
[
"quota_request_result",
{
"qid":"16066361-dfc0-49f6-b734-9b3dda09db22",
"success":false,
"result":"error",
"errormsg":"Quota group not found",
"error_code":1501,
"error_message":"Quota group not found"
}
]
If successfully placed in the waiting queue, a successful response is returned
[
"quota_request_result",
{
"qid":"16066361-dfc0-49f6-b734-9b3dda09db22",
"result":"ok"
}
]
Server events
After successful placement in the queue, as progress occurs, the server sends events to the connection.
-
quota_passed - quota granted.
-
quota_timeout - the quota was not granted within the configured time. The request is interrupted. If necessary, the connection can either proceed with the quota work or place another request.
-
quota_error - a microservice failure occurred. The request is interrupted. If necessary, the connection can either proceed with the quota work or place another request.
[
"quota_passed",
{
"key":"abc"
}
]
[
"quota_timeout",
{
"key":"abc"
}
]
After the quota is successfully granted, the connection is expected to close it after completing the quota work by sending a 'quota_release' request. If this does not happen within the interval set by the 'expires' parameter, the server sends a 'quota_expired' event to the connection and closes it automatically, granting it to another connection from the queue.
[
"quota_expired",
{
"key":"abc"
}
]
Abandoning a quota or waiting
Abandoning a quota should be sent after completing the quota work. The request can also be sent while waiting for quota allocation; then waiting stops and the service request is interrupted.
Closing the connection is equivalent to a 'quota_release' request.
[
"quota_release",
{
"qid":"16066361-dfc0-49f6-b734-9b3dda09db22",
"key": "abc"
}
]
Required request fields:
-
key- code of an existing quota access group.