hivemq / hivemq-mqtt-client

HiveMQ MQTT Client is an MQTT 5.0 and MQTT 3.1.1 compatible and feature-rich high-performance Java client library with different API flavours and backpressure support
https://hivemq.github.io/hivemq-mqtt-client/
Apache License 2.0
832 stars 153 forks source link

"mqtts://'' appended at my host #543

Closed lucanicoletti closed 1 year ago

lucanicoletti commented 1 year ago

Expected behavior

When I use Mqtt3Client.builder() and set host & port with .serverHost(config.host).serverPort(config.port), a mqtts:// is appended, giving me a UnknownHostException when trying to connect.

Actual behavior

Do not modify the provided host+port

To Reproduce

Simply build a Mqtt3Client (async) with port and host, and try to connect, a "mqtts://" is appended at the host

Steps

Reproducer code

val client = Mqtt3Client.builder().serverHost(/** your host */).serverPort(/** your port */).buildAsync()
client.connect().whenComplete { mqtt3ConnAck, ex ->
    continuation.resume(!mqtt3ConnAck.returnCode.isError)
}

Details

SgtSilvio commented 1 year ago

Hi @lucanicoletti the hivemq-mqtt-client does not add anything to the provided host. Where do you see the "mqtts://" prefix?

lucanicoletti commented 1 year ago

when I connect, I get the exception, with UnknownHostException: mqtts://{my host}. I figured out it's the protocol, and that I can set the protocols with .protocols(listOf()) providing a list of protocols, but the one I need fires a com.hivemq.client.mqtt.exceptions.ConnectionFailedException: java.lang.IllegalArgumentException: protocol ws is not supported

SgtSilvio commented 1 year ago

What do you pass to .serverHost(config.host)? I suspect config.host already contains mqtts://. The client library does not alter the provided hostname. There is not even an occurrence of "mqtts" in the code as you can see here: https://github.com/hivemq/hivemq-mqtt-client/search?q=mqtts

I figured out it's the protocol, and that I can set the protocols with .protocols(listOf()) providing a list of protocols

I guess you are referring to https://github.com/hivemq/hivemq-mqtt-client/blob/master/src/main/java/com/hivemq/client/mqtt/MqttClientSslConfigBuilderBase.java#L78. This is only to set the TLS protocol(s), for example "TLSv1.2" or "TLSv1.3".

Can you provide more details

lucanicoletti commented 1 year ago

Closing as it was completely my mistake! We received 2 values (one with mqtt pre-appended) and one without, a mapper deepdown our architecture was mapping the wrong one into the value (config.host) we were using. Thanks for the support.