netty 关闭chnnal_GitHub - chnzhang/surging: surging 是一个分布式微服务框架,提供高性能RPC远程服务调用,采用Zookeeper、Consul作为sur...

surging                     English

surging 是一个分布式微服务框架,提供高性能RPC远程服务调用,采用Zookeeper、Consul作为surging服务的注册中心,集成了哈希,随机,轮询作为负载均衡的算法,RPC集成采用的是netty框架,采用异步传输。

名字由来

英文名:surging

中文名:滔滔

中文名来自周星驰的经典台词

我对阁下的景仰犹如滔滔江水,连绵不绝,犹如黄河泛滥,一发而不可收拾,而取名英文的含义也希望此框架能流行起来,也能像《.net core surging》这句英文语句含义一样,.net core技术风起云涌,冲击整个软件生态系统。

配置:

var host = new ServiceHostBuilder()

.RegisterServices(builder =>

{

builder.AddMicroService(option =>

{

option.AddServiceRuntime();//

option.AddRelateService();//添加支持服务代理远程调用

// option.UseZooKeeperManager(new ConfigInfo("127.0.0.1:2181")); //使用Zookeeper管理

option.UseConsulManager(new ConfigInfo("127.0.0.1:8500"));//使用Consul管理

option.UseDotNettyTransport();//使用Netty传输

option.UseRabbitMQTransport();//使用rabbitmq 传输

option.AddRabbitMQAdapt();//基于rabbitmq的消费的服务适配

// option.UseProtoBufferCodec();//基于protobuf序列化

option.UseMessagePackCodec();//基于MessagePack序列化

builder.Register(p => new CPlatformContainer(ServiceLocator.Current));//初始化注入容器

});

})

.SubscribeAt() //消息订阅

//.UseServer("127.0.0.1", 98)

//.UseServer("127.0.0.1", 98,“true”) //自动生成Token

//.UseServer("127.0.0.1", 98,“123456789”) //固定密码Token

.UseServer(options=> {

options.Ip = "127.0.0.1";

options.Port = 98;

//options.IpEndpoint = new IPEndPoint(IPAddress.Any, 98);

//options.Ip = "0.0.0.0";

options.ExecutionTimeoutInMilliseconds = 30000; //执行超时时间

options.Strategy=(int)StrategyType.Failover; //容错策略使用故障切换

options.RequestCacheEnabled=true; //开启缓存(只有通过接口代理远程调用,才能启用缓存)

options.Injection="return null"; //注入方式

options.InjectionNamespaces= new string[] { "Surging.IModuleServices.Common" }); //脚本注入使用的命名空间

options.BreakeErrorThresholdPercentage="50"; //错误率达到多少开启熔断保护

options.BreakeSleepWindowInMilliseconds=60000; //熔断多少毫秒后去尝试请求

options.BreakerForceClosed=false; //是否强制关闭熔断

options.BreakerRequestVolumeThreshold = 20;//10秒钟内至少多少请求失败,熔断器才发挥起作用

options.MaxConcurrentRequests== 100000;//支持最大并发

options.NotRelatedAssemblyFiles = "Centa.Agency.Application.DTO\\w*|StackExchange.Redis\\w*"; //排除无需依赖注册

})

.UseLog4net("Configs/log4net.config") //使用log4net记录日志

.UseLog4net() //使用log4net记录日志

.UseProxy() //使用Proxy

.UseStartup()

.Build();

using (host.Run())

{

Console.WriteLine($"服务端启动成功,{DateTime.Now}。");

}

服务路由访问配置:

[ServiceBundle("api/{Service}")]

JWT验证,接口方法添加以下特性:

[Authorization(AuthType = AuthorizationType.JWT)];

AppSecret验证,接口方法添加以下特性:

[Authorization(AuthType = AuthorizationType.AppSecret)];

订阅功能:

ServiceLocator.GetService< ISubscriptionAdapt >().SubscribeAt();

增加服务容错、服务容错降级、服务强制降级

增加容错策略Injection,脚本注入:

[Command(Strategy= StrategyType.Injection ,Injection = @"return null;")]

[Command(Strategy= StrategyType.Injection ,Injection = @"return

Task.FromResult(new Surging.IModuleServices.Common.Models.UserModel

{

Name=""fanly"",

Age=18

});",InjectionNamespaces =new string[] { "Surging.IModuleServices.Common"})]

增加容错策略Injection,本地模块注入:

[Command(Strategy= StrategyType.Injection ,Injection = @"return true;")]

增加缓存降级,怎么使用?

在业务接口方法上添加如下特性

[Command(Strategy= StrategyType.Failover,FailoverCluster =3,RequestCacheEnabled =true)] //RequestCacheEnabled =true 就是启用缓存

怎么拦截获取缓存

在业务接口方法上添加如下特性

[InterceptMethod(CachingMethod.Get, Key = "GetUser_id_{0}", Mode = CacheTargetType.Redis, Time = 480)]

怎么拦截删除缓存

在业务接口方法上添加如下特性

[InterceptMethod(CachingMethod.Remove, "GetUser_id_{0}", "GetUserName_name_{0}", Mode = CacheTargetType.Redis)]

怎么添加缓存KEY

在业务模型属性上添加,如下特性,可以支持多个

[CacheKey(1)]

配置拦截器

.AddClientIntercepted(typeof(CacheProviderInterceptor))

IDE:Visual Studio 2017 15.3 Preview ,vscode

框架:.NET core 2.0

文档

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值