`
can_do
  • 浏览: 249804 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

EMQX中如何访问RestAPI

阅读更多
1、查看restapi端口

# netstat -tnulp|grep 19656
tcp        0      0 0.0.0.0:6369                0.0.0.0:*                   LISTEN      19656/beam.smp     
tcp        0      0 0.0.0.0:18083               0.0.0.0:*                   LISTEN      19656/beam.smp     
tcp        0      0 127.0.0.1:11883             0.0.0.0:*                   LISTEN      19656/beam.smp     
tcp        0      0 0.0.0.0:8883                0.0.0.0:*                   LISTEN      19656/beam.smp     
tcp        0      0 0.0.0.0:9080                0.0.0.0:*                   LISTEN      19656/beam.smp     
tcp        0      0 0.0.0.0:5369                0.0.0.0:*                   LISTEN      19656/beam.smp     
tcp        0      0 0.0.0.0:1883                0.0.0.0:*                   LISTEN      19656/beam.smp 

2、创建访问RestAPI的认证应用ID

[1/3] # ./emqx_ctl mgmt  insert <AppId> <Name>
# ./emqx_ctl mgmt insert b28477fa9f9798 Client@Yours
AppSecret: Mjg3ODQxNjgyNTc2Mjg1NDUzNzA3ODczNDM3MDc1Mzc0MDI
[2/3] # ./emqx_ctl mgmt list
app_id: b28477fa9f9798, secret: Mjg3ODQxNjgyNTc2Mjg1NDUzNzA3ODczNDM3MDc1Mzc0MDI, name: Client@Yours, desc: Application user, status: true, expired: undefined
[3/3] curl -v --basic -u <appid>:<appsecret> -k http://<eqmx_node_host>:8080/api/v3/brokers
=> <appid>:<appsecret>,可以通过CLI或者Dashboard进行创建

3、通过认证应用ID和秘钥进行访问

# curl -v --basic -u b28477fa9f9798:Mjg3ODQxNjgyNTc2Mjg1NDUzNzA3ODczNDM3MDc1Mzc0MDI -k http://192.168.1.148:9080/api/v3/brokers/
* About to connect() to 192.168.1.148 port 9080 (#0)
*   Trying 192.168.1.148... connected
* Connected to 192.168.1.148 (192.168.1.148) port 9080 (#0)
* Server auth using Basic with user 'b28477fa9f9798'
> GET /api/v3/brokers/ HTTP/1.1
> Authorization: Basic YjI4NDc3ZmE5Zjk3OTg6TWpnM09EUXhOamd5TlRjMk1qZzFORFV6TnpBM09EY3pORE0zTURjMU16YzBNREk=
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: 192.168.1.148:9080
> Accept: */*
>
< HTTP/1.1 200 OK
< content-length: 423
< content-type: application/json
< date: Thu, 13 Jun 2019 02:34:09 GMT
< server: Cowboy
<
* Connection #0 to host 192.168.1.148 left intact
* Closing connection #
=>result as the following:
{
  "code": 0,
  "data": [
    {
      "datetime": "2019-06-13 10:33:13",
      "node": "emqx@192.168.1.150",
      "node_status": "Running",
      "otp_release": "R21/10.3.2",
      "sysdescr": "EMQ X Broker",
      "uptime": "17 hours, 20 minutes, 54 seconds",
      "version": "v3.1.0"
    },
    {
      "datetime": "2019-06-13 10:33:13",
      "node": "emqx@192.168.1.148",
      "node_status": "Running",
      "otp_release": "R21/10.3.2",
      "sysdescr": "EMQ X Broker",
      "uptime": "17 hours, 21 minutes, 28 seconds",
      "version": "v3.1.0"
    }
  ]
}

【温馨提示】
如果您觉得满意,可以选择支持下,您的支持是我最大的动力:

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics