因为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. qrcode 4.0.4 : Python Package Index

    qrcode 4.0.4 : Python Package Index qrcode 4.0.4 Download qrcode-4.0.4.tar.gz QR Code image generato ...

  2. Linux安装完Tomcat后无法登陆管理界面

    今天在Linux中安装完Tomcat后无法登陆Tomcat的管理界面,也就无法利用Tomcat管理界面来部署项目. 在Windows中一般配置完Tomcat后,只要在[conf]目录下的“tomcat ...

  3. 极限挑战—C#+ODP 100万条数据导入Oracle数据库仅用不到1秒

    链接地址:http://www.cnblogs.com/armyfai/p/4646213.html 要:在这里我们将看到的是C#中利用ODP实现在Oracle数据库中瞬间导入百万级数据,这对快速批量 ...

  4. perl学习(8) 控制:unless,until,next,redo,last

    Perl中实现了所有C 的操作符! Perl力求代码最少! 1.1.unless unless的含义是:除非条件为真,否则执行块中的代码,和if正好相反 unless($fred=~ /^[A-Z_] ...

  5. VS2008通过 map 和 cod 文件定位崩溃代码行

    VS 2005/2008使用map文件查找程序崩溃原因 一般程序崩溃可以通过debug,找到程序在那一行代码崩溃了,最近编一个多线程的程序,都不知道在那发生错误,多线程并发,又不好单行调试,终于找到一 ...

  6. 手机端viewport的设置规范

    <meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale ...

  7. 首款符合PICO-ITX规格的A20开源硬件开发平台

    http://mp.weixin.qq.com/mp/appmsg/show?__biz=MjM5NzM0MjcyMQ==&appmsgid=10001083&itemidx=2&am ...

  8. [置顶] 应广大童鞋的要求提供一个封装模块,直接和ADB 服务进程交互

    很多童鞋在用ADB 的时候都是直接启动ADB 的进程,然后通过管道的方式获取输出,这样多个线程同时使用ADB 的时候任务管理器一闪一闪的,是不是很不爽啊,原先介绍过可以直接和ADB 服务进程通信,不用 ...

  9. 大豆生物柴油驱动的大巴斯(Bus)

    请看下图: 这是大豆生物柴油(Soybean biodiesel)驱动的大巴斯(Bus)的外观,感觉非常有劲. 回想历史,1893年,德国学者Rudolf Diesel(1858-1913)发明了一种 ...

  10. zabbix 监控jvm

    tomcat 机器配置: [root@wx03 lib]# pwd /usr/local/apache-tomcat-7.0.55/lib [root@wx03 lib]# ls -ltr *jmx* ...