因为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. JVM调优总结(八)-典型配置举例2

    常见配置汇总 堆设置 -Xms:初始堆大小 -Xmx:最大堆大小 -XX:NewSize=n:设置年轻代大小 -XX:NewRatio=n:设置年轻代和年老代的比值.如:为3,表示年轻代与年老代比值为 ...

  2. linux环境设置:使ftp不输密码

    # cd ~; # vi .netrc; Add beloew words, 可以追加多个账户: machine yourservername login yourname password your ...

  3. boost::property_tree读取解析ini文件--推荐

    boost::property_tree读取解析ini文件 #include "stdafx.h" #include <iostream> #include <b ...

  4. 操作3 mongodb和mysql 开启慢查询日志 ,以及mongodb从配置文件启动

    1. mongodb从配置文件启动 创建配置文件:/usr/local/mongodb/etc/mongodb.conf 配置文件的内容为: #Directory and relavent set d ...

  5. ASP.NET - Eval数据绑定

    <!--新闻分类--> <div id ="category" class ="Frm"> <h4>新闻分类</h4& ...

  6. 水平线、垂直线——axure线框图部件库介绍

    1. 将水平线.垂直线拖动到axure页面编辑区域,如图:  2. 水平线.垂直线相关属性设置 主要属性有.线条的颜色.粗细.线条的样式.箭头的样式 来自:非原型不设计

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

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

  8. JS - 跳转页面

    <!-- 第一种: --> <script type="text/javascript"> window.location.href = "log ...

  9. 今天就这么乱糟糟的过啦~刚刚接触html,就稍微写了一下,明天加油,今天直接贴图

    2015-01-01 <!DOCTYPE HTML> <html> <head> <meta charset = "gb2312"> ...

  10. vector中的find

    vector中的find - huangyimin的专栏 - 博客频道 - CSDN.NET vector中的find 2011-01-13 09:57 11334人阅读 评论(0) 收藏 举报 ve ...