I am trying to write an integration test using hivemq test containers.But at start itself the hivemq server is getting disconnected .
and getting the below error:
Failed connecting MQTT client: test-mqtt-client12 to broker. Exception is: {} Retrying connecting…
com.hivemq.client.mqtt.exceptions.ConnectionClosedException: Server closed connection without DISCONNECT.
My code is as follows:
public class TestDMAPLauncher {
private HiveMQContainer hivemq = new HiveMQContainer(DockerImageName.parse("hivemq/hivemq-ce:latest"));
@Autowired
private DefaultMqttClientConfigImpl mqttClientConfig;
@PostConstruct
public void init() {
hivemq.withExposedPorts(8080, 8081);
hivemq.start();
String address = hivemq.getHost() + ":" + hivemq.getMappedPort(8080);
log.debug("HiveMQ container address: {}", address);
mqttClientConfig.getMqtt().setServerPort(hivemq.getMappedPort(8080));
mqttClientConfig.getMqtt().setBrokerURL(hivemq.getHost());
}
public static void main(String[] args) {
ApplicationContext ctx = new AnnotationConfigApplicationContext(TestLauncher.class);
}
}