QueueConsumer улучшил логирование ошибок. IMDGMessageResolver добавил надёжности при ошибках форматирования ошибок.

This commit is contained in:
AKurakin 2023-05-05 11:57:49 +03:00
parent a83f4f348f
commit cdd6a0996f
2 changed files with 15 additions and 7 deletions

View file

@ -1,5 +1,6 @@
package ru.spcex.clearing.util.services;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.clearing.platform.dictionary.ErrorCodeDictionary;
@ -25,13 +26,17 @@ public class IMDGMessageResolver implements IMessageResolver {
@Override
public String resolve(EnumMessage errorMessage) {
if (errorMessage == null) return "null";
ErrorCodeDictionary errorDictionary = errorCodeDictionaryIMDG.getSingleObjectByID(errorMessage.getSubject().getId());
if (errorDictionary == null) {
log.warn("ERROR_CODE_DICTIONARY not found fo id={}", errorMessage.getSubject().getId());
try {
ErrorCodeDictionary errorDictionary = errorCodeDictionaryIMDG.getSingleObjectByID(errorMessage.getSubject().getId());
if (errorDictionary == null) {
log.warn("ERROR_CODE_DICTIONARY not found fo id={}", errorMessage.getSubject().getId());
return String.format("(%d) args %s", errorMessage.getSubject().getId(), Arrays.toString(errorMessage.getArgs()));
}
String textTemplate = errorDictionary.getName();
return String.format(textTemplate, errorMessage.getArgs());
} catch (Exception errFormatting) { // MissingFormatArgumentException
log.warn("Error in message resolver for error {}: {}", errorMessage.getSubject(), ExceptionUtils.getStackTrace(errFormatting));
return String.format("(%d) args %s", errorMessage.getSubject().getId(), Arrays.toString(errorMessage.getArgs()));
}
String textTemplate = errorDictionary.getName();
return String.format(textTemplate, errorMessage.getArgs());
}
}

View file

@ -83,9 +83,11 @@ public class QueueConsumer implements AutoCloseable {
Object o = null;
int lastErrors = 0;
while (!closed.get()) {
String lastTopic = null;
try {
ConsumerRecords<String, Object> records = consumer.poll(Duration.of(10, ChronoUnit.SECONDS));
for (ConsumerRecord<String, Object> next : records) {
lastTopic = next.topic();
ConsumerSpecificClass<?> callback = callbacks.get(next.topic());
Class<?> clazz = callback.getClazz();
JavaType payloadType = json.getTypeFactory().constructParametricType(BaseRequest.class, clazz);
@ -99,7 +101,8 @@ public class QueueConsumer implements AutoCloseable {
}
lastErrors = 0;
} catch (Throwable e) {
log.error(ExceptionUtils.getStackTrace(e));
log.error("Listener {} last topic \"{}\", error: {}",
QueueConsumer.this.getClass().getName(), lastTopic, ExceptionUtils.getStackTrace(e));
if (producer != null && o != null) {
sendErrorResponse((BaseRequest<?>) o);
}