同样的账号密码,能访问publish api, 但是连MQTTX连不上

curl -i --basic -u 'admin:cheersu1234!'  -X 'POST' \
  'http://192.168.51.XX:18083/api/v5/publish' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "payload_encoding": "plain",
  "topic": "api/example/topic",
  "qos": "0",
  "clientid": "api_example_client",
  "payload": "hello emqx api",
  "retain": false
}'
HTTP/1.1 202 Accepted
content-length: 54
content-type: application/json
date: Thu, 22 Dec 2022 08:26:27 GMT
server: Cowboy
{"message":"no_matching_subscribers","reason_code":16}

错误报告

环境

  • EMQX 版本:5.0.9
  • 操作系统版本:ubuntu16.04

重现此问题的步骤

  1. xxx
  2. xxx
  3. xxx

预期行为

实际行为


功能请求

描述你需要的功能

为什么你需要这个功能


其他

HTTP API 访问的是 HTTP 的监听端口,MQTT 客户端连接的是 MQTT 的监听端口,这俩的认证也不是一个体系的,用户名密码当然不能通用。

MQTT客户端连接应该用哪套用户名密码?

你可以看下官网的 认证 文档。



用的redis认证,密码方式时plain, 用设置的账号名密码登录不上

你可以 trace 一下这个客户端看下连接时的详细日志。

2022-12-22T12:18:58+00:00 [MQTT] test_client@192.168.51.35:58907 msg: mqtt_packet_received, packet: CONNECT(Q0, R0, D0),ClientId=test_client, ProtoName=MQTT, ProtoVsn=5, CleanStart=true, KeepAlive=60, Username=admin, Password=******
2022-12-22T12:18:58+00:00 [QUERY] test_client@192.168.51.35:58907 msg: redis_connector_received, connector: emqx_authn_redis:1, sql: HMGETmqtt_user:adminpassword, state: [auto_reconnect: true, poolname: emqx_authn_redis:1:2, type: single]
2022-12-22T12:18:58+00:00 [AUTHN] test_client@192.168.51.35:58907 msg: authenticator_result, authenticator: password_based:redis, result: {error,bad_username_or_password}
2022-12-22T12:18:58+00:00 [AUTHN] test_client@192.168.51.35:58907 msg: authentication_result, reason: chain_result, result: {stop,{error,bad_username_or_password}}
2022-12-22T12:18:58+00:00 [MQTT] test_client@192.168.51.35:58907 msg: mqtt_packet_sent, packet: CONNACK(Q0, R0, D0),AckFlags=0, ReasonCode=134
2022-12-22T12:18:58+00:00 [SOCKET] test_client@192.168.51.35:58907 msg: emqx_connection_terminated, reason: {shutdown,bad_username_or_password}
这就是trace的日志

日志报了用户名或密码错误,看下你 Redis 认证具体是怎么配置的?