use of software.amazon.awssdk.services.sqs.model.DeleteMessageRequest in project aws-doc-sdk-examples by awsdocs.
the class VideoDetect method getLabelJob.
public static void getLabelJob(RekognitionClient rekClient, SqsClient sqs, String queueUrl) {
List<Message> messages = null;
ReceiveMessageRequest messageRequest = ReceiveMessageRequest.builder().queueUrl(queueUrl).build();
try {
messages = sqs.receiveMessage(messageRequest).messages();
if (!messages.isEmpty()) {
for (Message message : messages) {
String notification = message.body();
// Get the status and job id from the notification
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonMessageTree = mapper.readTree(notification);
JsonNode messageBodyText = jsonMessageTree.get("Message");
ObjectMapper operationResultMapper = new ObjectMapper();
JsonNode jsonResultTree = operationResultMapper.readTree(messageBodyText.textValue());
JsonNode operationJobId = jsonResultTree.get("JobId");
JsonNode operationStatus = jsonResultTree.get("Status");
System.out.println("Job found in JSON is " + operationJobId);
DeleteMessageRequest deleteMessageRequest = DeleteMessageRequest.builder().queueUrl(queueUrl).build();
String jobId = operationJobId.textValue();
if (startJobId.compareTo(jobId) == 0) {
System.out.println("Job id: " + operationJobId);
System.out.println("Status : " + operationStatus.toString());
if (operationStatus.asText().equals("SUCCEEDED"))
GetResultsLabels(rekClient);
else
System.out.println("Video analysis failed");
sqs.deleteMessage(deleteMessageRequest);
} else {
System.out.println("Job received was not job " + startJobId);
sqs.deleteMessage(deleteMessageRequest);
}
}
}
} catch (RekognitionException e) {
e.getMessage();
System.exit(1);
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (JsonProcessingException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations