How to use policy wrap on RetryPolicy?

Multi tool use
I have the following retry policy which uses Polly.Extensions.Http
:
var retryPolicy = Policy.Handle<BrokenCircuitException>().OrTransientHttpError().WaitAndRetryAsync
(
retryCount: maxRetryCount,
sleepDurationProvider: attempt => TimeSpan.FromSeconds(Math.Pow(2, attempt)),
onRetryAsync: (exception, calculatedWaitDuration, retryCount, context) =>
{
//Code
}
);
I want to wrap the policy with circuit breaker and bulk head policies:
var circuitBreaker = Policy.Handle<HttpRequestException>().CircuitBreakerAsync(
exceptionsAllowedBeforeBreaking: maxExceptionsBeforeBreaking,
durationOfBreak: TimeSpan.FromSeconds(circuitBreakDurationSeconds),
onBreak: (exception, timespan, context) =>
{
//Code
},
onReset: (context) =>
{
//Code
}
);
var sharedBulkhead = Policy.BulkheadAsync(
maxParallelization: maxParallelizations,
maxQueuingActions: maxQueuingActions,
onBulkheadRejectedAsync: (context) =>
{
//Code
}
);
I use the following code to wrap the policies together:
Policy.WrapAsync(retryPolicy, circuitBreaker, sharedBulkhead);
This is giving an error: cannot convert from 'Polly.Retry.RetryPolicy<System.Net.Http.HttpResponseMessage>' to 'Polly.IAsyncPolicy'
c# asp.net polly
add a comment |
I have the following retry policy which uses Polly.Extensions.Http
:
var retryPolicy = Policy.Handle<BrokenCircuitException>().OrTransientHttpError().WaitAndRetryAsync
(
retryCount: maxRetryCount,
sleepDurationProvider: attempt => TimeSpan.FromSeconds(Math.Pow(2, attempt)),
onRetryAsync: (exception, calculatedWaitDuration, retryCount, context) =>
{
//Code
}
);
I want to wrap the policy with circuit breaker and bulk head policies:
var circuitBreaker = Policy.Handle<HttpRequestException>().CircuitBreakerAsync(
exceptionsAllowedBeforeBreaking: maxExceptionsBeforeBreaking,
durationOfBreak: TimeSpan.FromSeconds(circuitBreakDurationSeconds),
onBreak: (exception, timespan, context) =>
{
//Code
},
onReset: (context) =>
{
//Code
}
);
var sharedBulkhead = Policy.BulkheadAsync(
maxParallelization: maxParallelizations,
maxQueuingActions: maxQueuingActions,
onBulkheadRejectedAsync: (context) =>
{
//Code
}
);
I use the following code to wrap the policies together:
Policy.WrapAsync(retryPolicy, circuitBreaker, sharedBulkhead);
This is giving an error: cannot convert from 'Polly.Retry.RetryPolicy<System.Net.Http.HttpResponseMessage>' to 'Polly.IAsyncPolicy'
c# asp.net polly
add a comment |
I have the following retry policy which uses Polly.Extensions.Http
:
var retryPolicy = Policy.Handle<BrokenCircuitException>().OrTransientHttpError().WaitAndRetryAsync
(
retryCount: maxRetryCount,
sleepDurationProvider: attempt => TimeSpan.FromSeconds(Math.Pow(2, attempt)),
onRetryAsync: (exception, calculatedWaitDuration, retryCount, context) =>
{
//Code
}
);
I want to wrap the policy with circuit breaker and bulk head policies:
var circuitBreaker = Policy.Handle<HttpRequestException>().CircuitBreakerAsync(
exceptionsAllowedBeforeBreaking: maxExceptionsBeforeBreaking,
durationOfBreak: TimeSpan.FromSeconds(circuitBreakDurationSeconds),
onBreak: (exception, timespan, context) =>
{
//Code
},
onReset: (context) =>
{
//Code
}
);
var sharedBulkhead = Policy.BulkheadAsync(
maxParallelization: maxParallelizations,
maxQueuingActions: maxQueuingActions,
onBulkheadRejectedAsync: (context) =>
{
//Code
}
);
I use the following code to wrap the policies together:
Policy.WrapAsync(retryPolicy, circuitBreaker, sharedBulkhead);
This is giving an error: cannot convert from 'Polly.Retry.RetryPolicy<System.Net.Http.HttpResponseMessage>' to 'Polly.IAsyncPolicy'
c# asp.net polly
I have the following retry policy which uses Polly.Extensions.Http
:
var retryPolicy = Policy.Handle<BrokenCircuitException>().OrTransientHttpError().WaitAndRetryAsync
(
retryCount: maxRetryCount,
sleepDurationProvider: attempt => TimeSpan.FromSeconds(Math.Pow(2, attempt)),
onRetryAsync: (exception, calculatedWaitDuration, retryCount, context) =>
{
//Code
}
);
I want to wrap the policy with circuit breaker and bulk head policies:
var circuitBreaker = Policy.Handle<HttpRequestException>().CircuitBreakerAsync(
exceptionsAllowedBeforeBreaking: maxExceptionsBeforeBreaking,
durationOfBreak: TimeSpan.FromSeconds(circuitBreakDurationSeconds),
onBreak: (exception, timespan, context) =>
{
//Code
},
onReset: (context) =>
{
//Code
}
);
var sharedBulkhead = Policy.BulkheadAsync(
maxParallelization: maxParallelizations,
maxQueuingActions: maxQueuingActions,
onBulkheadRejectedAsync: (context) =>
{
//Code
}
);
I use the following code to wrap the policies together:
Policy.WrapAsync(retryPolicy, circuitBreaker, sharedBulkhead);
This is giving an error: cannot convert from 'Polly.Retry.RetryPolicy<System.Net.Http.HttpResponseMessage>' to 'Polly.IAsyncPolicy'
c# asp.net polly
c# asp.net polly
edited yesterday
asked yesterday


Nimish David Mathew
1321212
1321212
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
When policy configuration uses .HandleTransientHttpError()
or .OrTransientHttpError()
, the policies are configured to handle specific status code results of an execution returning HttpResponseMessage
.
This makes the returned policies of a type which fulfils the generic interface IAsyncPolicy<HttpResponseMessage>
rather than the non-generic IAsyncPolicy
.
To create a generic PolicyWrap<TResult>
using the PolicyWrap static syntax you must specify the generic type parameter explicitly:
Policy.WrapAsync<HttpResponseMessage>(retryPolicy, circuitBreaker, sharedBulkhead)
If you use the PolicyWrap instance syntax, the compiler can usually infer the syntax. So the following should also be sufficient:
retryPolicy.WrapAsync(circuitBreaker).WrapAsync(sharedBulkhead)
Polly documentation covers the differences between non-generic and generic policies, in general, in the readme and wiki.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53942022%2fhow-to-use-policy-wrap-on-retrypolicyhttpresponsemessage%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
When policy configuration uses .HandleTransientHttpError()
or .OrTransientHttpError()
, the policies are configured to handle specific status code results of an execution returning HttpResponseMessage
.
This makes the returned policies of a type which fulfils the generic interface IAsyncPolicy<HttpResponseMessage>
rather than the non-generic IAsyncPolicy
.
To create a generic PolicyWrap<TResult>
using the PolicyWrap static syntax you must specify the generic type parameter explicitly:
Policy.WrapAsync<HttpResponseMessage>(retryPolicy, circuitBreaker, sharedBulkhead)
If you use the PolicyWrap instance syntax, the compiler can usually infer the syntax. So the following should also be sufficient:
retryPolicy.WrapAsync(circuitBreaker).WrapAsync(sharedBulkhead)
Polly documentation covers the differences between non-generic and generic policies, in general, in the readme and wiki.
add a comment |
When policy configuration uses .HandleTransientHttpError()
or .OrTransientHttpError()
, the policies are configured to handle specific status code results of an execution returning HttpResponseMessage
.
This makes the returned policies of a type which fulfils the generic interface IAsyncPolicy<HttpResponseMessage>
rather than the non-generic IAsyncPolicy
.
To create a generic PolicyWrap<TResult>
using the PolicyWrap static syntax you must specify the generic type parameter explicitly:
Policy.WrapAsync<HttpResponseMessage>(retryPolicy, circuitBreaker, sharedBulkhead)
If you use the PolicyWrap instance syntax, the compiler can usually infer the syntax. So the following should also be sufficient:
retryPolicy.WrapAsync(circuitBreaker).WrapAsync(sharedBulkhead)
Polly documentation covers the differences between non-generic and generic policies, in general, in the readme and wiki.
add a comment |
When policy configuration uses .HandleTransientHttpError()
or .OrTransientHttpError()
, the policies are configured to handle specific status code results of an execution returning HttpResponseMessage
.
This makes the returned policies of a type which fulfils the generic interface IAsyncPolicy<HttpResponseMessage>
rather than the non-generic IAsyncPolicy
.
To create a generic PolicyWrap<TResult>
using the PolicyWrap static syntax you must specify the generic type parameter explicitly:
Policy.WrapAsync<HttpResponseMessage>(retryPolicy, circuitBreaker, sharedBulkhead)
If you use the PolicyWrap instance syntax, the compiler can usually infer the syntax. So the following should also be sufficient:
retryPolicy.WrapAsync(circuitBreaker).WrapAsync(sharedBulkhead)
Polly documentation covers the differences between non-generic and generic policies, in general, in the readme and wiki.
When policy configuration uses .HandleTransientHttpError()
or .OrTransientHttpError()
, the policies are configured to handle specific status code results of an execution returning HttpResponseMessage
.
This makes the returned policies of a type which fulfils the generic interface IAsyncPolicy<HttpResponseMessage>
rather than the non-generic IAsyncPolicy
.
To create a generic PolicyWrap<TResult>
using the PolicyWrap static syntax you must specify the generic type parameter explicitly:
Policy.WrapAsync<HttpResponseMessage>(retryPolicy, circuitBreaker, sharedBulkhead)
If you use the PolicyWrap instance syntax, the compiler can usually infer the syntax. So the following should also be sufficient:
retryPolicy.WrapAsync(circuitBreaker).WrapAsync(sharedBulkhead)
Polly documentation covers the differences between non-generic and generic policies, in general, in the readme and wiki.
answered yesterday
mountain traveller
2,486819
2,486819
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53942022%2fhow-to-use-policy-wrap-on-retrypolicyhttpresponsemessage%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
NXKH8dIS,zLVG5CJMg Bi5 1bl0OCdYuWxQbJc1yfQuvfwJHNT,Dm,ynDjBnP,0 QztIh,EUT,mfujrhJIGn5kC,bziMVrt7ji