diff --git a/src/JT808.DotNetty.Admin/JT808.DotNetty.Dashbord.GrpcServer/GrpcImpls/JT808AtomicCounterServiceGrpcImpl.cs b/src/JT808.DotNetty.Admin/JT808.DotNetty.Dashbord.GrpcServer/GrpcImpls/JT808AtomicCounterServiceGrpcImpl.cs new file mode 100644 index 0000000..4e42c6e --- /dev/null +++ b/src/JT808.DotNetty.Admin/JT808.DotNetty.Dashbord.GrpcServer/GrpcImpls/JT808AtomicCounterServiceGrpcImpl.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using Grpc.Core; +using JT808.GrpcDashbord.AtomicCounterGrpcService; +using JT808.GrpcDashbord.ServiceGrpcBase; +using static JT808.GrpcDashbord.AtomicCounterGrpcService.AtomicCounterService; + +namespace JT808.DotNetty.Dashbord.GrpcServer.GrpcImpls +{ + public class JT808AtomicCounterServiceGrpcImpl: AtomicCounterServiceBase + { + public override Task GetTcpAtomicCounter(EmptyRequest request, ServerCallContext context) + { + AtomicCounterReply atomicCounterReply = new AtomicCounterReply(); + atomicCounterReply.AtomicCounterInfo = new AtomicCounterInfo + { + MsgFailCount = 10, + MsgSuccessCount = 11111 + }; + atomicCounterReply.ResultReply = new ResultReply + { + Code = ResultReply.Types.StatusCode.Success, + }; + return Task.FromResult(atomicCounterReply); + } + + public override Task GetUdpAtomicCounter(EmptyRequest request, ServerCallContext context) + { + AtomicCounterReply atomicCounterReply = new AtomicCounterReply(); + atomicCounterReply.AtomicCounterInfo = new AtomicCounterInfo + { + MsgFailCount = 50, + MsgSuccessCount = 10000 + }; + atomicCounterReply.ResultReply = new ResultReply + { + Code = ResultReply.Types.StatusCode.Success, + }; + return Task.FromResult(atomicCounterReply); + } + } +} diff --git a/src/JT808.DotNetty.Admin/JT808.DotNetty.Dashbord.GrpcServer/JT808.DotNetty.Dashbord.GrpcServer.csproj b/src/JT808.DotNetty.Admin/JT808.DotNetty.Dashbord.GrpcServer/JT808.DotNetty.Dashbord.GrpcServer.csproj new file mode 100644 index 0000000..007d2c7 --- /dev/null +++ b/src/JT808.DotNetty.Admin/JT808.DotNetty.Dashbord.GrpcServer/JT808.DotNetty.Dashbord.GrpcServer.csproj @@ -0,0 +1,12 @@ + + + + Exe + netcoreapp2.2 + + + + + + + diff --git a/src/JT808.DotNetty.Admin/JT808.DotNetty.Dashbord.GrpcServer/Program.cs b/src/JT808.DotNetty.Admin/JT808.DotNetty.Dashbord.GrpcServer/Program.cs new file mode 100644 index 0000000..a571b5d --- /dev/null +++ b/src/JT808.DotNetty.Admin/JT808.DotNetty.Dashbord.GrpcServer/Program.cs @@ -0,0 +1,36 @@ +using Grpc.Core; +using JT808.DotNetty.Dashbord.GrpcServer.GrpcImpls; +using JT808.GrpcDashbord.AtomicCounterGrpcService; +using System; +using System.Threading; +using static JT808.GrpcDashbord.AtomicCounterGrpcService.AtomicCounterService; + +namespace JT808.DotNetty.Dashbord.GrpcServer +{ + class Program + { + static void Main(string[] args) + { + var server = new Server + { + Services = { + BindService(new JT808AtomicCounterServiceGrpcImpl()), + }, + Ports = { + new ServerPort("0.0.0.0", 14000,ServerCredentials.Insecure) + } + }; + Console.WriteLine("Google Grpc Starting"); + foreach (var item in server.Ports) + { + Console.WriteLine(string.Format("RPC server {0} listening on port {1}", item.Host, item.Port)); + } + server.Start(); + + AtomicCounterServiceClient client = new AtomicCounterServiceClient(new Channel("127.0.0.1:14000", ChannelCredentials.Insecure)); + var result=client.GetTcpAtomicCounter(new GrpcDashbord.ServiceGrpcBase.EmptyRequest()); + Console.ReadKey(); + server.ShutdownAsync().Wait(); + } + } +} diff --git a/src/JT808.DotNetty.Dashbord.sln b/src/JT808.DotNetty.Dashbord.sln index 504cf31..191353c 100644 --- a/src/JT808.DotNetty.Dashbord.sln +++ b/src/JT808.DotNetty.Dashbord.sln @@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT808.DotNetty.Dashbord.Grp EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT808.DotNetty.Dashbord", "JT808.DotNetty.Admin\JT808.DotNetty.Dashbord\JT808.DotNetty.Dashbord.csproj", "{80D1505D-44E1-4128-8900-B5C0AE7C69E5}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JT808.DotNetty.Dashbord.GrpcServer", "JT808.DotNetty.Admin\JT808.DotNetty.Dashbord.GrpcServer\JT808.DotNetty.Dashbord.GrpcServer.csproj", "{9F143F03-D90D-477F-9CE4-0BD1E2A1E379}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -35,6 +37,10 @@ Global {80D1505D-44E1-4128-8900-B5C0AE7C69E5}.Debug|Any CPU.Build.0 = Debug|Any CPU {80D1505D-44E1-4128-8900-B5C0AE7C69E5}.Release|Any CPU.ActiveCfg = Release|Any CPU {80D1505D-44E1-4128-8900-B5C0AE7C69E5}.Release|Any CPU.Build.0 = Release|Any CPU + {9F143F03-D90D-477F-9CE4-0BD1E2A1E379}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9F143F03-D90D-477F-9CE4-0BD1E2A1E379}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9F143F03-D90D-477F-9CE4-0BD1E2A1E379}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9F143F03-D90D-477F-9CE4-0BD1E2A1E379}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE