use of com.microsoft.azure.sdk.iot.device.exceptions.TransportException in project azure-iot-sdk-java by Azure.
the class MqttIotHubConnection method sendMessageResult.
/**
* Sends an ACK to the service for the provided message
* @param message the message to acknowledge to the service
* @param result Ignored. The only ack that can be sent in MQTT is COMPLETE
* @return true if the ACK was sent successfully and false otherwise
* @throws TransportException if the ACK could not be sent successfully
*/
@Override
public boolean sendMessageResult(IotHubTransportMessage message, IotHubMessageResult result) throws TransportException {
if (message == null || result == null) {
throw new TransportException(new IllegalArgumentException("message and result must be non-null"));
}
int messageId;
log.trace("Checking if MQTT layer can acknowledge the received message ({})", message);
if (receivedMessagesToAcknowledge.containsKey(message)) {
messageId = receivedMessagesToAcknowledge.get(message);
} else {
TransportException e = new TransportException(new IllegalArgumentException("Provided message cannot be acknowledged because it was already acknowledged or was never received from service"));
log.error("Mqtt layer could not acknowledge received message because it has no mapping to an outstanding mqtt message id ({})", message, e);
throw e;
}
log.trace("Sending MQTT ACK for a received message ({})", message);
if (message.getMessageType() == DEVICE_METHODS) {
this.deviceMethod.start();
this.deviceMethod.sendMessageAcknowledgement(messageId);
} else if (message.getMessageType() == DEVICE_TWIN) {
this.deviceTwin.start();
this.deviceTwin.sendMessageAcknowledgement(messageId);
} else {
this.deviceMessaging.sendMessageAcknowledgement(messageId);
}
log.trace("MQTT ACK was sent for a received message so it has been removed from the messages to acknowledge list ({})", message);
this.receivedMessagesToAcknowledge.remove(message);
return true;
}
Aggregations