Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rely on rabbitmq dlq for computation errors handling #166

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public enum Type {
UNSUPPORTED_FORMAT(HttpStatus.INTERNAL_SERVER_ERROR),
UNKNOWN_EQUIPMENT_TYPE(HttpStatus.INTERNAL_SERVER_ERROR),
UNKNOWN_VARIANT_ID(HttpStatus.NOT_FOUND),
FAILED_NETWORK_SAVING(HttpStatus.INTERNAL_SERVER_ERROR);
FAILED_NETWORK_SAVING(HttpStatus.INTERNAL_SERVER_ERROR),
FAILED_CASE_IMPORT(HttpStatus.INTERNAL_SERVER_ERROR);

public final HttpStatus status;

Expand Down Expand Up @@ -68,4 +69,8 @@ public static NetworkConversionException createVariantIdUnknown(String variantId
public static NetworkConversionException createFailedNetworkSaving(UUID networkUuid, Exception cause) {
return new NetworkConversionException(Type.FAILED_NETWORK_SAVING, String.format("The save of network '%s' has failed", networkUuid), cause);
}

public static NetworkConversionException createFailedCaseImport(Exception cause) {
return new NetworkConversionException(Type.FAILED_CASE_IMPORT, "Case import failed", cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@ Consumer<Message<UUID>> consumeCaseImportStart() {
NetworkInfos networkInfos = importCase(caseUuid, variantId, reportUuid, caseInfos.getFormat(), changedImportParameters);
notificationService.emitCaseImportSucceeded(networkInfos, caseInfos.getName(), caseInfos.getFormat(), receiver, allImportParameters);
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
notificationService.emitCaseImportFailed(receiver, e.getMessage());
throw NetworkConversionException.createFailedCaseImport(e);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class NotificationService {
public static final String HEADER_NETWORK_ID = "networkId";
public static final String HEADER_NETWORK_UUID = "networkUuid";
public static final String HEADER_RECEIVER = "receiver";
public static final String HEADER_ERROR_MESSAGE = "errorMessage";
public static final String HEADER_IMPORT_PARAMETERS = "importParameters";
public static final String HEADER_CASE_FORMAT = "caseFormat";
public static final String HEADER_CASE_NAME = "caseName";
Expand All @@ -50,11 +49,6 @@ private void sendCaseImportSucceededMessage(Message<String> message) {
networkConversionPublisher.send("publishCaseImportSucceeded-out-0", message);
}

private void sendCaseImportFailedMessage(Message<String> message) {
MESSAGE_OUTPUT_LOGGER.debug("Sending import failed message : {}", message);
networkConversionPublisher.send("publishCaseImportFailed-out-0", message);
}

public void emitCaseImportStart(UUID caseUuid, String variantId, UUID reportUuid, String caseFormat, Map<String, Object> importParameters, String receiver) {
sendCaseImportStartMessage(MessageBuilder.withPayload(caseUuid)
.setHeader(HEADER_VARIANT_ID, variantId)
Expand All @@ -75,11 +69,4 @@ public void emitCaseImportSucceeded(NetworkInfos networkInfos, String caseNameSt
.setHeader(HEADER_IMPORT_PARAMETERS, importParameters)
.build());
}

public void emitCaseImportFailed(String receiver, String errorMessage) {
sendCaseImportFailedMessage(MessageBuilder.withPayload("")
.setHeader(HEADER_RECEIVER, receiver)
.setHeader(HEADER_ERROR_MESSAGE, errorMessage)
.build());
}
}
16 changes: 13 additions & 3 deletions src/main/resources/config/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,24 @@ spring:
destination: ${powsybl-ws.rabbitmq.destination.prefix:}case.import.start
publishCaseImportSucceeded-out-0:
destination: ${powsybl-ws.rabbitmq.destination.prefix:}case.import.succeeded
publishCaseImportFailed-out-0:
destination: ${powsybl-ws.rabbitmq.destination.prefix:}case.import.failed
consumeCaseImportStart-in-0:
destination: ${powsybl-ws.rabbitmq.destination.prefix:}case.import.start
group: importGroup
consumer:
concurrency: 2
output-bindings: publishCaseImportStart-out-0;publishCaseImportSucceeded-out-0;publishCaseImportFailed-out-0
max-attempts: 1
output-bindings: publishCaseImportStart-out-0;publishCaseImportSucceeded-out-0
rabbit:
bindings:
consumeRun-in-0:
consumer:
auto-bind-dlq: true
dead-letter-exchange: ${powsybl-ws.rabbitmq.destination.prefix:}case.import.start.dlx
dead-letter-queue-name: ${powsybl-ws.rabbitmq.destination.prefix:}case.import.start.dlq
dead-letter-exchange-type: topic
quorum:
enabled: true
delivery-limit: 2

powsybl:
services:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,8 @@ void testFailedAsyncImport() throws Exception {
.param("caseFormat", "XIIDM"))
.andExpect(status().isOk());

Message<byte[]> message = output.receive(1000, "case.import.failed");
Message<byte[]> message = output.receive(1000, "case.import.start");
assertEquals(receiver, message.getHeaders().get(NotificationService.HEADER_RECEIVER));
assertEquals(IMPORT_CASE_ERROR_MESSAGE, message.getHeaders().get(NotificationService.HEADER_ERROR_MESSAGE));
}

@Test
Expand Down
Loading