0
andmattia created
- ABP Framework version: v7.4.5
- UI Type: Angular
- Database System: PostgreSQL
- Tiered (for MVC) or Auth Server Separated (for Angular): yes
I've an handler to sync data from microservices
public async Task HandleEventAsync(ProductEto eventData)
{
if (eventData != null)
{
using (var unitOfWork = _unitOfWorkManager.Begin())
{
_currentTenant.Change(eventData.TenantId);
try
{
var gmd = _objectMapper.Map<ProductEto, ProductSync>(eventData);
await _productSyncRepository.InsertAsync(gmd);
}
catch (Exception ex)
{
Logger.LogError(ex, "Handle Event ProductEto Error");
}
finally
{
await unitOfWork.CompleteAsync();
}
}
}
else
{
Logger.LogWarning("Input data is null into handle event ProductEto");
}
}
In this case I've a PK duplicate so Postgres raise an excetion but this happen in finally and my handler continue to retry process my data.
Also I observe that if I call InsertAsyc/UpdateAsync and not return to a local varibile update or insert in some case does't work, if I return the value it always work.
Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
3 Answer(s)
-
0
hi
You can try the code below
public async Task HandleEventAsync(ProductEto eventData) { if (eventData != null) { using (var unitOfWork = _unitOfWorkManager.Begin(requiresNew: true)) { _currentTenant.Change(eventData.TenantId); try { var gmd = _objectMapper.Map<ProductEto, ProductSync>(eventData); await _productSyncRepository.InsertAsync(gmd); await unitOfWork.CompleteAsync(); } catch (Exception ex) { Logger.LogError(ex, "Handle Event ProductEto Error"); } } } else { Logger.LogWarning("Input data is null into handle event ProductEto"); } }Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
If there is an
unhandled exceptionthe uow should fall back/fail.The
InsertAsyc/UpdateAsyncmethod has anautoSaveparameter. You can set it totrue.https://docs.abp.io/en/abp/latest/Unit-Of-Work#alternative-to-the-savechanges
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)