Hystrix.NET使用(c#)

本文介绍了如何在C#项目中使用Hystrix.NET库,通过实例展示了如何实现服务降级和熔断,并重点讲解了如何获取并展示类似于监控统计图的数据,以提升系统的容错性和稳定性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.简述


Hystrix在donet中的应用案例说明极少且不完整,此案例可以直接使用,基于donet4
适用点:隔离,熔断,降级,来解决web在高并发下,对远程服务的高依赖可能引起的雪崩问题
可以自己到github下载源码使用, 注意:直接下载的部分源码有问题,本案例已经修复这些bug


2.下载组件


链接: https://pan.baidu.com/s/1BM9VX4Z5Htc1Zxxvf9-u1A


3.组件结构






WEB URL:http://localhost:9000/dashboard/


STREAM URL: http://127.0.0.1:38080/Hystrix/


4.业务web中引入全部核心组件和独立组件,新建


-------AtlasPublisher.cs--------
     public class AtlasPublisher : IHystrixMetricsPublisher
    {
        CommandMetricObserver observer;


        public AtlasPublisher()
        {
            var atlasCfg = new AtlasConfig("http://10.0.75.2", 7101);
            observer = new CommandMetricObserver(atlasCfg);
            observer.Run();
        }


        public IHystrixMetricsPublisherCommand GetMetricsPublisherForCommand(HystrixCommandKey commandKey, HystrixCommandGroupKey commandGroupKey, HystrixCommandMetrics metrics, IHystrixCircuitBreaker circuitBreaker, IHystrixCommandProperties properties)
        {


            return new HystrixServoMetricsPublisherCommand(commandKey, commandGroupKey, metrics, circuitBreaker, properties);
        }


        public IHystrixMetricsPublisherThreadPool GetMetricsPublisherForThreadPool(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolMetrics metrics, IHystrixThreadPoolProperties properties)
        {
            return new Dummy1();
        }


        public void Dispose()
        {
            if (observer != null)
                observer.Stop();
            obser
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值