因为ORM的原因,对Attribute编程有一种情节。。所以这节的出现,完全是因为在WCF对自定义Attribute的一种应用。

WCF 项目应用连载[7] - 绑定、服务、行为 大数据传输与限流 - 上

前面一节已经讲得差不多够了。

对WCF的限流,这节,提供一个类。ServiceThrottlingAttribute

让你以硬编码方式使用WCF服务限流

    [ServiceThrottling(50,200,100)]
[ServiceContract(CallbackContract = typeof(ILigAgentCallback))]
public interface ILigAgent
public class ServiceThrottlingAttribute : Attribute,IServiceBehavior
{
#region Constructors
public ServiceThrottlingAttribute()
: this(defaultCalls, defaultInstances, defaultSession)
{
} public ServiceThrottlingAttribute(int maxCalls, int maxInstances, int maxSessions)
{
this.Initialize(maxCalls, maxInstances, maxSessions);
}
#endregion #region Interfaces
/// <summary>
///
/// </summary>
/// <param name="serviceDescriptiong"></param>
/// <param name="serviceHostBase"></param>
/// <param name="endpoints"></param>
/// <param name="bindingParameters"></param>
void IServiceBehavior.AddBindingParameters(ServiceDescription serviceDescriptiong, ServiceHostBase serviceHostBase,
Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters)
{
} /// <summary>
///
/// </summary>
/// <param name="serviceDescription"></param>
/// <param name="serviceHostBase"></param>
void IServiceBehavior.ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
ServiceThrottlingBehavior tbehavior = serviceDescription.Behaviors.Find<ServiceThrottlingBehavior>();
if (tbehavior == null)
{
serviceDescription.Behaviors.Add(this.throttlingBehavior);
}
} /// <summary>
///
/// </summary>
/// <param name="serviceDescription"></param>
/// <param name="serviceHostBase"></param>
void IServiceBehavior.Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{ }
#endregion #region Private Helpers
private void Initialize(int maxCalls, int maxInstances, int maxSessions)
{
this.throttlingBehavior = new ServiceThrottlingBehavior();
this.throttlingBehavior.MaxConcurrentCalls = maxCalls;
this.throttlingBehavior.MaxConcurrentInstances = maxInstances;
this.throttlingBehavior.MaxConcurrentSessions = maxSessions;
}
#endregion #region Fields
private const int defaultThrottling = 50;
private const int defaultCalls = 50;
private const int defaultInstances = 200;
private const int defaultSession = 100;
private ServiceThrottlingBehavior throttlingBehavior = null;
#endregion
}

WCF 项目应用连载[8] - 绑定、服务、行为 大数据传输与限流 - 下 (ServiceThrottlingAttribute)的更多相关文章

  1. WCF 项目应用连载[3] - 双向通信 实例管理与服务端监控

    WCF 项目应用连载[1] - 索引 - 轻量级的Log系统 - Lig Sample -序 第二节我们已经创建了Lig项目,并且能稳定工作了.现在我们来改进ILigAgent接口,实现WCF的双向通 ...

  2. WCF 项目应用连载[2] - 创建Lig日志系统

    WCF 项目应用连载[1] - 索引 - 轻量级的Log系统 - Lig Sample -序 现在我们创建一个Lig工程 - Litelog 2.1 创建Lig服务 _________________ ...

  3. 服务熔断、降级、限流、异步RPC -- HyStrix

    背景 伴随着业务复杂性的提高,系统的不断拆分,一个面向用户端的API,其内部的RPC调用层层嵌套,调用链条可能会非常长.这会造成以下几个问题: API接口可用性降低 引用Hystrix官方的一个例子, ...

  4. springcloud组件之hystrix服务熔断,降级,限流

    hystrix 简介 Hystrix是什么 在分布式环境中,许多服务依赖项中的一些必然会失败.Hystrix是一个库,通过添加延迟容忍和容错逻辑,帮助你控制这些分布式服务之间的交互.Hystrix通过 ...

  5. WCF项目问题2-无法激活服务,因为它需要 ASP.NET 兼容性。没有未此应用程序启用 ASP.NET 兼容性。请在 web.config 中启用 ASP.NET 兼容性,或将 AspNetCompatibilityRequirementsAttribute.AspNetCompatibilityRequirementsMode 属性设置为 Required 以外的值。

    无法激活服务,因为它需要 ASP.NET 兼容性.没有未此应用程序启用 ASP.NET 兼容性.请在 web.config 中启用 ASP.NET 兼容性,或将 AspNetCompatibility ...

  6. [WCF编程]9.性能与限流

    一.性能概述 WCF服务的性能取决于很多因素.出了CPU.RAM和网络性能等常见的因素外,实例上下文模式.并发模式.数据契约的设计或使用的绑定等与WCF有关的因素都起着重要的作用. 实例上下文模式用来 ...

  7. Spring Cloud Alibaba | Sentinel: 服务限流高级篇

    目录 Spring Cloud Alibaba | Sentinel: 服务限流高级篇 1. 熔断降级 1.1 降级策略 2. 热点参数限流 2.1 项目依赖 2.2 热点参数规则 3. 系统自适应限 ...

  8. 不死的小强 .net core 微服务 快速开发框架 Viper 限流

    1.Viper是什么? Viper 是.NET平台下的Anno微服务框架的一个示例项目.入门简单.安全.稳定.高可用.全平台可监控.底层通讯可以随意切换thrift grpc. 自带服务发现.调用链追 ...

  9. Spring Cloud微服务Sentinel+Apollo限流、熔断实战总结

    在Spring Cloud微服务体系中,由于限流熔断组件Hystrix开源版本不在维护,因此国内不少有类似需求的公司已经将眼光转向阿里开源的Sentinel框架.而以下要介绍的正是作者最近两个月的真实 ...

随机推荐

  1. Unix时间戳 POSIX时间 Unix时间

    Unix时间戳(Unix timestamp),或称Unix时间(Unix time).POSIX时间(POSIX time),是一种时间表示方式,定义为从格林威治时间1970年01月01日00时00 ...

  2. Oracle undo 镜像数据探究

                                                                 Oracle undo 镜像数据探究  今天是2013-08-18,隔别一周的 ...

  3. [置顶] think in java interview-高级开发人员面试宝典(八)

    面经出了7套,收到许多读者的Email,有许多人说了,这些基础知识是不是为了后面进一步的”通向架构师的道路“做准备的? 对的,你们没有猜错,就是这样的,我一直在酝酿后面的”通向架构师的道路“如何开章. ...

  4. How to install vim on linux

    前几日了解到 vim 文本编辑器,据说很强大,使用起来效率很高,今天怀着很好奇的心理,学习了一下vim编辑器的下载安装方法,在此详细介绍一下安装vim编辑器的几种常用方法: 第一种方法就是在 Ubun ...

  5. 开源JDBC工具类DbUtils

    本篇将会详细地介绍Apache公司的JDBC帮助工具类DbUtils以及如何使用.在上一篇中我们已经通过将以前对dao层使用JDBC操作数据库的冗余代码进行了简易封装形成自己的简单工具类JdbcUti ...

  6. 软考之路(四)---软件project一 概念模型,逻辑模型,物理模型

    自从接触到数据库到如今这三个概念大家理解的还有些不清楚,今天来为大家解答疑惑,共同提高,结合生活理解 概念模型        概念模型就是在了解了用户的需求,用户的业务领域工作情况以后,经过分析和总结 ...

  7. Eclipse使用总结

    Eclipse使用总结 1.Eclipse中出现无法找到Maven包     症状:出现org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER, 且出现无法找 ...

  8. Solarized Colorscheme for IntelliJ IDEA

    Solarized Colorscheme for IntelliJ IDEA Original Solarized color scheme developed by Ethan Schoonove ...

  9. 阿斯钢iojeg9uhweu9erhpu9hyw49

    http://www.huihui.cn/share/8424421 http://www.huihui.cn/share/8424375 http://www.huihui.cn/share/842 ...

  10. perl 贪婪匹配小例子

    redis01:/root# cat x2.pl my $str="a19823a456123"; if ($str =~/a(.*)23/){print "1----& ...