Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change(mqtt-proxy): remove deprecated upstream #7694

Merged
merged 2 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 1 addition & 58 deletions apisix/stream/plugins/mqtt-proxy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
-- limitations under the License.
--
local core = require("apisix.core")
local upstream = require("apisix.upstream")
local ipmatcher = require("resty.ipmatcher")
local bit = require("bit")
local ngx = ngx
local str_byte = string.byte
Expand All @@ -32,20 +30,7 @@ local schema = {
type = "object",
properties = {
protocol_name = {type = "string"},
protocol_level = {type = "integer"},
upstream = {
description = "Deprecated. We should configure upstream outside of the plugin",
type = "object",
properties = {
ip = {type = "string"}, -- deprecated, use "host" instead
host = {type = "string"},
port = {type = "number"},
},
oneOf = {
{required = {"host", "port"}},
{required = {"ip", "port"}},
},
}
protocol_level = {type = "integer"}
},
required = {"protocol_name", "protocol_level"},
}
Expand Down Expand Up @@ -189,48 +174,6 @@ function _M.preread(conf, ctx)
if res.client_id ~= "" then
ctx.mqtt_client_id = res.client_id
end

if not conf.upstream then
return
end

local host = conf.upstream.host
if not host then
host = conf.upstream.ip
end

if conf.host_is_domain == nil then
conf.host_is_domain = not ipmatcher.parse_ipv4(host)
and not ipmatcher.parse_ipv6(host)
end

if conf.host_is_domain then
local ip, err = core.resolver.parse_domain(host)
if not ip then
core.log.error("failed to parse host ", host, ", err: ", err)
return 503
end

host = ip
end

local up_conf = {
type = "roundrobin",
nodes = {
{host = host, port = conf.upstream.port, weight = 1},
}
}

local ok, err = upstream.check_schema(up_conf)
if not ok then
core.log.error("failed to check schema ", core.json.delay_encode(up_conf),
", err: ", err)
return 503
end

local matched_route = ctx.matched_route
upstream.set(ctx, up_conf.type .. "#route_" .. matched_route.value.id,
ctx.conf_version, up_conf)
return
end

Expand Down
4 changes: 0 additions & 4 deletions docs/en/latest/plugins/mqtt-proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ This Plugin supports both the protocols [3.1.*](http://docs.oasis-open.org/mqtt/
|----------------|---------|------------|-----------------------------------------------------------------------------------|
| protocol_name | string | True | Name of the protocol. Generally `MQTT`. |
| protocol_level | integer | True | Level of the protocol. It should be `4` for MQTT `3.1.*` and `5` for MQTT `5.0`. |
| upstream | object | Deprecated | Use separate Upstream in the Route instead. |
| upstream.host | string | True | IP or host of the upstream to forward the current request to. |
| upstream.ip | string | Deprecated | Use `host` instead. IP address of the upstream to forward the current request to. |
| upstream.port | number | True | Port of the upstream to forward the current request to. |

## Enabling the Plugin

Expand Down
3 changes: 0 additions & 3 deletions docs/en/latest/stand-alone.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,6 @@ stream_routes:
mqtt-proxy:
protocol_name: "MQTT"
protocol_level: 4
upstream:
ip: "127.0.0.1"
port: 1995
upstreams:
- nodes:
"127.0.0.1:1995": 1
Expand Down
4 changes: 0 additions & 4 deletions docs/zh/latest/plugins/mqtt-proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ description: 本文档介绍了 Apache APISIX mqtt-proxy 插件的信息,通
| -------------- | ------- | ----- | ------------------------------------------------------ |
| protocol_name | string | 是 | 协议名称,正常情况下应为 `MQTT`。 |
| protocol_level | integer | 是 | 协议级别,MQTT `3.1.*` 为 `4`,MQTT `5.0` 应是`5`。 |
| upstream | object | 废弃 | 推荐使用 Route 上配置的上游信息。 |
| upstream.host | string | 是 | 将当前请求转发到的上游的 IP 地址或域名。 |
| upstream.ip | string | 废弃 | 推荐使用 `host` 代替。将当前请求转发到的上游的 IP 地址。 |
| upstream.port | number | 是 | 将当前请求转发到的上游的端口。 |

## 启用插件

Expand Down
3 changes: 0 additions & 3 deletions docs/zh/latest/stand-alone.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,6 @@ stream_routes:
mqtt-proxy:
protocol_name: "MQTT"
protocol_level: 4
upstream:
ip: "127.0.0.1"
port: 1995
upstreams:
- nodes:
"127.0.0.1:1995": 1
Expand Down
34 changes: 24 additions & 10 deletions t/admin/stream-routes.t
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,19 @@ GET /t
"plugins": {
"mqtt-proxy": {
"protocol_name": "MQTT",
"protocol_level": 4,
"upstream": {
"ip": "127.0.0.1",
"port": 1980
}
"protocol_level": 4
}
},
"upstream": {
"type": "chash",
"key": "mqtt_client_id",
"nodes": [
{
"host": "127.0.0.1",
"port": 1980,
"weight": 1
}
]
}
}]]
)
Expand Down Expand Up @@ -260,12 +267,19 @@ passed
"plugins": {
"mqtt-proxy": {
"protocol_name": "MQTT",
"protocol_level": 4,
"upstream": {
"ip": "127.0.0.1",
"port": 1980
}
"protocol_level": 4
}
},
"upstream": {
"type": "chash",
"key": "mqtt_client_id",
"nodes": [
{
"host": "127.0.0.1",
"port": 1980,
"weight": 1
}
]
}
}]]
)
Expand Down
3 changes: 0 additions & 3 deletions t/config-center-yaml/stream-route.t
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ stream_routes:
mqtt-proxy:
protocol_name: "MQTT"
protocol_level: 4
upstream:
ip: "127.0.0.1"
port: 1995
upstreams:
- nodes:
"127.0.0.1:1995": 1
Expand Down
17 changes: 12 additions & 5 deletions t/debug/debug-mode.t
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,19 @@ passed
"plugins": {
"mqtt-proxy": {
"protocol_name": "MQTT",
"protocol_level": 4,
"upstream": {
"ip": "127.0.0.1",
"port": 1995
}
"protocol_level": 4
}
},
"upstream": {
"type": "chash",
"key": "mqtt_client_id",
"nodes": [
{
"host": "127.0.0.1",
"port": 1995,
"weight": 1
}
]
}
}]]
)
Expand Down
Loading