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

NIAD-2889: Bugfix - add additional JMS error handling #345

Merged
merged 7 commits into from
Oct 27, 2023
Merged
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Fixed

* Add additional error handling for exceptions raised when processing PSS queue, and MHS queue messages.
* Fix bug in some SQL statement which caused excessively large amounts of data to be returned, sometimes resulting in a PostgresSQL Out of Memory error.

## [0.15] - 2023-10-24

* Fixed issue with some `ObservationStatement` coded as blood pressure readings not being output into Bundle.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package uk.nhs.adaptors.connector.config;

import java.time.temporal.ChronoUnit;
import java.util.List;

import javax.sql.DataSource;

import lombok.extern.slf4j.Slf4j;
import org.jdbi.v3.core.Jdbi;
import org.jdbi.v3.core.mapper.RowMapper;
import org.jdbi.v3.core.spi.JdbiPlugin;
import org.jdbi.v3.core.statement.SqlLogger;
import org.jdbi.v3.core.statement.StatementContext;
import org.jdbi.v3.postgres.PostgresPlugin;
import org.jdbi.v3.sqlobject.SqlObjectPlugin;
import org.springframework.boot.autoconfigure.domain.EntityScan;
Expand All @@ -19,12 +15,13 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy;

import lombok.extern.slf4j.Slf4j;
import uk.nhs.adaptors.connector.dao.ImmunizationSnomedCTDao;
import uk.nhs.adaptors.connector.dao.MessagePersistDurationDao;
import uk.nhs.adaptors.connector.dao.MigrationStatusLogDao;
import uk.nhs.adaptors.connector.dao.PatientAttachmentLogDao;
import uk.nhs.adaptors.connector.dao.PatientMigrationRequestDao;
import uk.nhs.adaptors.connector.dao.SnomedCTDao;
import uk.nhs.adaptors.connector.dao.PatientAttachmentLogDao;

@Slf4j
@Configuration
Expand All @@ -37,15 +34,6 @@ public Jdbi jdbi(DataSource ds, List<JdbiPlugin> jdbiPlugins, List<RowMapper<?>>
TransactionAwareDataSourceProxy proxy = new TransactionAwareDataSourceProxy(ds);
Jdbi jdbi = Jdbi.create(proxy);

SqlLogger sqlLogger = new SqlLogger() {
@Override
public void logAfterExecution(StatementContext context) {
LOGGER.debug("sql {}, parameters {}, timeTaken {} ms", context.getRenderedSql(),
context.getBinding().toString(), context.getElapsedTime(ChronoUnit.MILLIS));
}
};
jdbi.setSqlLogger(sqlLogger);

jdbiPlugins.forEach(jdbi::installPlugin);
rowMappers.forEach(jdbi::registerRowMapper);
return jdbi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,27 @@ public class JmsListenerErrorHandler implements ErrorHandler {
WebClientRequestException.class, "Unable to connect to MHS"
);

/**
* Increment the delivery count for all exceptions, except for RETRYABLE_EXCEPTION_MESSAGES which are retried indefinitely.
* See <a href="https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/jms/listener/AbstractMessageListenerContainer.html#class-description">AbstractMessageListenerContainer</a>
* for documentation.
*/
@Override
public void handleError(Throwable t) {

LOGGER.warn("Handling JMS message error due to [{}] with message [{}]", t.getClass(), t.getMessage());
t.printStackTrace();

Throwable cause = t.getCause();
Class<? extends Throwable> classOfCause = cause.getClass();
if (cause == null) {
return;
}

Class<? extends Throwable> classOfCause = cause.getClass();
LOGGER.warn("Caught Error cause of type: [{}], with message: [{}]", classOfCause.toString(), cause.getMessage());

// Rety these specific exceptions continuously until they stop happening.
// These retries will happen until the associated transfer times out.
if (RETRYABLE_EXCEPTION_MESSAGES.containsKey(classOfCause)) {
benhession marked this conversation as resolved.
Show resolved Hide resolved
throw new RuntimeException(RETRYABLE_EXCEPTION_MESSAGES.get(classOfCause));
}
Expand Down