2021-02-26 21:40:08 +08:00
---
title: mqtt-proxy
---
2019-10-31 09:27:28 +08:00
<!--
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
-->
2021-02-26 21:40:08 +08:00
## Summary
2021-01-03 11:26:40 +08:00
2019-09-16 13:03:26 +08:00
- [**Name** ](#name )
- [**Attributes** ](#attributes )
- [**How To Enable** ](#how-to-enable )
2021-01-26 09:32:11 +08:00
- [**Delete Plugin** ](#delete-plugin )
2019-09-16 13:03:26 +08:00
## Name
The plugin `mqtt-proxy` only works in stream model, it help you to dynamic load
balance by `client_id` of MQTT.
2019-11-29 08:54:59 +08:00
And this plugin both support MQTT protocol [3.1.* ](http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html ) and [5.0 ](https://docs.oasis-open.org/mqtt/mqtt/v5.0/mqtt-v5.0.html ).
2019-09-16 13:03:26 +08:00
## Attributes
2020-09-23 08:11:27 +08:00
| Name | Type | Requirement | Default | Valid | Description |
| -------------- | ------- | ----------- | ------- | ----- | -------------------------------------------------------------------------------------- |
2020-12-13 00:04:48 +08:00
| protocol_name | string | required | | | Name of protocol, should be `MQTT` in normal. |
2020-09-23 08:11:27 +08:00
| protocol_level | integer | required | | | Level of protocol, it should be `4` for MQTT `3.1.*` . it should be `5` for MQTT `5.0` . |
2021-06-09 19:23:40 +08:00
| upstream.host | string | required | | | the IP or host of upstream, will forward current request to. |
| upstream.ip | string | deprecated | | | Use "host" instead. IP address of upstream, will forward current request to.|
2020-09-23 08:11:27 +08:00
| upstream.port | number | required | | | Port of upstream, will forward current request to. |
2019-09-16 13:03:26 +08:00
## How To Enable
2019-11-29 08:54:59 +08:00
To enable this plugin, we need to enable the stream_proxy configuration in `conf/config.yaml` first.
For example, the following configuration represents listening on the 9100 TCP port.
```yaml
...
router:
http: 'radixtree_uri'
ssl: 'radixtree_sni'
stream_proxy: # TCP/UDP proxy
tcp: # TCP proxy port list
- 9100
dns_resolver:
...
```
Then send the MQTT request to port 9100.
2019-09-16 13:03:26 +08:00
Creates a stream route, and enable plugin `mqtt-proxy` .
```shell
2020-11-28 19:05:14 +08:00
curl http://127.0.0.1:9080/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
2019-09-16 13:03:26 +08:00
{
"remote_addr": "127.0.0.1",
"plugins": {
"mqtt-proxy": {
"protocol_name": "MQTT",
"protocol_level": 4,
"upstream": {
2021-06-09 19:23:40 +08:00
"host": "127.0.0.1",
2019-09-16 13:03:26 +08:00
"port": 1980
}
}
}
}'
```
## Delete Plugin
```shell
$ curl http://127.0.0.1:2379/v2/keys/apisix/stream_routes/1 -X DELETE
```
The `mqtt-proxy` plugin has been deleted now.