Raki
Raki
CC#
Created by Raki on 1/25/2024 in #help
How to slow down my api call to a external service using polly
I came across this code and tried to implement but I believe only 10 calls are processed, Even if 50 calls made. Is that the expected behaviour. var rateLimitPolicy = Policy.RateLimitAsync<HttpResponseMessage>(10, TimeSpan.FromSeconds(1)); services .AddHttpClient < IContentfulManagementService, ContentfulManagementService > ((s, c) => { c.BaseAddress = new Uri(managementApiURL); c.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", managementApiKey); c.Timeout = timeout; }) .AddTransientHttpErrorPolicy(ErrorPolicy) .AddPolicyHandler(timeoutPolicy).AddPolicyHandler(rateLimitPolicy);
7 replies
CC#
Created by Raki on 1/25/2024 in #help
How to slow down my api call to a external service using polly
c#
services
.AddHttpClient < IContentfulManagementService, ContentfulManagementService > ((s, c) => {
c.BaseAddress = new Uri(managementApiURL);
c.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", managementApiKey);
c.Timeout = timeout;
})
.AddTransientHttpErrorPolicy(ErrorPolicy)
.AddPolicyHandler(timeoutPolicy);

private static Func < PolicyBuilder < HttpResponseMessage > , IAsyncPolicy < HttpResponseMessage >> ErrorPolicy =>
p => p.Or < TimeoutRejectedException > ().WaitAndRetryAsync(2, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));
}
c#
services
.AddHttpClient < IContentfulManagementService, ContentfulManagementService > ((s, c) => {
c.BaseAddress = new Uri(managementApiURL);
c.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", managementApiKey);
c.Timeout = timeout;
})
.AddTransientHttpErrorPolicy(ErrorPolicy)
.AddPolicyHandler(timeoutPolicy);

private static Func < PolicyBuilder < HttpResponseMessage > , IAsyncPolicy < HttpResponseMessage >> ErrorPolicy =>
p => p.Or < TimeoutRejectedException > ().WaitAndRetryAsync(2, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));
}
7 replies
CC#
Created by Raki on 1/22/2024 in #help
How to write retry policy in .net
So is this policy should be handled in the startup. I already have a retry policy has been added for timeout. I can't able to see the class ResiliencePipeline eventhough I have polly in my .net core. Seems like I have Microsoft.extension.http.polly. Is both are different. services .AddHttpClient<IContentfulManagementService, ContentfulManagementService>((s, c) => { c.BaseAddress = new Uri(managementApiURL); c.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", ManagementClientApiKey); c.Timeout = timeout; }) .AddTransientHttpErrorPolicy(ErrorPolicy) .AddPolicyHandler(timeoutPolicy); private static Func<PolicyBuilder<HttpResponseMessage>, IAsyncPolicy<HttpResponseMessage>> ErrorPolicy => p => p.Or<TimeoutRejectedException>().WaitAndRetryAsync(2, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));
7 replies
CC#
Created by Raki on 1/22/2024 in #help
How to write retry policy in .net
Any idea on how to start
7 replies
CC#
Created by Raki on 1/20/2024 in #help
Beginner question. what does this createhostbuilder do?
I don't see any file with the file name secrets or Platform scerets in the codebase
4 replies
CC#
Created by Raki on 1/16/2024 in #help
Need help on how to write unit tests in xunit for the code
I'm currently learning unit tests and need to know how to write test for the following method. It doesn't return anything just doing a action. How to asset that. I'm clueless on this one.
5 replies
CC#
Created by Raki on 9/21/2023 in #help
❔ How to set code expression value in web.config settings.
I want to store the datetime value somewhere and two projects should use this. How to achieve that in this case. I generally do this via web.config key
9 replies
CC#
Created by Raki on 5/25/2023 in #help
❔ Why deconstuctor/Finalize example not working in vs 2022. Anything missing
14 replies
CC#
Created by Raki on 5/25/2023 in #help
❔ Why deconstuctor/Finalize example not working in vs 2022. Anything missing
I'm just pressing F5 to run this but Ideally the deconstructor should be called when GC.Collect executes but in my console window. I don't see it
14 replies
CC#
Created by Raki on 4/12/2023 in #help
❔ Where to store the app service app settings variable so I can access them based on environment
Thanks it helped a lot
8 replies
CC#
Created by Raki on 12/2/2022 in #help
✅ How to check whether a given list is present in the List of list
thanks that helped to solve it
8 replies
CC#
Created by Raki on 12/2/2022 in #help
✅ How to check whether a given list is present in the List of list
8 replies
CC#
Created by Raki on 10/29/2022 in #help
What is meant by copy on build.
Thanks...
2 replies