use of com.microsoft.azure.sdk.iot.device.DeviceClient in project azure-iot-sdk-java by Azure.
the class SendMessagesIT method SendMessagesOverMqtt.
@Test
public void SendMessagesOverMqtt() throws URISyntaxException, IOException {
String messageString = "Java client e2e test message over Mqtt protocol";
Message msg = new Message(messageString);
DeviceClient client = new DeviceClient(DeviceConnectionString.get(iotHubConnectionString, deviceMqtt), IotHubClientProtocol.MQTT);
client.open();
for (int i = 0; i < NUM_MESSAGES_PER_CONNECTION; ++i) {
try {
Success messageSent = new Success();
EventCallback callback = new EventCallback();
client.sendEventAsync(msg, callback, messageSent);
Integer waitDuration = 0;
while (!messageSent.getResult()) {
Thread.sleep(RETRY_MILLISECONDS);
if ((waitDuration += RETRY_MILLISECONDS) > SEND_TIMEOUT_MILLISECONDS) {
break;
}
}
if (!messageSent.getResult()) {
Assert.fail("Sending message over MQTT protocol failed");
}
} catch (Exception e) {
Assert.fail("Sending message over MQTT protocol failed");
}
}
client.closeNow();
}
Aggregations