Giter VIP home page Giter VIP logo

fanliang11 / surging Goto Github PK

View Code? Open in Web Editor NEW
3.2K 305.0 925.0 27.81 MB

Surging is a micro-service engine that provides a lightweight, high-performance, modular RPC request pipeline. support Event-based Asynchronous Pattern and reactive programming ,The service engine supports http, TCP, WS,Grpc, Thrift,Mqtt, UDP, and DNS protocols. It uses ZooKeeper and Consul as a registry, and integrates it. Hash, random, polling, Fair Polling as a load balancing algorithm, built-in service governance to ensure reliable RPC communication, the engine contains Diagnostic, link tracking for protocol and middleware calls, and integration SkyWalking Distributed APM

License: MIT License

C# 88.55% CSS 1.18% JavaScript 3.84% Smarty 0.25% PowerShell 0.01% HTML 1.94% Thrift 0.01% Less 4.21%
microservices apigateway surging rabbitmq messagepack protobuffer json-serialization consul zookeeper log4net

surging's Introduction

surging                     English

Member project of .NET Core Community GitHub license

surging 是一个分布式微服务框架,提供高性能RPC远程服务调用,采用Zookeeper、Consul作为surging服务的注册中心,集成了哈希,随机,轮询,压力最小优先作为负载均衡的算法,RPC可以选择采用netty或thrift框架,采用异步非阻塞传输。


名字由来

英文名:surging

中文名:滔滔

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

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

微服务定义

微服务应该是可以自由组合拆分,对于每个业务都是独立的,针对于业务模块的 CRUD 可以注册为服务,而每个服务都是高度自治的,从开发,部署都是独立,而每个服务只做单一功能,利用领域驱动设计去更好的拆分成粒度更小的模块

微服务边界

微服务是针对业务的松耦合,也是粒度最小的功能业务模块,针对于行业解决方案,集成相应的service host,而针对于业务需要一些中间件来辅助,比如缓存中间件,eventbus中间件(消息中间件),数据储存中间件,而各个服务又可以互相通过rpc进行可靠性通信。

引擎是微服务的容器,而docker 是服务引擎的容器,而利用k8s或rancher可以针对docker集群化管理,可以服务编排弹性扩容,熟知工具,让工具物尽其用。

能做什么

1.简化的服务调用,通过服务规则的指定,就可以做到服务之间的远程调用,无需其它方式的侵入

2.服务自动注册与发现,不需要配置服务提供方地址,注册中心基于ServiceId 或者RoutePath查询服务提供者的地址和元数据,并且能够平滑添加或删除服务提供者。

3.软负载均衡及容错机制,通过surging内部负载算法和容错规则的设定,从而达到内部调用的负载和容错

4.分布式缓存中间件:通过哈希一致性算法来实现负载,并且有健康检查能够平滑的把不健康的服务从列表中删除

  1. 事件总线:通过对于事件总线的适配可以实现发布订阅交互模式

6.容器化持续集成与持续交付 :通过构建一体化Devops平台,实现项目的自动化构建、部署、测试和发布,从而提高生产环境的可靠性、稳定性、弹性和安全性。

  1. 业务模块化驱动引擎,通过加载指定业务模块,能够更加灵活、高效的部署不同版本的业务功能模块

引擎如何安装

docker hub : docker pull serviceengine/surging:版本号

nuget:Install-Package surging -Version 版本号

架构图

架构图

调用链

链路图

配置:

var host = new ServiceHostBuilder()
               .RegisterServices(builder =>
               {
                   builder.AddMicroService(option =>
                   {
                       option.AddServiceRuntime();//
                       option.AddRelateService();//添加支持服务代理远程调用
                        option.AddConfigurationWatch();//添加同步更新配置文件的监听处理
                       // 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.ShuntStrategy=AddressSelectorMode.Polling; //使用轮询负载分流策略
                   options.NotRelatedAssemblyFiles = "Centa.Agency.Application.DTO\\w*|StackExchange.Redis\\w*"; //排除无需依赖注册
               })
               //.UseLog4net("Configs/log4net.config") //使用log4net记录日志
               .UseNLog(LogLevel.Error, "Configs/NLog.config")// 使用NLog 记录日志
               //.UseLog4net(LogLevel.Error) //使用log4net记录日志
               //.UseLog4net()  //使用log4net记录日志
               .Configure(build =>
               build.AddEventBusFile("eventBusSettings.json", optional: false))//使用eventBusSettings.json文件进行配置
               .Configure(build =>
                build.AddCacheFile("cacheSettings.json", optional: false))//使用cacheSettings.json文件进行配置
               .UseProxy() //使用Proxy
               .UseStartup<Startup>()
               .Build();
               
           using (host.Run())
           {
               Console.WriteLine($"服务端启动成功,{DateTime.Now}");
           }

文件配置:

{
  "ConnectionString": "${Register_Conn}|127.0.0.1:8500", // ${环境变量名} |默认值,
  "SessionTimeout": "${Register_SessionTimeout}|50",
  "ReloadOnChange": true
}

非容器环境文件配置

 {
  "Ip": "${Server_IP}|127.0.0.1",
  "WatchInterval": 30,
  "Port": "${Server_port}",
  "Token": "true",
   "Protocol": "${Protocol}|Tcp", //支持Http,Tcp协议
  "RootPath": "${RootPath}",
  "RequestCacheEnabled": false
}

容器环境文件配置

 {
  "Ip": "${Server_IP}|0.0.0.0",//私有容器IP
  "WatchInterval": 30,
  "Port": "${Server_port}|98",//私有容器端口
   "MappingIp": "${Mapping_ip}",//公开主机IP
  "MappingPort": "${Mapping_Port}",//公开主机端口
   "Protocol": "${Protocol}|Tcp", //支持Http,Tcp协议
  "Token": "true",
  "RootPath": "${RootPath}",
  "RequestCacheEnabled": false
}

服务路由访问配置:

[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))

捐赠明细

surging 接受来自社区的捐赠,所有款项将通过 捐赠明细表 进行公示,接受社区监督。

IDE:Visual Studio 2017 15.5,vscode
框架:.NET core 2.1
QQ群:615562965

谁在使用

surging's People

Contributors

alexinea avatar anybt avatar archimate avatar brucehu123 avatar cfoan avatar fanliang11 avatar firstrose avatar imiyu avatar linch90 avatar liuhll avatar phil-guo avatar pintybo avatar smuki avatar wadnm avatar xiaobei930 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

surging's Issues

客户端 UseProxy与AddClientProxy部分功能重复了

builder.Services.Register(provider =>new ServiceProxyFactory(
                 provider.Resolve<IRemoteInvokeService>(),
                 provider.Resolve<ITypeConvertibleService>(),
                 provider.Resolve<IServiceProvider>(),
                 builder.GetInterfaceService()
                 )).As<IServiceProxyFactory>().SingleInstance();

new ServiceProxyFactory应该与UseProxy的作用重复了

Surging 数据返回大小有限制么?

服务端启动成功,2018/1/3 17:36:13。
fail: Surging.Core.DotNetty.DotNettyServerMessageListener[0]
与服务器:[::ffff:127.0.0.1]:34691通信时发送了错误。
System.Net.Sockets.SocketException (0x80004005): 远程主机强迫关闭了一个现有的连
接。
at DotNetty.Transport.Channels.Sockets.SocketChannelAsyncOperation.Validate()

at DotNetty.Transport.Channels.Sockets.AbstractSocketByteChannel.SocketByteCh
annelUnsafe.FinishRead(SocketChannelAsyncOperation operation)
fail: Surging.Core.DotNetty.DotNettyServerMessageListener[0]
与服务器:[::ffff:127.0.0.1]:57473通信时发送了错误。
System.Net.Sockets.SocketException (0x80004005): 远程主机强迫关闭了一个现有的连
接。
at DotNetty.Transport.Channels.Sockets.SocketChannelAsyncOperation.Validate()

at DotNetty.Transport.Channels.Sockets.AbstractSocketByteChannel.SocketByteCh
annelUnsafe.FinishRead(SocketChannelAsyncOperation operation)

服务间通过远程代理调用异常,请帮忙给看一下?

qq 20180106133010
我用这种方式远程调用接口,同时已经将远程接口引用到项目中

this.GetService<IProductService>().GetProduct(1);

远程服务接口声明

[Service(Date ="20180106",Director ="",Name ="获取产品数据")]
  Task<string> GetProduct(int id);

请帮忙分析一下原因,看看我的用法有问题吗,顺便能给出一个服务间调用的实例demo么,这个比较急,谢谢了!

使用api网关遇到的问题

hi~
我在使用api网关时,遇到几点小问题

  1. ModuleName 是不是取Service前的Name;比如UserAppService, ModuleName 是UserApp , 取User 不行

  2. 使用api网关能否指定http Method, GET/ POST ; 貌似现在只能是 POST JSON

服务调用

serviceProxyProvider.Invoke(model, path, serviceKey);
我写了一个测试 在service.client
public static void Test(IServiceProxyProvider serviceProxyProvider)
{
Dictionary<string, object> model = new Dictionary<string, object>();
model.Add("UserId", "1");
string path = "api/user/getuser";
string serviceKey = "User";

        var userProxy = serviceProxyProvider.Invoke<object>(model, path, serviceKey);
        var s = userProxy.Result;
    }

想通过api 方式调用服务
服务端和客户端启动后
image
user返回的信息
image
返回的是自定义属性当中的?
image

服务之间调用的时候,会报错。

    public Task<string> GetUserName(int id)
    {
        Console.WriteLine("被调用");

        StartRequest1();

        return Task.FromResult($"id:{id} is name fanly.");
    }


    private static void StartRequest1()
    {

        var service = ServiceLocator.GetService<IServiceProxyFactory>();
        var userProxy = service.CreateProxy<IUser2Service>();
        var ss = userProxy.GetUserName(123);
        Console.WriteLine(ss);

    }

2018-01-04 13:25:09,225 [32] ERROR Surging.Core.CPlatform.Runtime.Server.Implementation.DefaultServiceExecutor [(null)] - 执行本地逻辑时候发生了错误。
Autofac.Core.Registration.ComponentNotRegisteredException: The requested service 'Surging.Core.ProxyGenerator.IServiceProxyFactory' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.
at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable1 parameters) at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context, IEnumerable1 parameters)
at Surging.Core.CPlatform.Utilities.ServiceLocator.GetServiceT in D:\Users\yxl2016\Desktop\surging-master\src\Surging.Core\Surging.Core.CPlatform\Utilities\ServiceLocator.cs:line 12
at Surging.Modules.Common.Domain.UserService.StartRequest1() in D:\Users\yxl2016\Desktop\surging-master\src\Surging.Modules\Surging.Modules.Common\Domain\UserService.cs:line 32
at Surging.Modules.Common.Domain.UserService.GetUserName(Int32 id) in D:\Users\yxl2016\Desktop\surging-master\src\Surging.Modules\Surging.Modules.Common\Domain\UserService.cs:line 23
at (Object , Object[] )
at Surging.Core.CPlatform.Runtime.Server.Implementation.ServiceDiscovery.Implementation.ClrServiceEntryFactory.<>c__DisplayClass5_0.b__1(String key, IDictionary`2 parameters)
at Surging.Core.CPlatform.Runtime.Server.Implementation.DefaultServiceExecutor.d__6.MoveNext()

两个服务之间该怎么调用呢?

var result = this.GetService().GetMembers(10).Result; 用这个调用本服务是可以的,但是如何调用其他服务的接口呢?
例如我有两个服务一个订单服务,一个库存服务,我要在订单的服务中调用库存的服务,订单服务是不是需要引用订单服务中定义的接口库?

在调动接口http://localhost:729/api/user/getuser报错

我讲demo中的接口

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

new Surging.IModuleServices.Common.Models.UserModel
{
Name=""fanly"",
Age=19
};", InjectionNamespaces = new string[] { "Surging.IModuleServices.Common" }, RequestCacheEnabled = true)]
[Service(Date = "2017-8-11", Director = "fanly", Name = "获取用户")]
[InterceptMethod(CachingMethod.Get, Key = "GetUser_id_0", CacheSectionType = SectionType.ddlCache, Mode = CacheTargetType.Redis, Time = 480)]
Task GetUser(UserModel user);

属性RequestCacheEnabled 修改为true 想进入InterceptMethod 查看操作缓存的过程,结果报错,麻烦给看看是怎么回事,配置哪里有问题么?

===================================================

NullReferenceException: Object reference not set to an instance of an object.
Surging.Core.ProxyGenerator.Interceptors.Implementation.InterceptorProvider.GetInvocation(object proxy, IDictionary<string, object> parameters, string serviceId, Type returnType) in InterceptorProvider.cs
+
{
var entry = (from q in _serviceEntryManager.GetEntries()
let k = q.Attributes
where q.Descriptor.Id == serviceId
select q).FirstOrDefault();
var constructor = InvocationMethods.CompositionInvocationConstructor;
return constructor.Invoke(new object[]{
parameters,
serviceId,
GetKey(parameters),
entry.Attributes,
returnType,
proxy
Surging.Core.ProxyGenerator.Implementation.ServiceProxyBase.GetInvocation(IDictionary<string, object> parameters, string serviceId, Type returnType) in ServiceProxyBase.cs
+
}
}

    private IInvocation GetInvocation(IDictionary<string, object> parameters, string serviceId, Type returnType)
    {
        var invocation = _serviceProvider.GetInstances<IInterceptorProvider>();
        return invocation.GetInvocation(this, parameters, serviceId, returnType);
    }
    
    #endregion Protected Method
}

}
Surging.Core.ProxyGenerator.Implementation.ServiceProxyBase+d__8.MoveNext() in ServiceProxyBase.cs
+
var invoker = _serviceProvider.GetInstances(command.Strategy.ToString());
return await invoker.Invoke(parameters, serviceId, _serviceKey, typeof(T) == typeof(Object));
}
}
else
{
var invocation = GetInvocation(parameters, serviceId, typeof(T));
await _interceptor.Intercept(invocation);
message = invocation.ReturnValue is RemoteInvokeResultMessage
? invocation.ReturnValue as RemoteInvokeResultMessage : null;
result = invocation.ReturnValue;
}
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Surging.Core.ProxyGenerator.Implementation.RemoteServiceProxy+d__2.MoveNext() in RemoteServiceProxy.cs
+
{
}
public new async Task Invoke(IDictionary<string, object> parameters, string serviceId)
{
return await base.Invoke(parameters, serviceId);
}
}
}
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Surging.Core.ProxyGenerator.Implementation.ServiceProxyProvider+d__3.MoveNext() in ServiceProxyProvider.cs
+
var proxy= new RemoteServiceProxy(parameters["serviceKey"].ToString(), _serviceProvider);
result = await proxy.Invoke(parameters, serviceRoute.ServiceDescriptor.Id);
}
else
{
var proxy = new RemoteServiceProxy(null, _serviceProvider);
result = await proxy.Invoke(parameters, serviceRoute.ServiceDescriptor.Id);
}
return result;
}
public async Task Invoke(IDictionary<string, object> parameters, string routePath, string serviceKey)
{
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Surging.ApiGateway.Controllers.ServicesController+d__4.MoveNext() in ServicesController.cs
+
result = ServiceResult.Create(true, await _serviceProxyProvider.Invoke(model, path, serviceKey));
result.StatusCode = (int)ServiceStatusCode.Success;
}
else
{
result = ServiceResult.Create(true, await _serviceProxyProvider.Invoke(model, path));
result.StatusCode = (int)ServiceStatusCode.Success;
}
}
}
return result;
}
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
lambda_method(Closure , object )
Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable+Awaiter.GetResult()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+d__12.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+d__10.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+d__14.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+d__22.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+d__17.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+d__15.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Builder.RouterMiddleware+d__4.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware+d__7.MoveNext()

Show raw exception details
System.NullReferenceException: Object reference not set to an instance of an object.
at Surging.Core.ProxyGenerator.Interceptors.Implementation.InterceptorProvider.GetInvocation(Object proxy, IDictionary2 parameters, String serviceId, Type returnType) in E:\work\TechnicalPointSurvey\surging\surging-master\src\Surging.Core\Surging.Core.ProxyGenerator\Interceptors\Implementation\InterceptorProvider.cs:line 30 at Surging.Core.ProxyGenerator.Implementation.ServiceProxyBase.GetInvocation(IDictionary2 parameters, String serviceId, Type returnType) in E:\work\TechnicalPointSurvey\surging\surging-master\src\Surging.Core\Surging.Core.ProxyGenerator\Implementation\ServiceProxyBase.cs:line 114
at Surging.Core.ProxyGenerator.Implementation.ServiceProxyBase.d__81.MoveNext() in E:\work\TechnicalPointSurvey\surging\surging-master\src\Surging.Core\Surging.Core.ProxyGenerator\Implementation\ServiceProxyBase.cs:line 69 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at Surging.Core.ProxyGenerator.Implementation.RemoteServiceProxy.d__21.MoveNext() in E:\work\TechnicalPointSurvey\surging\surging-master\src\Surging.Core\Surging.Core.ProxyGenerator\Implementation\RemoteServiceProxy.cs:line 32 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at Surging.Core.ProxyGenerator.Implementation.ServiceProxyProvider.d__31.MoveNext() in E:\work\TechnicalPointSurvey\surging\surging-master\src\Surging.Core\Surging.Core.ProxyGenerator\Implementation\ServiceProxyProvider.cs:line 31 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at Surging.ApiGateway.Controllers.ServicesController.d__4.MoveNext() in E:\work\TechnicalPointSurvey\surging\surging-master\src\Surging.ApiGateway\Controllers\ServicesController.cs:line 64
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at lambda_method(Closure , Object )
at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d__15.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Builder.RouterMiddleware.d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.d__7.MoveNext()

网关聚合模型传递

{
“ServiceAggregation”:[
{
           "RoutePath": "api/user/getuser",
           "ServiceKey": "User",
          "Params":{"UserId":1},
           "Key":"Users"
},
{
           "RoutePath": "api/user/getuser",
           "ServiceKey": "User",
          "Params":{"UserId":1},
           "Key":"Roles"
}]
}

result return:

{"User":{"UserId": 1,"Name":"Fanly","Age":18},"Roles":{"RoleName": "Admin"}}

如何使用surging快速搭建项目

  1. 运行网关程序

default
可以把红框的(服务 | | 领域接口)删除,只部署运行的网关
default

  1. 新建服务项目

2.1 需要引用的服务创建

default

default
default

default

2.2 无需引用的服务创建

qq 20180116163838

default

default

default

default

default

这里只是个人的简单理解和使用,继续研究和使用作者代码,感谢作者的支持

前几天下载的代码怎么运行报错

您好,前几天下载下来学习,想在本地运行一下,出现 由于目标计算机积极拒绝,无法连接
本地开发环境的是是vs2017 ,求指导

运行案例出现异常

Unhandled Exception: System.AggregateException: One or more errors occurred. (Value cannot be null.
Parameter name: serviceKey) ---> System.ArgumentNullException: Value cannot be null.
Parameter name: serviceKey
at Autofac.Core.KeyedService..ctor(Object serviceKey, Type serviceType)
at Autofac.ResolutionExtensions.IsRegisteredWithKey[TService](IComponentContext context, Object serviceKey)
at Surging.Core.CPlatform.CPlatformContainer.IsRegistered[T](Object serviceKey) in C:\proj\surging\src\Surging.Core\Surging.Core.CPlatform\CPlatformContainer.cs:line 25
at Surging.Core.ProxyGenerator.Implementation.ServiceProxyBase.d__81.MoveNext() in C:\proj\surging\src\Surging.Core\Surging.Core.ProxyGenerator\Implementation\ServiceProxyBase.cs:line 67 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at Surging.Cores.ClientProxys.UserServiceClientProxy.d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Surging.Services.Client.Startup.<>c__DisplayClass7_0.<b__0>d.MoveNext() in C:\proj\surging\src\Surging.Services\Surging.Services.Client\Startup.cs:line 83
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait()
at Surging.Services.Client.Startup.Test(IServiceProxyFactory serviceProxyFactory) in C:\proj\surging\src\Surging.Services\Surging.Services.Client\Startup.cs:line 75
at Surging.Services.Client.Program.Main(String[] args) in C:\proj\surging\src\Surging.Services\Surging.Services.Client\Program.cs:line 74

api网关调用rpc服务时,如果参数不符,直接返回了Entity:null,机制有问题;

问题描述:
方法定义:public Task GetUserLevelModel(string userid)

此时如果http post的请求中,没有传递参数,目前机制是直接返回结果:{"Entity":null,"IsSucceed":true,"Message":"","StatusCode":200}
resp结果中没有参数不正确的提示;

且:此时用户的代码压根没执行,因此用户程序中参数为空的检查是不执行的。

原因分析:经过断点跟踪,
在 public async Task<ServiceResult> Path(string path, [FromQuery]string serviceKey, [FromBody]Dictionary<string, object> model) 的model参数为null或者参数的key不在model中,在发起rpc调用时TransportClient类 SendAsync方法,会抛异常,api网关直接将返回如上结果。

结论:此处的判断逻辑或者说错误提示应该更加明确,在参数不齐全的情况下,异常后的排查成本会很高。

运行环境net core sdk要求

运行Surging.Services.Server项目,出现闪退现象。如下图

image

image

解决:发现net core sdk 是2.0的不满足要求,需要升级为最新版本,如下图
image

Surging.ApiGateway 启动报错

InvalidOperationException: Can not find compilation library location for package 'Microsoft.ApplicationInsights'
Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths()
System.Linq.Enumerable+SelectManySingleSelectorIterator.MoveNext()
Microsoft.AspNetCore.Mvc.Razor.Compilation.MetadataReferenceFeatureProvider.PopulateFeature(IEnumerable<ApplicationPart> parts, MetadataReferenceFeature feature)
Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.PopulateFeature<TFeature>(TFeature feature)
Microsoft.AspNetCore.Mvc.Razor.Internal.RazorReferenceManager.GetCompilationReferences()
System.Threading.LazyInitializer.EnsureInitializedCore<T>(ref T target, ref bool initialized, ref object syncLock, Func<T> valueFactory)
Microsoft.AspNetCore.Mvc.Razor.Internal.RazorReferenceManager.get_CompilationReferences()
Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRoslynCompilationService.CreateCompilation(string compilationContent, string assemblyName)
Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRoslynCompilationService.Compile(RelativeFileInfo fileInfo, string compilationContent)
Microsoft.AspNetCore.Mvc.Razor.Internal.RazorCompilationService.Compile(RelativeFileInfo file)
Microsoft.AspNetCore.Mvc.Razor.Internal.CompilerCache.CreateCacheEntry(string relativePath, string normalizedPath, Func<RelativeFileInfo, CompilationResult> compile)
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Razor.Internal.CompilerCache.GetOrAdd(string relativePath, Func<RelativeFileInfo, CompilationResult> compile)
Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRazorPageFactoryProvider.CreateFactory(string relativePath)
Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.CreateCacheResult(HashSet<IChangeToken> expirationTokens, string relativePath, bool isMainPage)
Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.OnCacheMiss(ViewLocationExpanderContext expanderContext, ViewLocationCacheKey cacheKey)
Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.LocatePageFromViewLocations(ActionContext actionContext, string pageName, bool isMainPage)
Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.FindView(ActionContext context, string viewName, bool isMainPage)
Microsoft.AspNetCore.Mvc.ViewEngines.CompositeViewEngine.FindView(ActionContext context, string viewName, bool isMainPage)
Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ViewResultExecutor.FindView(ActionContext actionContext, ViewResult viewResult)
Microsoft.AspNetCore.Mvc.ViewResult+<ExecuteResultAsync>d__26.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+<InvokeResultAsync>d__30.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+<InvokeNextResultFilterAsync>d__28.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ResultExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+<InvokeNextResourceFilter>d__22.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ResourceExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+<InvokeAsync>d__20.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Builder.RouterMiddleware+<Invoke>d__4.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware+<Invoke>d__7.MoveNext()

独立部署成功,热部署无效

@fanliang11 我独立创建领域及控制台执行,并启动服务完成了服务的注册,对接口进行调用也OK;98端口为源项目服务,99是我自己实现的一个demo;现想把自己实现的服务寄宿在98端口对应的服务上,一直没有成功;我进行两种尝试
1.98服务启动后 将领域dll直接扔到服务目录一直无法发现服务;
2.98端口服务停掉,先放自现实的dll再启动,会报异常,无法加载所给的dll;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.