WCF 项目应用连载[8] - 绑定、服务、行为 大数据传输与限流 - 下 (ServiceThrottlingAttribute)
因为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)的更多相关文章
- WCF 项目应用连载[3] - 双向通信 实例管理与服务端监控
WCF 项目应用连载[1] - 索引 - 轻量级的Log系统 - Lig Sample -序 第二节我们已经创建了Lig项目,并且能稳定工作了.现在我们来改进ILigAgent接口,实现WCF的双向通 ...
- WCF 项目应用连载[2] - 创建Lig日志系统
WCF 项目应用连载[1] - 索引 - 轻量级的Log系统 - Lig Sample -序 现在我们创建一个Lig工程 - Litelog 2.1 创建Lig服务 _________________ ...
- 服务熔断、降级、限流、异步RPC -- HyStrix
背景 伴随着业务复杂性的提高,系统的不断拆分,一个面向用户端的API,其内部的RPC调用层层嵌套,调用链条可能会非常长.这会造成以下几个问题: API接口可用性降低 引用Hystrix官方的一个例子, ...
- springcloud组件之hystrix服务熔断,降级,限流
hystrix 简介 Hystrix是什么 在分布式环境中,许多服务依赖项中的一些必然会失败.Hystrix是一个库,通过添加延迟容忍和容错逻辑,帮助你控制这些分布式服务之间的交互.Hystrix通过 ...
- WCF项目问题2-无法激活服务,因为它需要 ASP.NET 兼容性。没有未此应用程序启用 ASP.NET 兼容性。请在 web.config 中启用 ASP.NET 兼容性,或将 AspNetCompatibilityRequirementsAttribute.AspNetCompatibilityRequirementsMode 属性设置为 Required 以外的值。
无法激活服务,因为它需要 ASP.NET 兼容性.没有未此应用程序启用 ASP.NET 兼容性.请在 web.config 中启用 ASP.NET 兼容性,或将 AspNetCompatibility ...
- [WCF编程]9.性能与限流
一.性能概述 WCF服务的性能取决于很多因素.出了CPU.RAM和网络性能等常见的因素外,实例上下文模式.并发模式.数据契约的设计或使用的绑定等与WCF有关的因素都起着重要的作用. 实例上下文模式用来 ...
- Spring Cloud Alibaba | Sentinel: 服务限流高级篇
目录 Spring Cloud Alibaba | Sentinel: 服务限流高级篇 1. 熔断降级 1.1 降级策略 2. 热点参数限流 2.1 项目依赖 2.2 热点参数规则 3. 系统自适应限 ...
- 不死的小强 .net core 微服务 快速开发框架 Viper 限流
1.Viper是什么? Viper 是.NET平台下的Anno微服务框架的一个示例项目.入门简单.安全.稳定.高可用.全平台可监控.底层通讯可以随意切换thrift grpc. 自带服务发现.调用链追 ...
- Spring Cloud微服务Sentinel+Apollo限流、熔断实战总结
在Spring Cloud微服务体系中,由于限流熔断组件Hystrix开源版本不在维护,因此国内不少有类似需求的公司已经将眼光转向阿里开源的Sentinel框架.而以下要介绍的正是作者最近两个月的真实 ...
随机推荐
- UVa 二分图匹配 Biginners
UVa 1045 - The Great Wall Game 最小权匹配 题意:给你一个n*n的棋盘,上面有n个棋子,要求通过移动各个棋子使得棋子在同一行或者同一列或者对角线上,求最小移动次数. 思路 ...
- Python IDLE 运行错误:IDLE's subprocess didn't make connection. --已解决(原创)!
Python IDLE 错误描述: Subprocess Startup ErrorIDLE's subprocess didn't make connection. Either IDLE can' ...
- 【Cocos2d-x】截图分享功能
Cocos2d-x截图实现 图片将会保存在data/data/包名/files文件夹下. Android下分享一张图片 linux系统下的文件权限 普通情况下android下的每个应用程序都是一个独立 ...
- [ACM] hdu 1251 统计难题 (字典树)
统计难题 Problem Description Ignatius近期遇到一个难题,老师交给他非常多单词(仅仅有小写字母组成,不会有反复的单词出现),如今老师要他统计出以某个字符串为前缀的单词数量(单 ...
- javascript每日一练(四)——DOM二
一.DOM的创建,插入,删除 createElement(标签名) appendChild(节点) insertBefore(节点,原有节点) removeChild(节点) <!doctype ...
- django-cookieless 0.7 : Python Package Index
django-cookieless 0.7 : Python Package Index django-cookieless 0.7 Download django-cookieless-0.7.ta ...
- HDU 1593 find a way to escape
数学题. 题意是问你能不能逃脱. 当V1的 角速度大于 V2的时候,能够一直保持 V1,O(圆心),V2 三点一线. 跑到一定距离.角速度小于的时候,就以三点一线为初始状态直接跑直线. #includ ...
- crm查询记录共享给了哪些人
有时候,我们须要查询一个记录.共享给了哪些人?怎么做? 第一种做法:是sql的方式 select * from PrincipalObjectAccess where objectid = '5226 ...
- java中int,char,string三种类型的相互转换
如何将字串 String 转换成整数 int? int i = Integer.valueOf(my_str).intValue(); int i=Integer.parseInt(str); 如何将 ...
- linux命令:du,看文件大小
du -s698 . (698字节)From <http://jingyan.baidu.com/article/a17d52855c10bf8098c8f2c9.html>