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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
