use of com.hivemq.client.mqtt.mqtt3.message.connect.connack.Mqtt3ConnAck in project open-smart-grid-platform by OSGP.
the class MqttClientIT method mqttClientRestoresBrokerConnection.
@Test
void mqttClientRestoresBrokerConnection() throws Exception {
final Mqtt3ConnAck mqtt3ConnAck = this.mqttClient.connect().get(10, TimeUnit.SECONDS);
assertThat(this.mqttClient.isConnected()).as("MqttClient connect resulted in: %s", mqtt3ConnAck).isTrue();
final PublishedMessage message1 = this.publishedMessage("TST-01", "test-1");
final PublishedMessage message2 = this.publishedMessage("TST-02", "test-2");
this.publishMessages(message1, message2);
eclipseMosquittoContainer.stop();
this.theClientWillBeWaitingForReconnect();
// Preserve the port bindings that the client used to connect with.
// Without this the container will bind other ports on the host.
eclipseMosquittoContainer.setPortBindings(Arrays.asList(String.format("%d:1883", containerMqttPort), String.format("%d:8883", containerMqttSslPort)));
eclipseMosquittoContainer.start();
this.theClientWillBeConnected();
final PublishedMessage message3 = this.publishedMessage("TST-03", "test-3");
final PublishedMessage message4 = this.publishedMessage("TST-04", "test-4");
this.publishMessages(message3, message4);
this.theClientWillHaveReceivedThePublishedMessages(message1, message2, message3, message4);
}
use of com.hivemq.client.mqtt.mqtt3.message.connect.connack.Mqtt3ConnAck in project open-smart-grid-platform by OSGP.
the class Client method run.
@Override
public void run() {
this.running = true;
try {
this.mqtt3BlockingClient = Mqtt3Client.builder().identifier(this.uuid.toString()).serverHost(this.host).serverPort(this.port).sslConfig(this.mqttClientSslConfig).automaticReconnectWithDefaultConfig().buildBlocking();
final Mqtt3ConnAck ack = this.mqtt3BlockingClient.connect();
LOG.info("Client {} received Ack {}", this.getClass().getSimpleName(), ack.getType());
this.addShutdownHook();
LOG.info("Client {} started", this.getClass().getSimpleName());
this.onConnect(this.mqtt3BlockingClient);
} catch (final Exception ex) {
LOG.error("Exception while starting client.", ex);
this.stopClient();
}
}
use of com.hivemq.client.mqtt.mqtt3.message.connect.connack.Mqtt3ConnAck in project open-smart-grid-platform by OSGP.
the class MqttClientIT method messageHandlerHandlesPublishedMessages.
@Test
void messageHandlerHandlesPublishedMessages() throws Exception {
final Mqtt3ConnAck mqtt3ConnAck = this.mqttClient.connect().get(10, TimeUnit.SECONDS);
assertThat(this.mqttClient.isConnected()).as("MqttClient connect resulted in: %s", mqtt3ConnAck).isTrue();
try {
final PublishedMessage message1 = this.publishedMessage("TST-01", "test-1");
final PublishedMessage message2 = this.publishedMessage("TST-02", "test-2");
this.publishMessages(message1, message2);
assertThat(this.messageHandler.publishedMessages()).containsExactlyInAnyOrder(message1, message2);
} finally {
this.mqttClient.disconnect();
}
}
Aggregations