You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/08/01 05:38:45 UTC
[GitHub] [apisix] soulbird opened a new pull request, #7581: docs: add websocket rate limit example
soulbird opened a new pull request, #7581:
URL: https://github.com/apache/apisix/pull/7581
### Description
Fixes #7521
### Checklist
- [ ] I have explained the need for this PR and the problem it solves
- [ ] I have explained the changes or the new features added to this PR
- [ ] I have added tests corresponding to this change
- [ ] I have updated the documentation to reflect this change
- [ ] I have verified that this change is backward compatible (If not, please discuss on the [APISIX mailing list](https://github.com/apache/apisix/tree/master#community) first)
<!--
Note
1. Mark the PR as draft until it's ready to be reviewed.
2. Always add/update tests for any changes unless you have a good reason.
3. Always update the documentation to reflect the changes made in the PR.
4. Make a new commit to resolve conversations instead of `push -f`.
5. To resolve merge conflicts, merge master instead of rebasing.
6. Use "request review" to notify the reviewer after making changes.
7. Only a reviewer can mark a conversation as resolved.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] guoqqqi commented on a diff in pull request #7581: docs: add websocket rate limit example
Posted by GitBox <gi...@apache.org>.
guoqqqi commented on code in PR #7581:
URL: https://github.com/apache/apisix/pull/7581#discussion_r935357268
##########
docs/en/latest/plugins/limit-conn.md:
##########
@@ -141,3 +141,76 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
}
}'
```
+
+## Limit the rate of WebSocket connections
+
+Apache APISIX supports WebSocket proxy, we can use `limit-conn` plugin to limit the number of concurrent WebSocket connections.
+
+1. Create a Route and enable the WebSocket proxy and the `limit-conn` plugin.
+
+````shell
+curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+ "uri": "/ws",
+ "enable_websocket":true,
+ "plugins": {
+ "limit-conn": {
+ "conn": 1,
+ "burst": 0,
+ "default_conn_delay": 0.1,
+ "rejected_code": 503,
+ "key_type": "var",
+ "key": "remote_addr"
+ }
+ },
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": {
+ "127.0.0.1:1980": 1
+ }
+ }
+}'
+````
+
+The above route enables the WebSocket proxy on `/ws`, and limits the number of concurrent WebSocket connections to 1. More than 1 concurrent WebSocket connection will return `503` to reject the request.
Review Comment:
```suggestion
The above route enables the WebSocket proxy on `/ws`, and limits the number of concurrent WebSocket connections to 1 (conn). More than 1 concurrent WebSocket connection will return `503` to reject the request.
```
it seems like better
##########
docs/en/latest/plugins/limit-conn.md:
##########
@@ -141,3 +141,76 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
}
}'
```
+
+## Limit the rate of WebSocket connections
+
+Apache APISIX supports WebSocket proxy, we can use `limit-conn` plugin to limit the number of concurrent WebSocket connections.
+
+1. Create a Route and enable the WebSocket proxy and the `limit-conn` plugin.
+
+````shell
+curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+ "uri": "/ws",
+ "enable_websocket":true,
Review Comment:
```suggestion
"enable_websocket": true,
```
##########
docs/zh/latest/plugins/limit-conn.md:
##########
@@ -136,3 +136,76 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
```
现在就已经移除了 limit-conn 插件了。其他插件的开启和移除也是同样的方法。
+
+## 对 WebSocket 连接限速
+
+Apache APISIX 支持 WebSocket 代理,我们可以使用 `limit-conn` 插件限制 WebSocket 连接的并发数。
+
+1、创建路由并启用 WebSocket 代理和 `limit-conn` 插件
+
+```shell
+curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+ "uri": "/ws",
+ "enable_websocket":true,
+ "plugins": {
+ "limit-conn": {
+ "conn": 1,
+ "burst": 0,
+ "default_conn_delay": 0.1,
+ "rejected_code": 503,
+ "key_type": "var",
+ "key": "remote_addr"
+ }
+ },
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": {
+ "127.0.0.1:1980": 1
+ }
+ }
+}'
+```
+
+上述路由在 `/ws` 上开启了 WebSocket 代理,并限制了 WebSocket 连接并发数 1,超过 1 个并发的 WebSocket 连接将返回 `503` 拒绝请求。
Review Comment:
```suggestion
上述路由在 `/ws` 上开启了 WebSocket 代理,并限制了 WebSocket 连接并发数 1(conn),超过 1 个并发的 WebSocket 连接将返回 `503` 拒绝请求。
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] SylviaBABY merged pull request #7581: docs: add websocket rate limit example
Posted by GitBox <gi...@apache.org>.
SylviaBABY merged PR #7581:
URL: https://github.com/apache/apisix/pull/7581
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] hf400159 commented on a diff in pull request #7581: docs: add websocket rate limit example
Posted by GitBox <gi...@apache.org>.
hf400159 commented on code in PR #7581:
URL: https://github.com/apache/apisix/pull/7581#discussion_r934217967
##########
docs/zh/latest/plugins/limit-conn.md:
##########
@@ -136,3 +136,79 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
```
现在就已经移除了 limit-conn 插件了。其他插件的开启和移除也是同样的方法。
+
+## 对 WebSocket 连接限速
+
+Apache APISIX 支持 WebSocket 代理,我们可以使用 `limit-conn` 插件限制 WebSocket 连接的并发数。
+
+1、启动 WebSocket Server
+
+```shell
+docker run -p 1980:8080 --name websocket-demo casperklein/websocket-demo
+```
+
+2、注册路由,在路由上启用 WebSocket 代理并开启 limit-conn 插件
Review Comment:
```suggestion
2、创建路由并启用 WebSocket 代理和 `limit-conn` 插件。
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] soulbird commented on a diff in pull request #7581: docs: add websocket rate limit example
Posted by GitBox <gi...@apache.org>.
soulbird commented on code in PR #7581:
URL: https://github.com/apache/apisix/pull/7581#discussion_r935583386
##########
docs/zh/latest/plugins/limit-conn.md:
##########
@@ -136,3 +136,76 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
```
现在就已经移除了 limit-conn 插件了。其他插件的开启和移除也是同样的方法。
+
+## 对 WebSocket 连接限速
+
+Apache APISIX 支持 WebSocket 代理,我们可以使用 `limit-conn` 插件限制 WebSocket 连接的并发数。
+
+1、创建路由并启用 WebSocket 代理和 `limit-conn` 插件
+
+```shell
+curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+ "uri": "/ws",
+ "enable_websocket":true,
+ "plugins": {
+ "limit-conn": {
+ "conn": 1,
+ "burst": 0,
+ "default_conn_delay": 0.1,
+ "rejected_code": 503,
+ "key_type": "var",
+ "key": "remote_addr"
+ }
+ },
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": {
+ "127.0.0.1:1980": 1
+ }
+ }
+}'
+```
+
+上述路由在 `/ws` 上开启了 WebSocket 代理,并限制了 WebSocket 连接并发数 1,超过 1 个并发的 WebSocket 连接将返回 `503` 拒绝请求。
Review Comment:
How about "上述路由在 `/ws` 上开启了 WebSocket 代理,并限制了 WebSocket 连接并发数为 1" ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] juzhiyuan commented on a diff in pull request #7581: docs: add websocket rate limit example
Posted by GitBox <gi...@apache.org>.
juzhiyuan commented on code in PR #7581:
URL: https://github.com/apache/apisix/pull/7581#discussion_r934210347
##########
docs/zh/latest/plugins/limit-conn.md:
##########
@@ -136,3 +136,79 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
```
现在就已经移除了 limit-conn 插件了。其他插件的开启和移除也是同样的方法。
+
+## 对 WebSocket 链接限速
Review Comment:
```suggestion
## 对 WebSocket 连接限速
```
##########
docs/zh/latest/plugins/limit-conn.md:
##########
@@ -136,3 +136,79 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
```
现在就已经移除了 limit-conn 插件了。其他插件的开启和移除也是同样的方法。
+
+## 对 WebSocket 链接限速
Review Comment:
Hey @navendu-pottekkat and @hf400159, please have a review when available 🙏
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] soulbird commented on pull request #7581: docs: add websocket rate limit example
Posted by GitBox <gi...@apache.org>.
soulbird commented on PR #7581:
URL: https://github.com/apache/apisix/pull/7581#issuecomment-1202274289
> Do we have documentation for WebSocket? I feel that this PR should not be submitted to the limit conn part
In APISIX, there is currently no special document to describe websocket related functions
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] soulbird commented on a diff in pull request #7581: docs: add websocket rate limit example
Posted by GitBox <gi...@apache.org>.
soulbird commented on code in PR #7581:
URL: https://github.com/apache/apisix/pull/7581#discussion_r935584284
##########
docs/en/latest/plugins/limit-conn.md:
##########
@@ -141,3 +141,76 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
}
}'
```
+
+## Limit the rate of WebSocket connections
Review Comment:
How about `Limit the number of concurrent WebSocket connections` ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] hf400159 commented on a diff in pull request #7581: docs: add websocket rate limit example
Posted by GitBox <gi...@apache.org>.
hf400159 commented on code in PR #7581:
URL: https://github.com/apache/apisix/pull/7581#discussion_r934229818
##########
docs/en/latest/plugins/limit-conn.md:
##########
@@ -141,3 +141,79 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
}
}'
```
+
+## Limit the rate of WebSocket connections
Review Comment:
I think you can simplify this step. We don't have to tell the user how to create a WebSocket Server.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] SkyeYoung commented on a diff in pull request #7581: docs: add websocket rate limit example
Posted by GitBox <gi...@apache.org>.
SkyeYoung commented on code in PR #7581:
URL: https://github.com/apache/apisix/pull/7581#discussion_r935354436
##########
docs/en/latest/plugins/limit-conn.md:
##########
@@ -141,3 +141,76 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
}
}'
```
+
+## Limit the rate of WebSocket connections
+
+Apache APISIX supports WebSocket proxy, we can use `limit-conn` plugin to limit the number of concurrent WebSocket connections.
+
+1. Create a Route and enable the WebSocket proxy and the `limit-conn` plugin.
Review Comment:
```suggestion
1. Create a Route, enable the WebSocket proxy and the `limit-conn` plugin.
```
too much `and`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] SylviaBABY commented on a diff in pull request #7581: docs: add websocket rate limit example
Posted by GitBox <gi...@apache.org>.
SylviaBABY commented on code in PR #7581:
URL: https://github.com/apache/apisix/pull/7581#discussion_r934165093
##########
docs/en/latest/plugins/limit-conn.md:
##########
@@ -141,3 +141,79 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
}
}'
```
+
+## Limit the rate of WebSocket connections
+
+Apache APISIX supports WebSocket proxy, we can use limit-conn plugin to limit the number of concurrent WebSocket connections.
Review Comment:
```suggestion
Apache APISIX supports WebSocket proxy, we can use `limit-conn` plugin to limit the number of concurrent WebSocket connections.
```
##########
docs/en/latest/plugins/limit-conn.md:
##########
@@ -141,3 +141,79 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
}
}'
```
+
+## Limit the rate of WebSocket connections
+
+Apache APISIX supports WebSocket proxy, we can use limit-conn plugin to limit the number of concurrent WebSocket connections.
+
+1. Start WebSocket Server
+
+````
+docker run -p 1980:8080 --name websocket-demo casperklein/websocket-demo
+````
+
+2. Register the route, enable the WebSocket proxy on the route and enable the limit-conn plugin
+
+````
+curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+ "uri": "/ws",
+ "enable_websocket":true,
+ "plugins": {
+ "limit-conn": {
+ "conn": 1,
+ "burst": 0,
+ "default_conn_delay": 0.1,
+ "rejected_code": 503,
+ "key_type": "var",
+ "key": "remote_addr"
+ }
+ },
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": {
+ "127.0.0.1:1980": 1
+ }
+ }
+}'
+````
+
+The above route enables the WebSocket proxy on `/ws`, and limits the number of concurrent WebSocket connections to 1. More than 1 concurrent WebSocket connection will return 503 to reject the request.
+
+3. Initiate a WebSocket request, and the link is established successfully
+
+````
Review Comment:
```suggestion
````shell
```
##########
docs/zh/latest/plugins/limit-conn.md:
##########
@@ -136,3 +136,79 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
```
现在就已经移除了 limit-conn 插件了。其他插件的开启和移除也是同样的方法。
+
+## 对 WebSocket 链接限速
+
+Apache APISIX 支持 WebSocket 代理,我们可以使用 limit-conn 插件限制 WebSocket 链接的并发数。
Review Comment:
```suggestion
Apache APISIX 支持 WebSocket 代理,我们可以使用 `limit-conn` 插件限制 WebSocket 链接的并发数。
```
##########
docs/zh/latest/plugins/limit-conn.md:
##########
@@ -136,3 +136,79 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
```
现在就已经移除了 limit-conn 插件了。其他插件的开启和移除也是同样的方法。
+
+## 对 WebSocket 链接限速
+
+Apache APISIX 支持 WebSocket 代理,我们可以使用 limit-conn 插件限制 WebSocket 链接的并发数。
+
+1、启动 WebSocket Server
+
+```
+docker run -p 1980:8080 --name websocket-demo casperklein/websocket-demo
+```
+
+2、注册路由,在路由上启用 WebSocket 代理并开启 limit-conn 插件
+
+```
Review Comment:
```suggestion
```shell
```
##########
docs/en/latest/plugins/limit-conn.md:
##########
@@ -141,3 +141,79 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
}
}'
```
+
+## Limit the rate of WebSocket connections
+
+Apache APISIX supports WebSocket proxy, we can use limit-conn plugin to limit the number of concurrent WebSocket connections.
+
+1. Start WebSocket Server
+
+````
Review Comment:
```suggestion
````shell
```
##########
docs/zh/latest/plugins/limit-conn.md:
##########
@@ -39,7 +39,7 @@ title: limit-conn
| rejected_msg | string | 否 | | 非空 | 当请求超过 `conn` + `burst` 这个阈值时,返回的响应体。 |
| allow_degradation | boolean | 否 | false | | 当插件功能临时不可用时是否允许请求继续。当值设置为 true 时则自动允许请求继续,默认值是 false。 |
-### 如何启用
+## 开启插件
下面是一个示例,在指定的 route 上开启了 limit-conn 插件,并设置 `key_type` 为 `var`:
Review Comment:
```suggestion
下面是一个示例,在指定的路由上开启了 `limit-conn` 插件,并设置 `key_type` 为 `var`:
```
##########
docs/en/latest/plugins/limit-conn.md:
##########
@@ -141,3 +141,79 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
}
}'
```
+
+## Limit the rate of WebSocket connections
+
+Apache APISIX supports WebSocket proxy, we can use limit-conn plugin to limit the number of concurrent WebSocket connections.
+
+1. Start WebSocket Server
+
+````
+docker run -p 1980:8080 --name websocket-demo casperklein/websocket-demo
+````
+
+2. Register the route, enable the WebSocket proxy on the route and enable the limit-conn plugin
+
+````
Review Comment:
```suggestion
````shell
```
##########
docs/zh/latest/plugins/limit-conn.md:
##########
@@ -136,3 +136,79 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
```
现在就已经移除了 limit-conn 插件了。其他插件的开启和移除也是同样的方法。
+
+## 对 WebSocket 链接限速
+
+Apache APISIX 支持 WebSocket 代理,我们可以使用 limit-conn 插件限制 WebSocket 链接的并发数。
+
+1、启动 WebSocket Server
+
+```
Review Comment:
```suggestion
```shell
```
##########
docs/zh/latest/plugins/limit-conn.md:
##########
@@ -136,3 +136,79 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
```
现在就已经移除了 limit-conn 插件了。其他插件的开启和移除也是同样的方法。
+
+## 对 WebSocket 链接限速
+
+Apache APISIX 支持 WebSocket 代理,我们可以使用 limit-conn 插件限制 WebSocket 链接的并发数。
+
+1、启动 WebSocket Server
+
+```
+docker run -p 1980:8080 --name websocket-demo casperklein/websocket-demo
+```
+
+2、注册路由,在路由上启用 WebSocket 代理并开启 limit-conn 插件
+
+```
+curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+ "uri": "/ws",
+ "enable_websocket":true,
+ "plugins": {
+ "limit-conn": {
+ "conn": 1,
+ "burst": 0,
+ "default_conn_delay": 0.1,
+ "rejected_code": 503,
+ "key_type": "var",
+ "key": "remote_addr"
+ }
+ },
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": {
+ "127.0.0.1:1980": 1
+ }
+ }
+}'
+```
+
+上述路由在 `/ws` 上开启了 WebSocket 代理,并限制了 WebSocket 链接并发数 1,超过 1 个并发的 WebSocket 链接将返回 503 拒绝请求。
+
+3、发起 WebSocket 请求,链接建立成功
+
+```
Review Comment:
```suggestion
```shell
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] moonming commented on pull request #7581: docs: add websocket rate limit example
Posted by GitBox <gi...@apache.org>.
moonming commented on PR #7581:
URL: https://github.com/apache/apisix/pull/7581#issuecomment-1202271776
Do we have documentation for WebSocket? I feel that this PR should not be submitted to the limit conn part
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] moonming commented on a diff in pull request #7581: docs: add websocket rate limit example
Posted by GitBox <gi...@apache.org>.
moonming commented on code in PR #7581:
URL: https://github.com/apache/apisix/pull/7581#discussion_r935378216
##########
docs/zh/latest/plugins/limit-conn.md:
##########
@@ -136,3 +136,76 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
```
现在就已经移除了 limit-conn 插件了。其他插件的开启和移除也是同样的方法。
+
+## 对 WebSocket 连接限速
Review Comment:
`限速` or `限制并发数`?
##########
docs/en/latest/plugins/limit-conn.md:
##########
@@ -141,3 +141,76 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
}
}'
```
+
+## Limit the rate of WebSocket connections
+
+Apache APISIX supports WebSocket proxy, we can use `limit-conn` plugin to limit the number of concurrent WebSocket connections.
+
+1. Create a Route and enable the WebSocket proxy and the `limit-conn` plugin.
+
+````shell
+curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+ "uri": "/ws",
+ "enable_websocket":true,
+ "plugins": {
+ "limit-conn": {
+ "conn": 1,
+ "burst": 0,
+ "default_conn_delay": 0.1,
+ "rejected_code": 503,
+ "key_type": "var",
+ "key": "remote_addr"
+ }
+ },
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": {
+ "127.0.0.1:1980": 1
+ }
+ }
+}'
+````
+
+The above route enables the WebSocket proxy on `/ws`, and limits the number of concurrent WebSocket connections to 1. More than 1 concurrent WebSocket connection will return `503` to reject the request.
+
+2. Initiate a WebSocket request, and the link is established successfully
Review Comment:
```suggestion
2. Initiate a WebSocket request, and the connection is established successfully
```
##########
docs/en/latest/plugins/limit-conn.md:
##########
@@ -141,3 +141,76 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
}
}'
```
+
+## Limit the rate of WebSocket connections
Review Comment:
```suggestion
## Limit connections of WebSocket
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] soulbird commented on a diff in pull request #7581: docs: add websocket rate limit example
Posted by GitBox <gi...@apache.org>.
soulbird commented on code in PR #7581:
URL: https://github.com/apache/apisix/pull/7581#discussion_r934231150
##########
docs/zh/latest/plugins/limit-conn.md:
##########
@@ -136,3 +136,79 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
```
现在就已经移除了 limit-conn 插件了。其他插件的开启和移除也是同样的方法。
+
+## 对 WebSocket 连接限速
+
+Apache APISIX 支持 WebSocket 代理,我们可以使用 `limit-conn` 插件限制 WebSocket 连接的并发数。
+
+1、启动 WebSocket Server
+
+```shell
+docker run -p 1980:8080 --name websocket-demo casperklein/websocket-demo
+```
+
+2、注册路由,在路由上启用 WebSocket 代理并开启 limit-conn 插件
+
+```shell
+curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+ "uri": "/ws",
+ "enable_websocket":true,
+ "plugins": {
+ "limit-conn": {
+ "conn": 1,
+ "burst": 0,
+ "default_conn_delay": 0.1,
+ "rejected_code": 503,
+ "key_type": "var",
+ "key": "remote_addr"
+ }
+ },
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": {
+ "127.0.0.1:1980": 1
+ }
+ }
+}'
+```
+
+上述路由在 `/ws` 上开启了 WebSocket 代理,并限制了 WebSocket 连接并发数 1,超过 1 个并发的 WebSocket 连接将返回 503 拒绝请求。
+
+3、发起 WebSocket 请求,连接建立成功
+
+```shell
+curl --include \
+ --no-buffer \
+ --header "Connection: Upgrade" \
+ --header "Upgrade: websocket" \
+ --header "Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==" \
+ --header "Sec-WebSocket-Version: 13" \
+ --http1.1 \
+ http://127.0.0.1:9080/ws
+
+HTTP/1.1 101 Switching Protocols
+Connection: upgrade
+Upgrade: websocket
+Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk=
+Server: APISIX/2.15.0
+```
+
+4、在另一个终端中再次发起 WebSocket 请求,请求将被拒绝
+
+```shell
+HTTP/1.1 503 Service Temporarily Unavailable
+Date: Mon, 01 Aug 2022 03:49:17 GMT
+Content-Type: text/html; charset=utf-8
+Content-Length: 194
+Connection: keep-alive
+Server: APISIX/2.15.0
+
+<html>
+<head><title>503 Service Temporarily Unavailable</title></head>
+<body>
+<center><h1>503 Service Temporarily Unavailable</h1></center>
+<hr><center>openresty</center>
+</body>
+</html>
+```
Review Comment:
Both of these are response data
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] hf400159 commented on a diff in pull request #7581: docs: add websocket rate limit example
Posted by GitBox <gi...@apache.org>.
hf400159 commented on code in PR #7581:
URL: https://github.com/apache/apisix/pull/7581#discussion_r934217967
##########
docs/zh/latest/plugins/limit-conn.md:
##########
@@ -136,3 +136,79 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
```
现在就已经移除了 limit-conn 插件了。其他插件的开启和移除也是同样的方法。
+
+## 对 WebSocket 连接限速
+
+Apache APISIX 支持 WebSocket 代理,我们可以使用 `limit-conn` 插件限制 WebSocket 连接的并发数。
+
+1、启动 WebSocket Server
+
+```shell
+docker run -p 1980:8080 --name websocket-demo casperklein/websocket-demo
+```
+
+2、注册路由,在路由上启用 WebSocket 代理并开启 limit-conn 插件
Review Comment:
```suggestion
2、创建路由并启用 WebSocket 代理以及配置 `limit-conn` 插件。
```
##########
docs/zh/latest/plugins/limit-conn.md:
##########
@@ -136,3 +136,79 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
```
现在就已经移除了 limit-conn 插件了。其他插件的开启和移除也是同样的方法。
+
+## 对 WebSocket 连接限速
+
+Apache APISIX 支持 WebSocket 代理,我们可以使用 `limit-conn` 插件限制 WebSocket 连接的并发数。
+
+1、启动 WebSocket Server
+
+```shell
+docker run -p 1980:8080 --name websocket-demo casperklein/websocket-demo
+```
+
+2、注册路由,在路由上启用 WebSocket 代理并开启 limit-conn 插件
+
+```shell
+curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+ "uri": "/ws",
+ "enable_websocket":true,
+ "plugins": {
+ "limit-conn": {
+ "conn": 1,
+ "burst": 0,
+ "default_conn_delay": 0.1,
+ "rejected_code": 503,
+ "key_type": "var",
+ "key": "remote_addr"
+ }
+ },
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": {
+ "127.0.0.1:1980": 1
+ }
+ }
+}'
+```
+
+上述路由在 `/ws` 上开启了 WebSocket 代理,并限制了 WebSocket 连接并发数 1,超过 1 个并发的 WebSocket 连接将返回 503 拒绝请求。
+
+3、发起 WebSocket 请求,连接建立成功
+
+```shell
+curl --include \
+ --no-buffer \
+ --header "Connection: Upgrade" \
+ --header "Upgrade: websocket" \
+ --header "Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==" \
+ --header "Sec-WebSocket-Version: 13" \
+ --http1.1 \
+ http://127.0.0.1:9080/ws
+
+HTTP/1.1 101 Switching Protocols
+Connection: upgrade
+Upgrade: websocket
+Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk=
+Server: APISIX/2.15.0
+```
Review Comment:
**command** and **response** are represented by two code blocks.
##########
docs/en/latest/plugins/limit-conn.md:
##########
@@ -141,3 +141,79 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
}
}'
```
+
+## Limit the rate of WebSocket connections
+
+Apache APISIX supports WebSocket proxy, we can use `limit-conn` plugin to limit the number of concurrent WebSocket connections.
+
+1. Start WebSocket Server
+
+````shell
+docker run -p 1980:8080 --name websocket-demo casperklein/websocket-demo
+````
+
+2. Register the route, enable the WebSocket proxy on the route and enable the limit-conn plugin
Review Comment:
```suggestion
2. Create a Route and enable the WebSocket proxy and the `limit-conn` plugin.
```
##########
docs/zh/latest/plugins/limit-conn.md:
##########
@@ -136,3 +136,79 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
```
现在就已经移除了 limit-conn 插件了。其他插件的开启和移除也是同样的方法。
+
+## 对 WebSocket 连接限速
+
+Apache APISIX 支持 WebSocket 代理,我们可以使用 `limit-conn` 插件限制 WebSocket 连接的并发数。
+
+1、启动 WebSocket Server
+
+```shell
+docker run -p 1980:8080 --name websocket-demo casperklein/websocket-demo
+```
+
+2、注册路由,在路由上启用 WebSocket 代理并开启 limit-conn 插件
+
+```shell
+curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+ "uri": "/ws",
+ "enable_websocket":true,
+ "plugins": {
+ "limit-conn": {
+ "conn": 1,
+ "burst": 0,
+ "default_conn_delay": 0.1,
+ "rejected_code": 503,
+ "key_type": "var",
+ "key": "remote_addr"
+ }
+ },
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": {
+ "127.0.0.1:1980": 1
+ }
+ }
+}'
+```
+
+上述路由在 `/ws` 上开启了 WebSocket 代理,并限制了 WebSocket 连接并发数 1,超过 1 个并发的 WebSocket 连接将返回 503 拒绝请求。
Review Comment:
```suggestion
上述路由在 `/ws` 上开启了 WebSocket 代理,并限制了 WebSocket 连接并发数 1,超过 1 个并发的 WebSocket 连接将返回 `503` 拒绝请求。
```
##########
docs/en/latest/plugins/limit-conn.md:
##########
@@ -141,3 +141,79 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
}
}'
```
+
+## Limit the rate of WebSocket connections
+
+Apache APISIX supports WebSocket proxy, we can use `limit-conn` plugin to limit the number of concurrent WebSocket connections.
+
+1. Start WebSocket Server
+
+````shell
+docker run -p 1980:8080 --name websocket-demo casperklein/websocket-demo
+````
+
+2. Register the route, enable the WebSocket proxy on the route and enable the limit-conn plugin
+
+````shell
+curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+ "uri": "/ws",
+ "enable_websocket":true,
+ "plugins": {
+ "limit-conn": {
+ "conn": 1,
+ "burst": 0,
+ "default_conn_delay": 0.1,
+ "rejected_code": 503,
+ "key_type": "var",
+ "key": "remote_addr"
+ }
+ },
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": {
+ "127.0.0.1:1980": 1
+ }
+ }
+}'
+````
+
+The above route enables the WebSocket proxy on `/ws`, and limits the number of concurrent WebSocket connections to 1. More than 1 concurrent WebSocket connection will return 503 to reject the request.
+
+3. Initiate a WebSocket request, and the link is established successfully
+
+````shell
+curl --include \
+ --no-buffer \
+ --header "Connection: Upgrade" \
+ --header "Upgrade: websocket" \
+ --header "Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==" \
+ --header "Sec-WebSocket-Version: 13" \
+ --http1.1 \
+ http://127.0.0.1:9080/ws
+
+HTTP/1.1 101 Switching Protocols
+Connection: upgrade
+Upgrade: websocket
+Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk=
+Server: APISIX/2.15.0
+````
Review Comment:
**command** and **response** are represented by two code blocks.
##########
docs/zh/latest/plugins/limit-conn.md:
##########
@@ -136,3 +136,79 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
```
现在就已经移除了 limit-conn 插件了。其他插件的开启和移除也是同样的方法。
+
+## 对 WebSocket 连接限速
+
+Apache APISIX 支持 WebSocket 代理,我们可以使用 `limit-conn` 插件限制 WebSocket 连接的并发数。
+
+1、启动 WebSocket Server
+
+```shell
+docker run -p 1980:8080 --name websocket-demo casperklein/websocket-demo
+```
+
+2、注册路由,在路由上启用 WebSocket 代理并开启 limit-conn 插件
+
+```shell
+curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+ "uri": "/ws",
+ "enable_websocket":true,
+ "plugins": {
+ "limit-conn": {
+ "conn": 1,
+ "burst": 0,
+ "default_conn_delay": 0.1,
+ "rejected_code": 503,
+ "key_type": "var",
+ "key": "remote_addr"
+ }
+ },
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": {
+ "127.0.0.1:1980": 1
+ }
+ }
+}'
+```
+
+上述路由在 `/ws` 上开启了 WebSocket 代理,并限制了 WebSocket 连接并发数 1,超过 1 个并发的 WebSocket 连接将返回 503 拒绝请求。
+
+3、发起 WebSocket 请求,连接建立成功
+
+```shell
+curl --include \
+ --no-buffer \
+ --header "Connection: Upgrade" \
+ --header "Upgrade: websocket" \
+ --header "Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==" \
+ --header "Sec-WebSocket-Version: 13" \
+ --http1.1 \
+ http://127.0.0.1:9080/ws
+
+HTTP/1.1 101 Switching Protocols
+Connection: upgrade
+Upgrade: websocket
+Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk=
+Server: APISIX/2.15.0
+```
+
+4、在另一个终端中再次发起 WebSocket 请求,请求将被拒绝
+
+```shell
+HTTP/1.1 503 Service Temporarily Unavailable
+Date: Mon, 01 Aug 2022 03:49:17 GMT
+Content-Type: text/html; charset=utf-8
+Content-Length: 194
+Connection: keep-alive
+Server: APISIX/2.15.0
+
+<html>
+<head><title>503 Service Temporarily Unavailable</title></head>
+<body>
+<center><h1>503 Service Temporarily Unavailable</h1></center>
+<hr><center>openresty</center>
+</body>
+</html>
+```
Review Comment:
ditto
##########
docs/en/latest/plugins/limit-conn.md:
##########
@@ -141,3 +141,79 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
}
}'
```
+
+## Limit the rate of WebSocket connections
+
+Apache APISIX supports WebSocket proxy, we can use `limit-conn` plugin to limit the number of concurrent WebSocket connections.
+
+1. Start WebSocket Server
+
+````shell
+docker run -p 1980:8080 --name websocket-demo casperklein/websocket-demo
+````
+
+2. Register the route, enable the WebSocket proxy on the route and enable the limit-conn plugin
+
+````shell
+curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+ "uri": "/ws",
+ "enable_websocket":true,
+ "plugins": {
+ "limit-conn": {
+ "conn": 1,
+ "burst": 0,
+ "default_conn_delay": 0.1,
+ "rejected_code": 503,
+ "key_type": "var",
+ "key": "remote_addr"
+ }
+ },
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": {
+ "127.0.0.1:1980": 1
+ }
+ }
+}'
+````
+
+The above route enables the WebSocket proxy on `/ws`, and limits the number of concurrent WebSocket connections to 1. More than 1 concurrent WebSocket connection will return 503 to reject the request.
+
+3. Initiate a WebSocket request, and the link is established successfully
+
+````shell
+curl --include \
+ --no-buffer \
+ --header "Connection: Upgrade" \
+ --header "Upgrade: websocket" \
+ --header "Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==" \
+ --header "Sec-WebSocket-Version: 13" \
+ --http1.1 \
+ http://127.0.0.1:9080/ws
+
+HTTP/1.1 101 Switching Protocols
+Connection: upgrade
+Upgrade: websocket
+Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk=
+Server: APISIX/2.15.0
+````
+
+4. Initiate the WebSocket request again in another terminal, the request will be rejected
+
+````shell
+HTTP/1.1 503 Service Temporarily Unavailable
+Date: Mon, 01 Aug 2022 03:49:17 GMT
+Content-Type: text/html; charset=utf-8
+Content-Length: 194
+Connection: keep-alive
+Server: APISIX/2.15.0
+
+<html>
+<head><title>503 Service Temporarily Unavailable</title></head>
+<body>
+<center><h1>503 Service Temporarily Unavailable</h1></center>
+<hr><center>openresty</center>
+</body>
+</html>
Review Comment:
ditto
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] hf400159 commented on a diff in pull request #7581: docs: add websocket rate limit example
Posted by GitBox <gi...@apache.org>.
hf400159 commented on code in PR #7581:
URL: https://github.com/apache/apisix/pull/7581#discussion_r934227000
##########
docs/en/latest/plugins/limit-conn.md:
##########
@@ -141,3 +141,79 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
}
}'
```
+
+## Limit the rate of WebSocket connections
+
+Apache APISIX supports WebSocket proxy, we can use `limit-conn` plugin to limit the number of concurrent WebSocket connections.
+
+1. Start WebSocket Server
+
+````shell
+docker run -p 1980:8080 --name websocket-demo casperklein/websocket-demo
+````
+
+2. Register the route, enable the WebSocket proxy on the route and enable the limit-conn plugin
+
+````shell
+curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+ "uri": "/ws",
+ "enable_websocket":true,
+ "plugins": {
+ "limit-conn": {
+ "conn": 1,
+ "burst": 0,
+ "default_conn_delay": 0.1,
+ "rejected_code": 503,
+ "key_type": "var",
+ "key": "remote_addr"
+ }
+ },
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": {
+ "127.0.0.1:1980": 1
+ }
+ }
+}'
+````
+
+The above route enables the WebSocket proxy on `/ws`, and limits the number of concurrent WebSocket connections to 1. More than 1 concurrent WebSocket connection will return 503 to reject the request.
+
+3. Initiate a WebSocket request, and the link is established successfully
+
+````shell
+curl --include \
+ --no-buffer \
+ --header "Connection: Upgrade" \
+ --header "Upgrade: websocket" \
+ --header "Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==" \
+ --header "Sec-WebSocket-Version: 13" \
+ --http1.1 \
+ http://127.0.0.1:9080/ws
+
+HTTP/1.1 101 Switching Protocols
+Connection: upgrade
+Upgrade: websocket
+Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk=
+Server: APISIX/2.15.0
+````
+
+4. Initiate the WebSocket request again in another terminal, the request will be rejected
+
+````shell
+HTTP/1.1 503 Service Temporarily Unavailable
+Date: Mon, 01 Aug 2022 03:49:17 GMT
+Content-Type: text/html; charset=utf-8
+Content-Length: 194
+Connection: keep-alive
+Server: APISIX/2.15.0
+
+<html>
+<head><title>503 Service Temporarily Unavailable</title></head>
+<body>
+<center><h1>503 Service Temporarily Unavailable</h1></center>
+<hr><center>openresty</center>
+</body>
+</html>
Review Comment:
ditto
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org