hivemq-mqtt-client
hivemq-mqtt-client copied to clipboard
Subscriber message,CONNECT failed as CONNACK contained an Error Code: BAD_USER_NAME_OR_PASSWORD
Hi @zqb666 - It depends on how the broker authorization is setup but for simple auth:
final Mqtt5BlockingClient client = Mqtt5Client.builder()
.identifier(getClientId())
.serverHost(HOST)
.serverPort(PORT)
.simpleAuth()
.username(USERNAME)
.password(ByteBuffer.wrap(PASSWORD.getBytes(StandardCharsets.UTF_8)))
.applySimpleAuth()
See also this blog post: Authentication with Username and Password
Hi @zqb666 - did this help out at all? Did you find a solution that works for you?
Hi @zqb666 - It depends on how the broker authorization is setup but for simple auth:
final Mqtt5BlockingClient client = Mqtt5Client.builder() .identifier(getClientId()) .serverHost(HOST) .serverPort(PORT) .simpleAuth() .username(USERNAME) .password(ByteBuffer.wrap(PASSWORD.getBytes(StandardCharsets.UTF_8))) .applySimpleAuth() See also this blog post: Authentication with Username and Password
i tyy your code ,fix a little problem, result like this:
final Mqtt5BlockingClient client = (Mqtt5BlockingClient) Mqtt5Client.builder() .identifier(UUID.randomUUID().toString()) .serverHost(BROKER_HOST) .serverPort(1883) .simpleAuth() .username(USERNAME) .password(ByteBuffer.wrap(PASSWORD.getBytes(StandardCharsets.UTF_8))) .applySimpleAuth();