Git Product home page Git Product logo

hystrix.dotnet's Introduction

Hystrix.Dotnet

A combination of circuit breaker and timeout. The .NET version of the open source Hystrix library built by Netflix.

Build Status .NET Version Coverage Status License

Why?

In order to isolate failure in one dependency from taking down another component. Whenever the circuit breaker opens it returns an exception or runs the fallback without burdening the failing system. It sends through a single request on a regular interval to see if the dependent system is back in business.

How to use

Circuit breakers are the main concept in Hystrix, and they are identifyable by a group and command key, which are arbitrary strings to support structuring and organizing the various circuit breakers we have in our application. Every circuit breaker can have its own configuration regarding its timeout, fallback mechanism, error threshold, etc.

Once we have a reference to a circuit breaker (represented by the IHystrixCommand interface), we can execute an operation through it using either the synchronous version:

T result = hystrixCommand.Execute<T>(() => myFunctionWithReturnTypeT());

Or use the async version:

T result = await hystrixCommand.ExecuteAsync<T>(() => myAsyncFunctionWithReturnTypeTaskT());

In the documentation you can find more examples, and details about creating commands and customizing the configuration.

Sample projects

In the samples directory you can find an example project illustrating the configuration of Hystrix for ASP.NET and ASP.NET Core.

Known issues

Unlike the original Hystrix implementation, the current .Net implementation doesn't use a way to limit the maximum number of concurrent requests per command. Using the ExecuteAsync method will make efficient use of the threadpool, so it's not entirely clear whether it will give us any benefits.

Neither are retries implemented at this moment.

hystrix.dotnet's People

Contributors

1kastner avatar discosultan avatar jorritsalverda avatar markvincze avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hystrix.dotnet's Issues

Remove depedency to Log4Net

Hi,

Could you please remove dependency to Log4Net, it's sad we should use Log4Net if we want to use something else to log. Especially you don't have that much log in your solution.

Thanks

Signed Assembly not available in Nuget

Currently our application is signed, so we are facing issue while loading the unsigned Hystrix dlls. Please can you provide signed assembly for Hystrix.

Create online documentation from docstrings

I see a good documentation in some interfaces, e.g. the IHystrixCommand. Now I wondered whether it is possible to create an online documentation which is accessable for everybody. If so, a link the the global README.md would be great for doing quick and good research. Hystrix Javadocs are an example of what I could imagine. Now the question is, which exact standards did you comply with? Asking seems faster then reverse-engineering here, but I guess it is XMLDOCTAGS which could be used for creating a documentation with sandcastle.

[Questions] HystrixCommand Design Implementation

On Netfix java port, you wrap each "critical code" with a command. In other words, you need to create a new class which inherits from HystrixCommand and place your execute and fallback logic inside this class.
The approach which was selected for this port differs, so you do not need to create command classes.

  1. Why was this design was prefer?

IMHO, having also the "inheritance" approach is valuable and provides more flexibility and readability (especially for complex behaviors).
2. What is your take on that? would that something you consider supporting?

My last question refers to production readiness of this port.
3. Do you have this port already running on large scale production environments?

Thanks!

ObjectDisposedException on .NET Core

When running the metrics stream middleware, we occasionally see the following error in the logs generated by the framework:

Cannot access a disposed object.
Object name: 'WriteReqPool'.
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'WriteReqPool'.
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.WriteReqPool.Allocate()
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketOutput.WriteContext.DoWriteIfNeeded()
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.SocketOutput.WriteAllPending()
   at Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread.DoPostWork()

Doesn't seem to cause any actual problems though.
We have to figure out if we do something incorrectly in the middleware, or this is another problem (like aspnet/KestrelHttpServer#1402 (comment)) in Kestrel itself.

How to open the project

When I tried to open the Hystrix.Dotnet.sln file, this error message popped up:

E:\ProgrammingProjects\csharp-hystrix\src\Hystrix.Dotnet\Hystrix.Dotnet.csproj : error  : Der MSBuild-XML-Namespace muss der Standard-XML-Namespace des Projekts sein. Wenn das Projekt im MSBuild 2003-Format erstellt wurde, fügen Sie dem <Project>-Element xmlns="http://schemas.microsoft.com/developer/msbuild/2003" hinzu. Wenn das Projekt im alten Format 1.0 oder 1.2 erstellt wurde, konvertieren Sie es in das MSBuild 2003-Format.  E:\ProgrammingProjects\csharp-hystrix\src\Hystrix.Dotnet\Hystrix.Dotnet.csproj

E:\ProgrammingProjects\csharp-hystrix\test\Hystrix.Dotnet.UnitTests\Hystrix.Dotnet.UnitTests.csproj : error  : Der MSBuild-XML-Namespace muss der Standard-XML-Namespace des Projekts sein. Wenn das Projekt im MSBuild 2003-Format erstellt wurde, fügen Sie dem <Project>-Element xmlns="http://schemas.microsoft.com/developer/msbuild/2003" hinzu. Wenn das Projekt im alten Format 1.0 oder 1.2 erstellt wurde, konvertieren Sie es in das MSBuild 2003-Format.  E:\ProgrammingProjects\csharp-hystrix\test\Hystrix.Dotnet.UnitTests\Hystrix.Dotnet.UnitTests.csproj

E:\ProgrammingProjects\csharp-hystrix\src\Hystrix.Dotnet.AspNet\Hystrix.Dotnet.AspNet.csproj : error  : Der MSBuild-XML-Namespace muss der Standard-XML-Namespace des Projekts sein. Wenn das Projekt im MSBuild 2003-Format erstellt wurde, fügen Sie dem <Project>-Element xmlns="http://schemas.microsoft.com/developer/msbuild/2003" hinzu. Wenn das Projekt im alten Format 1.0 oder 1.2 erstellt wurde, konvertieren Sie es in das MSBuild 2003-Format.  E:\ProgrammingProjects\csharp-hystrix\src\Hystrix.Dotnet.AspNet\Hystrix.Dotnet.AspNet.csproj

E:\ProgrammingProjects\csharp-hystrix\src\Hystrix.Dotnet.AspNetCore\Hystrix.Dotnet.AspNetCore.csproj : error  : Der MSBuild-XML-Namespace muss der Standard-XML-Namespace des Projekts sein. Wenn das Projekt im MSBuild 2003-Format erstellt wurde, fügen Sie dem <Project>-Element xmlns="http://schemas.microsoft.com/developer/msbuild/2003" hinzu. Wenn das Projekt im alten Format 1.0 oder 1.2 erstellt wurde, konvertieren Sie es in das MSBuild 2003-Format.  E:\ProgrammingProjects\csharp-hystrix\src\Hystrix.Dotnet.AspNetCore\Hystrix.Dotnet.AspNetCore.csproj

E:\ProgrammingProjects\csharp-hystrix\test\Hystrix.Dotnet.AspNet.UnitTests\Hystrix.Dotnet.AspNet.UnitTests.csproj : error  : Der MSBuild-XML-Namespace muss der Standard-XML-Namespace des Projekts sein. Wenn das Projekt im MSBuild 2003-Format erstellt wurde, fügen Sie dem <Project>-Element xmlns="http://schemas.microsoft.com/developer/msbuild/2003" hinzu. Wenn das Projekt im alten Format 1.0 oder 1.2 erstellt wurde, konvertieren Sie es in das MSBuild 2003-Format.  E:\ProgrammingProjects\csharp-hystrix\test\Hystrix.Dotnet.AspNet.UnitTests\Hystrix.Dotnet.AspNet.UnitTests.csproj

E:\ProgrammingProjects\csharp-hystrix\test\Hystrix.Dotnet.AspNetCore.UnitTests\Hystrix.Dotnet.AspNetCore.UnitTests.csproj : error  : Der MSBuild-XML-Namespace muss der Standard-XML-Namespace des Projekts sein. Wenn das Projekt im MSBuild 2003-Format erstellt wurde, fügen Sie dem <Project>-Element xmlns="http://schemas.microsoft.com/developer/msbuild/2003" hinzu. Wenn das Projekt im alten Format 1.0 oder 1.2 erstellt wurde, konvertieren Sie es in das MSBuild 2003-Format.  E:\ProgrammingProjects\csharp-hystrix\test\Hystrix.Dotnet.AspNetCore.UnitTests\Hystrix.Dotnet.AspNetCore.UnitTests.csproj

I am sorry that it is in German but I guess the important parts can be understood. The major point is that the Project element should have the namespace "http://schemas.microsoft.com/developer/msbuild/2003".
I used Microsoft Visual Studio Community 2015 Version 14.0.25431.01 Update 3 when trying this.

Some information about which versions were used when you set up the project could be really helpful, thanks a lot!

Implement retry

When executing operations that can occasionally fail (for example because of flaky network connection), it'd be nice to be able to tell Hystrix to automatically retry.

Configuration per command:

  • Is retry enabled
  • How many times do we retry
  • Wait time between retries

Questions:

  • Increase wait time between subsequent retries? (use Jitter?)
  • Filter the situations in which we retry (for example we retry in case of a timeout, or in case of exceptions related to networking, but we don't retry in case of an InvalidOperationException)?

Owin middleware

Hello,

I'm running a self hosted API with Owin and have implemented my own Owin middleware to replace the HystrixStreamHandler that I cannot use without IIS.

I would like to make a PR to provide the middleware code in his own project (Hystrix.Dotnet.Owin) but it would be great to have the configuration parsing shared accross both projects (Hystrix.Dotnet.AspNet and Hystrix.Dotnet.Owin) and so extracting that logic into another project Hystrix.Dotnet.WebConfiguration.

What do you think ?

kévin

Add example for fallback function to README.md

I was searching for some explanation how I can set a fallback because I come from the Java version which uses self-written classes, see the Java version. So when I searched for the fallback I found some information, e.g. in the HystrixCommand implementation. It seems like I can just pass some delegate but a nice example for that in the global README.md would be great. If you agree I could do a pull request as well.

Stream metrics from console/windows application

On our microservices environment, most of the microservices are implemented as console applications which using Topshelf run as windows services.
I could not find any "out of the box" solution for streaming commands metrics from a console or windows application.
Am I missing something? Have you already implemented this?

Execute method does not pass exception as a parameter in Fallback method

Currently IHystrixCommand has Execute method with two overloads, but both does not provide exception parameter in fallback method. InnerException is valuable in case any exception occurred during execution, then in fallback we can log and throw an exception based on that.

Below are the two overloads.
T Execute(Func primaryFunction, CancellationTokenSource cancellationTokenSource = null);
T Execute(Func primaryFunction, Func fallbackFunction, CancellationTokenSource cancellationTokenSource = null)

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.