报错 Unhandled Exception: WebSocketException: Connection to ‘http://broker.emqx.io:8083#’ was not upgraded to websocket
而 mqtt_client 的官方示例是可以连接成功的
这个是日志报的错误
2023-11-07 17:19:27 Received terminate signal, shutting down now
2023-11-07 17:19:27 Stop listener http:dashboard on :18083 successfully.
2023-11-07 17:19:27 Listener ssl:default on 0.0.0.0:8883 stopped.
2023-11-07 17:19:27 Listener tcp:default on 0.0.0.0:1883 stopped.
2023-11-07 17:19:27 Listener ws:default on 0.0.0.0:8083 stopped.
2023-11-07 17:19:27 Listener wss:default on 0.0.0.0:8084 stopped.
2023-11-07 17:19:29 WARNING: Default (insecure) Erlang cookie is in use.
2023-11-07 17:19:29 WARNING: Configure node.cookie in /opt/emqx/etc/emqx.conf or override from environment variable EMQX_NODE__COOKIE
2023-11-07 17:19:29 WARNING: NOTE: Use the same cookie for all nodes in the cluster.
2023-11-07 17:19:31 EMQX_RPC__PORT_DISCOVERY [rpc.port_discovery]: manual
2023-11-07 17:19:31 EMQX_NODE__NAME [node.name]: emqx@172.17.0.2
2023-11-07 17:19:33 Listener ssl:default on 0.0.0.0:8883 started.
2023-11-07 17:19:33 Listener tcp:default on 0.0.0.0:1883 started.
2023-11-07 17:19:33 Listener ws:default on 0.0.0.0:8083 started.
2023-11-07 17:19:33 Listener wss:default on 0.0.0.0:8084 started.
2023-11-07 17:19:33 Listener http:dashboard on :18083 started.
2023-11-07 17:19:33 EMQX 5.3.0 is running now!
本机安装 emqx,然后用这个地址试试:ws://localhost:8083/mqtt
。
不行的话,打开 emqx 的 debug 日志级别,看看 emqx 的日志。