Edition 0 Updated to asp. Net core 0


Designing resilient applications for Azure



Yüklə 11,82 Mb.
Pdf görüntüsü
səhifə252/288
tarix12.07.2023
ölçüsü11,82 Mb.
#136458
1   ...   248   249   250   251   252   253   254   255   ...   288
Designing resilient applications for Azure
https://learn.microsoft.com/azure/architecture/framework/resiliency/app-design
 

Transient fault handling
https://learn.microsoft.com/azure/architecture/best-practices/transient-faults
 
Implement retries with exponential backoff 
Retries with exponential backoff
 is a technique that retries an operation, with an exponentially 
increasing wait time, up to a maximum retry count has been reached (the 
exponential backoff
). This 
technique embraces the fact that cloud resources might intermittently be unavailable for more than a 
few seconds for any reason. For example, an orchestrator might be moving a container to another 
node in a cluster for load balancing. During that time, some requests might fail. Another example 
could be a database like SQL Azure, where a database can be moved to another server for load 
balancing, causing the database to be unavailable for a few seconds. 
There are many approaches to implement retries logic with exponential backoff. 
Implement resilient Entity Framework Core SQL 
connections 
For Azure SQL DB, Entity Framework (EF) Core already provides internal database connection resiliency 
and retry logic. But you need to enable the Entity Framework execution strategy for each 
DbContext
 
connection if you want to have 
resilient EF Core connections

For instance, the following code at the EF Core connection level enables resilient SQL connections that 
are retried if the connection fails. 
// Program.cs from any ASP.NET Core Web API
// Other code ...
builder.
Services
.
AddDbContext
(options => 



297 
CHAPTER 7 | Implement resilient applications 
options.
UseSqlServer
(builder.
Configuration
[
"ConnectionString"
], 
sqlServerOptionsAction: sqlOptions => 

sqlOptions.
EnableRetryOnFailure

maxRetryCount: 
10

maxRetryDelay: TimeSpan.
FromSeconds
(
30
), 
errorNumbersToAdd: 

Yüklə 11,82 Mb.

Dostları ilə paylaş:
1   ...   248   249   250   251   252   253   254   255   ...   288




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin