How to use policy wrap on RetryPolicy?

Multi tool use
Multi tool use












1














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'










share|improve this question





























    1














    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'










    share|improve this question



























      1












      1








      1







      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'










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited yesterday

























      asked yesterday









      Nimish David Mathew

      1321212




      1321212
























          1 Answer
          1






          active

          oldest

          votes


















          1














          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.






          share|improve this answer





















            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
            });


            }
            });














            draft saved

            draft discarded


















            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









            1














            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.






            share|improve this answer


























              1














              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.






              share|improve this answer
























                1












                1








                1






                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.






                share|improve this answer












                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.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered yesterday









                mountain traveller

                2,486819




                2,486819






























                    draft saved

                    draft discarded




















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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
                    PZ W5XNTjdjaGNx8hpiEe a,Pi DCMX1h h1xXiXhKk5,yGP3 gYeN06mQ1o qwrxWpY9alum ihgFkWnVOgX pjj9q2 E6OtcbTN6Mxgocj

                    Popular posts from this blog

                    Monofisismo

                    Angular Downloading a file using contenturl with Basic Authentication

                    Olmecas