I’m having wierd problems connecting to a MQTT broker using HiveMQ Async client. I’m having an unit test that simpley checks publishing and veriying the published message via a Subscriber. Here is the snippet:
“MqttClientFactory#publish” should “connect to a local MQTT broker and publish” in {
val mqttConfig = MqttConfig(“cpo-platform-test”, “localhost”, 1883, “joesan”, “joesan”)
val published = MqttClientFactory.publish(
mqttConfig,
“cpo-test-topic”,
MqttQos.EXACTLY_ONCE
)
whenReady(published, timeout(Span(100, Seconds))) { Unit => {
val client = MqttClientFactory.asyncMqttClient(mqttConfig)
println("In here ****************** ")
client
.connect()
.thenCompose(_ => client.subscribeWith().topicFilter(“cpo-test-topic”).qos(MqttQos.EXACTLY_ONCE).callback(println).send())
}
}
}
When I ran this, I get the following error:
The future returned an exception of type: java.util.concurrent.CompletionException, with message: com.hivemq.client.mqtt.exceptions.MqttClientStateException: MQTT client is not connected…
ScalaTestFailureLocation: com.openelectrons.cpo.mqtt.MqttClientFactoryTest at (MqttClientFactoryTest.scala:28)
org.scalatest.exceptions.TestFailedException: The future returned an exception of type: java.util.concurrent.CompletionException, with message: com.hivemq.client.mqtt.exceptions.MqttClientStateException: MQTT client is not connected…
at org.scalatest.concurrent.Futures$FutureConcept.tryTryAgain$1(Futures.scala:531)
at org.scalatest.concurrent.Futures$FutureConcept.futureValueImpl(Futures.scala:550)
at org.scalatest.concurrent.Futures$FutureConcept.futureValueImpl$(Futures.scala:479)
What could be the issue? The mqtt broker is indeed running on port 1883, here is s screenshot of the same: