use of software.amazon.awssdk.crt.mqtt.MqttMessage in project aws-greengrass-nucleus by aws-greengrass.
the class IotJobsClientWrapper method PublishDescribeJobExecution.
@Override
public CompletableFuture<Integer> PublishDescribeJobExecution(DescribeJobExecutionRequest request, QualityOfService qos) {
if (request.thingName == null || request.jobId == null) {
CompletableFuture result = new CompletableFuture();
result.completeExceptionally(new MqttException("DescribeJobExecutionRequest must have a non-null thingName and a non-null jobId"));
return result;
}
String topic = String.format(DESCRIBE_JOB_TOPIC, request.thingName, request.jobId);
String payloadJson = this.gson.toJson(request);
MqttMessage message = new MqttMessage(topic, payloadJson.getBytes(StandardCharsets.UTF_8));
return this.connection.publish(message, qos, false);
}
use of software.amazon.awssdk.crt.mqtt.MqttMessage in project aws-greengrass-nucleus by aws-greengrass.
the class IotJobsClientWrapper method SubscribeToDescribeJobExecutionRejected.
@Override
public CompletableFuture<Integer> SubscribeToDescribeJobExecutionRejected(DescribeJobExecutionSubscriptionRequest request, QualityOfService qos, Consumer<RejectedError> handler, Consumer<Exception> exceptionHandler) {
if (request.jobId == null || request.thingName == null) {
CompletableFuture result = new CompletableFuture();
result.completeExceptionally(new MqttException("DescribeJobExecutionSubscriptionRequest must have a non-null jobId and a non-null thingName"));
return result;
}
String topic = String.format(JOB_DESCRIBE_REJECTED_TOPIC, request.thingName, request.jobId);
Consumer<MqttMessage> messageHandler = describeJobSubscriptionCbs.computeIfAbsent(new Pair<>(handler, exceptionHandler), (k) -> (message) -> {
try {
String payload = new String(message.getPayload(), StandardCharsets.UTF_8);
RejectedError response = this.gson.fromJson(payload, RejectedError.class);
handler.accept(response);
} catch (Exception e) {
if (exceptionHandler != null) {
exceptionHandler.accept(e);
}
}
});
return this.connection.subscribe(topic, qos, messageHandler);
}
Aggregations