RED-1098: Implemented a receiver for dead messages from the pdftron-exchanges

This commit is contained in:
Viktor Seifert 2022-07-01 12:01:55 +02:00
parent 8435da351c
commit 1c3f2e8174
2 changed files with 73 additions and 2 deletions

View File

@ -49,6 +49,7 @@ public class MessagingConfiguration {
public static final String PDF_2_IMAGE_DLQ = "pdf2image_dead_letter_queue";
public static final String PDFTRON_QUEUE = "pdftron_queue";
public static final String PDFTRON_DLQ = "pdftron_dlq";
public static final String PDFTRON_RESULT_QUEUE = "pdftron_result_queue";
@ -246,13 +247,31 @@ public class MessagingConfiguration {
@Bean
public Queue pdfTronQueue() {
return QueueBuilder.durable(PDFTRON_QUEUE).build();
return QueueBuilder.durable(PDFTRON_QUEUE)
.withArgument("x-dead-letter-exchange", "")
.withArgument("x-dead-letter-routing-key", PDFTRON_DLQ)
.withArgument("x-max-priority", 2)
.maxPriority(2)
.build();
}
@Bean
public Queue pdfTronDlq() {
return QueueBuilder.durable(PDFTRON_DLQ).build();
}
@Bean
public Queue pdfTronResultQueue() {
return QueueBuilder.durable(PDFTRON_RESULT_QUEUE).build();
return QueueBuilder.durable(PDFTRON_RESULT_QUEUE)
.withArgument("x-dead-letter-exchange", "")
.withArgument("x-dead-letter-routing-key", PDFTRON_DLQ)
.withArgument("x-max-priority", 2)
.maxPriority(2)
.build();
}
}

View File

@ -0,0 +1,52 @@
package com.iqser.red.service.peristence.v1.server.service.download;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.iqser.red.service.peristence.v1.server.configuration.MessagingConfiguration;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.DownloadStatusPersistenceService;
import com.iqser.red.service.persistence.service.v1.api.model.download.DownloadStatusValue;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Service
@RequiredArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
@RabbitListener(queues = MessagingConfiguration.PDFTRON_DLQ)
public class RedactionDlqMessageReceiver {
private static final String LINE_SEPARATOR = System.lineSeparator();
ObjectMapper objectMapper;
DownloadStatusPersistenceService downloadStatusPersistenceService;
@RabbitHandler
public void receive(String in) throws JsonProcessingException {
// Since we receive different message types here, we do not convert to an object here;
// We just assume that the message contains a downloadId.
JsonNode jsonNode = objectMapper.readTree(in);
final String downloadId;
try {
downloadId = jsonNode.findValue("downloadId").asText();
} catch (Exception e) {
log.warn("Received a message in the " + MessagingConfiguration.PDFTRON_DLQ + " that contains no downloadId" + LINE_SEPARATOR + "{}", jsonNode.asText());
throw new RuntimeException(e);
}
log.info("Received a dead message with downloadId:{}, updating the download as failed", downloadId);
downloadStatusPersistenceService.updateStatus(downloadId, DownloadStatusValue.FAILED);
}
}