速率限制

使用速率限制中间件来限制每秒的请求

The rate limit HTTP middleware allows restricting the maximum number of allowed HTTP requests per second. 速率限制可以保护您的应用程序免受拒绝服务(DOS)攻击。 DOS攻击可以由恶意的第三方发起,也可以由你的软件中的错误发起(也就是 “友军 “DOS攻击)。

配置

根据下述定义,请求正文转换为大写字母:

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: ratelimit
  5. spec:
  6. type: middleware.http.ratelimit
  7. version: v1
  8. metadata:
  9. - name: maxRequestsPerSecond
  10. value: 10

元数据字段规范

字段详情Example
maxRequestsPerSecond按远程IP和路径每秒的最大请求。 需要考虑的是, 限制在每个 Dapr sidecar中独立执行,而不是群集10

一旦达到上限,请求将返回 HTTP Status code 429: Too Many Requests

Alternatively, the max concurrency setting can be used to rate limit applications and applies to all traffic regardless of remote IP or path.

Dapr配置

To be applied, the middleware must be referenced in configuration. See middleware pipelines.

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Configuration
  3. metadata:
  4. name: appconfig
  5. spec:
  6. httpPipeline:
  7. handlers:
  8. - name: ratelimit
  9. type: middleware.http.ratelimit

相关链接