From 00be99c72d505a3bd67f9526fc040c1deb0ec098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BE=E8=BD=AC=E5=9B=9E=E9=AD=82?= Date: Tue, 2 Jul 2019 00:17:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DotNettyServerMessageListener.cs | 7 ++++--- .../DotNettyTransportClientFactory.cs | 3 ++- .../Implementation/RemoteServiceProxy.cs | 19 ++++++++++++------- .../Implementation/ServiceProxyGenerater.cs | 3 +++ .../Implementation/ServiceProxyProvider.cs | 3 +++ 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/Surging.Core/Surging.Core.DotNetty/DotNettyServerMessageListener.cs b/src/Surging.Core/Surging.Core.DotNetty/DotNettyServerMessageListener.cs index 6e3d94ef4..81f8a1104 100644 --- a/src/Surging.Core/Surging.Core.DotNetty/DotNettyServerMessageListener.cs +++ b/src/Surging.Core/Surging.Core.DotNetty/DotNettyServerMessageListener.cs @@ -65,7 +65,7 @@ public async Task StartAsync(EndPoint endPoint) IEventLoopGroup bossGroup = new MultithreadEventLoopGroup(1); IEventLoopGroup workerGroup = new MultithreadEventLoopGroup();//Default eventLoopCount is Environment.ProcessorCount * 2 var bootstrap = new ServerBootstrap(); - + if (AppConfig.ServerOptions.Libuv) { var dispatcher = new DispatcherEventLoopGroup(); @@ -78,13 +78,14 @@ public async Task StartAsync(EndPoint endPoint) bossGroup = new MultithreadEventLoopGroup(1); workerGroup = new MultithreadEventLoopGroup(); bootstrap.Channel(); - } + } bootstrap .Option(ChannelOption.SoBacklog, AppConfig.ServerOptions.SoBacklog) .ChildOption(ChannelOption.Allocator, PooledByteBufferAllocator.Default) .Group(bossGroup, workerGroup) .ChildHandler(new ActionChannelInitializer(channel => { + //设置数据传输协议和解码器,客户端需一致 var pipeline = channel.Pipeline; pipeline.AddLast(new LengthFieldPrepender(4)); pipeline.AddLast(new LengthFieldBasedFrameDecoder(int.MaxValue, 0, 4, 0, 4)); @@ -162,7 +163,7 @@ public override void ExceptionCaught(IChannelHandlerContext context, Exception e { context.CloseAsync();//客户端主动断开需要应答,否则socket变成CLOSE_WAIT状态导致socket资源耗尽 if (_logger.IsEnabled(LogLevel.Error)) - _logger.LogError(exception,$"与服务器:{context.Channel.RemoteAddress}通信时发送了错误。"); + _logger.LogError(exception, $"与服务器:{context.Channel.RemoteAddress}通信时发送了错误。"); } #endregion Overrides of ChannelHandlerAdapter diff --git a/src/Surging.Core/Surging.Core.DotNetty/DotNettyTransportClientFactory.cs b/src/Surging.Core/Surging.Core.DotNetty/DotNettyTransportClientFactory.cs index f3ddc3824..fc83be46c 100644 --- a/src/Surging.Core/Surging.Core.DotNetty/DotNettyTransportClientFactory.cs +++ b/src/Surging.Core/Surging.Core.DotNetty/DotNettyTransportClientFactory.cs @@ -63,6 +63,7 @@ public DotNettyTransportClientFactory(ITransportMessageCodecFactory codecFactory _bootstrap = GetBootstrap(); _bootstrap.Handler(new ActionChannelInitializer(c => { + //设置数据传输协议和解码器,与服务端对应 var pipeline = c.Pipeline; pipeline.AddLast(new LengthFieldPrepender(4)); pipeline.AddLast(new LengthFieldBasedFrameDecoder(int.MaxValue, 0, 4, 0, 4)); @@ -130,7 +131,7 @@ public void Dispose() private static Bootstrap GetBootstrap() { IEventLoopGroup group; - + var bootstrap = new Bootstrap(); if (AppConfig.ServerOptions.Libuv) { diff --git a/src/Surging.Core/Surging.Core.ProxyGenerator/Implementation/RemoteServiceProxy.cs b/src/Surging.Core/Surging.Core.ProxyGenerator/Implementation/RemoteServiceProxy.cs index 76d52f017..d1d45850a 100644 --- a/src/Surging.Core/Surging.Core.ProxyGenerator/Implementation/RemoteServiceProxy.cs +++ b/src/Surging.Core/Surging.Core.ProxyGenerator/Implementation/RemoteServiceProxy.cs @@ -9,27 +9,32 @@ namespace Surging.Core.ProxyGenerator.Implementation { - public class RemoteServiceProxy: ServiceProxyBase + public class RemoteServiceProxy : ServiceProxyBase { + /// + /// 远程服务代理,通过RoutePath调用服务时使用 + /// 由ServiceProxyProvider调用 + /// 通过执行基类的Invoke函数实现远程服务调用 + /// public RemoteServiceProxy(string serviceKey, CPlatformContainer serviceProvider) - :this(serviceProvider.GetInstances(), - serviceProvider.GetInstances(),serviceKey,serviceProvider, + : this(serviceProvider.GetInstances(), + serviceProvider.GetInstances(), serviceKey, serviceProvider, serviceProvider.GetInstances()) { - + } public RemoteServiceProxy(IRemoteInvokeService remoteInvokeService, ITypeConvertibleService typeConvertibleService, String serviceKey, CPlatformContainer serviceProvider, IServiceRouteProvider serviceRouteProvider - ):base(remoteInvokeService, typeConvertibleService, serviceKey, serviceProvider) + ) : base(remoteInvokeService, typeConvertibleService, serviceKey, serviceProvider) { } - public new async Task Invoke(IDictionary parameters, string serviceId) + public new async Task Invoke(IDictionary parameters, string serviceId) { - return await base.Invoke(parameters, serviceId); + return await base.Invoke(parameters, serviceId); } } diff --git a/src/Surging.Core/Surging.Core.ProxyGenerator/Implementation/ServiceProxyGenerater.cs b/src/Surging.Core/Surging.Core.ProxyGenerator/Implementation/ServiceProxyGenerater.cs index 4380a8f94..6454fea2b 100644 --- a/src/Surging.Core/Surging.Core.ProxyGenerator/Implementation/ServiceProxyGenerater.cs +++ b/src/Surging.Core/Surging.Core.ProxyGenerator/Implementation/ServiceProxyGenerater.cs @@ -25,6 +25,9 @@ namespace Surging.Core.ProxyGenerator.Implementation { + /// + /// 服务代理生成器 + /// public class ServiceProxyGenerater : IServiceProxyGenerater,IDisposable { #region Field diff --git a/src/Surging.Core/Surging.Core.ProxyGenerator/Implementation/ServiceProxyProvider.cs b/src/Surging.Core/Surging.Core.ProxyGenerator/Implementation/ServiceProxyProvider.cs index daa7d6c95..86240a0f5 100644 --- a/src/Surging.Core/Surging.Core.ProxyGenerator/Implementation/ServiceProxyProvider.cs +++ b/src/Surging.Core/Surging.Core.ProxyGenerator/Implementation/ServiceProxyProvider.cs @@ -6,6 +6,9 @@ namespace Surging.Core.ProxyGenerator.Implementation { + /// + /// 服务代理提供者,通过RoutePath调用服务时使用 + /// public class ServiceProxyProvider : IServiceProxyProvider { private readonly IServiceRouteProvider _serviceRouteProvider;