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框架.而以下要介绍的正是作者最近两个月的真实 ...
随机推荐
- mockito中两种部分mock的实现,spy、callRealMethod
什么是类的部分mock(partial mock)?A:部分mock是说一个类的方法有些是实际调用,有些是使用mockito的stubbing(桩实现). 为什么需要部分mock? A:当需要测试一个 ...
- 解决linux下javac -version和java -version版本显示不一致
解决linux下javac -version和java -version版本显示不一致 [javascript] view plaincopy [root@localhost usr]# $JAVA_ ...
- 一步一步重写 CodeIgniter 框架 (2) —— 实现简单的路由功能
在上一课中,我们实现了简单的根据 URI 执行某个类的某个方法.但是这种映射没有扩展性,对于一个成熟易用的框架肯定是行不通的.那么,我们可以让 框架的用户 通过自定义这种转换来控制,用 CI 的术语就 ...
- window批处理-3.go
go: 控制批处理中的命令运行流程 命令格式: go label lable--行号 demo bat @echo off echo 跳过中间.运行最后 goto last type a.txt :l ...
- Study notes for Sparse Coding
Sparse Coding Sparse coding is a class of unsupervised methods for learning sets of over-complete ba ...
- Android开发10.1:UI组件适配器AdapterView(创建ListView,Adapter接口)
@version:Android4.3 API18 @author:liuxinming 概述 AdapterView继承了ViewGroup,它的本质是容器 ...
- springmvc + jquery easyui实现分页显示
如有不明确的地方,戏迎增加QQ群交流:66728073 推荐一本Java学习的书:深入理解Java7 一,下载并导入jquery easyui的导 <link rel="st ...
- C# - Environment类,获取桌面的路径
private void button1_Click(object sender, EventArgs e) { string Path = Environment.GetFolderPath(Env ...
- C++和JNI的数据转换
链接地址:http://blog.csdn.net/manymore13/article/details/19078713 转载地址:http://www.cnblogs.com/daniel-she ...
- QUrl不同版本之间的坑
在项目中使用了native application + html的方式构建界面. 之前在4.8.4用QUrl直接加载相对路径一点问题都没有.但是切换到5.1编译之后却发现本地的html文件全部没有加载 ...