surging 将推出社区版微服务平台
前言
对于.NET大家并不陌生,有大批的企业选择.NET作为公司构建多种应用的开发平台,但是近几年随着微服务,大数据,移动端,物联网兴起,而后.NET社区生态没有跟上时代的步伐,已开始趋于没落,而其中最具代表的微服务,能够提供多种业务场景的解决方案的只有surging ,而surging 最近几年也在不断推动发展,预计明年将升级成为微服务平台,在这之前会在公司的重点项目中使用surging ,以便推出给大家带来稳定,高效的微服务平台,大家如果要得到最新的消息可以添加群:21811617,此群请不要涉及政治,暴力,因为有些人玩不起。多聊技术,积极向上开心的事情,以下是介绍最新的微服务平台功能
过滤器
框架中有AuthorizationFilter,ExceptionFilter,ActionFilter,而ActionFilter是最近新添加的功能,此功能可以用来做权限,创建ActionFilter过滤器如下:
public class PermissionAttribute : BaseActionFilterAttribute { private readonly ISerializer<string> _serializer; public PermissionAttribute() { _serializer = ServiceLocator.Current.Resolvestring>>(); } public override Task OnActionExecutingAsync(ServiceRouteContext actionExecutedContext, CancellationToken cancellationToken) { var payload= RpcContext.GetContext().GetAttachment("payload"); var model= _serializer.Deserialize(payload.ToString().Trim('"').Replace("\\",""),typeof(UserModel)); // actionExecutedContext.ResultMessage.ExceptionMessage = "权限不足";//通过ExceptionMessage 来控制过滤 return Task.FromResult(model); } }
添加注入到引擎中,添加模块配置:
public class IntercepteModule : SystemModule { public override void Initialize(AppModuleContext context) { base.Initialize(context); } ////// Inject dependent third-party components /// /// protected override void RegisterBuilder(ContainerBuilderWrapper builder) { base.RegisterBuilder(builder); builder.AddClientIntercepted(typeof(CacheProviderInterceptor)); builder.AddFilter(typeof(PermissionAttribute)); //builder.AddClientIntercepted(typeof(LogProviderInterceptor)); } }
然后可以在接口方法中添加Permission特性
[Authorization(AuthType = AuthorizationType.JWT)] [Permission] [HttpPost(true),HttpPut(true)] TaskSave(IdentityUser requestData);
也可以在接口上添加Permission特性
[ServiceBundle("api/{Service}/{Method}")] [Permission] //[ServiceBundle("api/{Service}")] //[ServiceBundle("api/{Service}/{Method}/test")] //[ServiceBundle("api/{Service}/{Method}/test",false)] public interface IUserService: IServiceKey { [Authorization(AuthType = AuthorizationType.JWT)] [Permission] [HttpPost(true),HttpPut(true)] TaskSave(IdentityUser requestData); }
不登陆调用会看到如下错误信息:
然后从RpcContext.GetContext().GetAttachment("payload")代码中的jwt token 的payload 可以获取信息,断点测试如下:
链路跟踪
链路跟踪采用的是skywalking 6.0 , 而最新的已经升级到8.0, 可以看surging支持的skywalking 8.0:
平台可视化界面
总结
surging 支持的国标28181,rtmp,httpflv,ws,mqtt,rtsp就不过多介绍了,后续surging微服务平台 会更新到https://github.com/microsurging,请大家关注