GithubHelp home page GithubHelp logo

renliguo / polly-samples Goto Github PK

View Code? Open in Web Editor NEW

This project forked from app-vnext/polly-samples

0.0 2.0 0.0 43.64 MB

Provides sample implementations of the Polly library. The intent of this project is to help newcomers kick-start their use of Polly within their own projects.

License: GNU General Public License v2.0

C# 93.66% CSS 0.59% HTML 3.34% ASP 0.02% JavaScript 2.39%

polly-samples's Introduction

Polly-Samples

Provides sample implementations using the Polly library. The intent of this project is to help newcomers kick-start the use of Polly within their own projects. The samples demonstrate the policies in action, against faulting endpoints

About the numbered demos

Background

  • The demos run against an example 'faulting server' (also within the solution as PollyTestApp). To simulate failure, the dummy server rejects more than 3 calls from the same IP in any five-second period (bulkhead demos excepted).
  • Be sure to read the <summary/> at the top of each demo: this explains the intent of that demo, and what resilience it adds to its handling of the calls to the 'faulting server'.
  • Sometimes the <summary/> also highlights what this demo doesn't achieve - often picked up in the following demo. Explore the demos in sequence, for best understanding.
  • All demos exist in both sync and async forms.

Demo sequence

  • Demo 00 shows behaviour calling the faulting server every half-second, with no Polly policies protecting the call.
  • Demos 01-04 show various flavors of Polly retry.
  • Demos 06-07 show retry combined with Circuit-Breaker.
  • Demo 07 shows the Polly v5.0 PolicyWrap for combining policies.
  • Demo 08 adds Polly v5.0 Fallback, making the call protected (in a PolicyWrap) by a Fallback, Retry, Circuitbreaker.
  • Demo 09 shows the Polly v5.0 Timeout policy for an overall call timeout, in combination with Fallback and WaitAndRetry.

Bulkhead isolation demos

Background

The bulkhead isolation demos place calls against two different endpoints on a downstream server:

  • The good endpoint returns results in a timely manner
  • The faulting endpoint simulates a faulting downstream system: it does respond, but only after a long delay.
  • (Note: Unlike the other demos, there is no rate-limiting rejection of the caller.)

Demo sequence

In both bulkhead demos, the upstream system makes a random mixture of calls to the good and faulting endpoints.

  • In Demo 00 there is no isolation: calls to both the good and faulting endpoints share resources.
    • Sooner or later, the faulting stream of calls saturates all resource in the caller, starving the calls to the good endpoint of resource too.
    • Watch how the the calls to the good endpoint eventually start backing up (watch the 'pending' or 'faulting' counts climb), because the faulting stream of calls is starving the whole system of resource.
  • In Demo 01, the calls to faulting and good endpoints are separated by bulkhead isolation.
    • The faulting stream of calls still backs up and fails.
    • But the calls to the good endpoint are unaffected - they consistently succeed, because they are isolated in a separate bulkhead.

Running the demos

To start the dummy faulting server (PollyTestApp)

  • Start the dummy server, by starting PollyTestApp.
  • Be sure the port number for the dummy server in PollyDemos\Configuration.cs matches the port on which PollyTestApp has started on your machine (in the previous step).

Then ...

To run the demos - WPF (PollyTestClientWPF)

  • Start the PollyTestClientWPF application.
  • Start button starts a demo; Stop button stops it; Clear button clears the output.
  • Many Polly policies are about handling exceptions. If running the demos in debug mode out of Visual Studio and flow is interrupted by Visual Studio breaking on exceptions, uncheck the box "Break when this exception type is user-unhandled" in the dialog shown when Visual Studio breaks on an exception. Or simply run without debugging.

To run the demos - Console (PollyTestClientConsole)

  • To run a demo, uncomment the demo you wish to run in PollyTestClientConsole\program.cs. Then start PollyTestClientConsole.
  • Many Polly policies are about handling exceptions. If running the demos in debug mode out of Visual Studio and flow is interrupted by Visual Studio breaking on exceptions, uncheck the box "Break when this exception type is user-unhandled" in the dialog shown when Visual Studio breaks on an exception. Or simply run without debugging.

Want further information?

  • Any questions about the operation of the demos, ask on this repo; any questions about Polly, ask at Polly.
  • For full Polly syntax, see Polly.
  • For deeper discussions of transient fault-handling and further Polly patterns, see the Polly wiki

Slide deck from DevIntersections presentation

View the slides presented at DevIntersections and other conferences. You are welcome to use and adapt this presentation for not-for-profit presentations of Polly to co-workers, user groups and similar, subject to the condition that references to the .NET Foundation, App-vNext and Polly team are retained.

polly-samples's People

Contributors

joelhulen avatar dreisenberger avatar reisenberger avatar vincentshow avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.