We've multiple dependent APIs that are calling inside loops and we need to persist each APIs response in one Audit table. Now, we're facing an issue like if the first API is throwing some exception (400/500...) we need to store at least audit data in the audit table but because of @Transactional it is rollicking audit table data also and we don't want to rollback those data. Please give needful suggestions. We tried this but no luck @Transactional(propagation = Propagation.NEVER)
,
@Transactional(propagation = Propagation.NOT_SUPPORTED)
. For NOT_SUPPORTED, it's stopped to proceed further.
@Transactional
public void apiImplementation() {
auditService.addDataInAuditTable("123","...");
boolean isLastPage = true;
int currentPage = 0;
do {
ResponseEntity<AbcModel> response = restApiService
apiCallToGetAbcDetails(100, currentPage++);
if (response != null && response.getStatusCode() == HttpStatus.OK) {
AbcModel abcModel = response.getBody();
if (abcModel != null) {
isLastPage = abcModel.isLastPage();
abcModel.getData.forEach(this::secondApiImplementation);
}
}
} while (!isLastPage);
}
private void secondApiImplementation(AbcModel abcModel) {
here we're saving data and calling the second Api... and also save data in auditlog for second api
}