Pārlūkot izejas kodu

提交TEAMModelOS.Grpc模块

CrazyIter 5 gadi atpakaļ
vecāks
revīzija
2d9ae60503

+ 27 - 0
TEAMModelOS.Grpc/Program.cs

@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.Extensions.Hosting;
+
+namespace TEAMModelOS.Grpc
+{
+    public class Program
+    {
+        public static void Main(string[] args)
+        {
+            CreateHostBuilder(args).Build().Run();
+        }
+
+        // Additional configuration is required to successfully run gRPC on macOS.
+        // For instructions on how to configure Kestrel and gRPC clients on macOS, visit https://go.microsoft.com/fwlink/?linkid=2099682
+        public static IHostBuilder CreateHostBuilder(string[] args) =>
+            Host.CreateDefaultBuilder(args)
+                .ConfigureWebHostDefaults(webBuilder =>
+                {
+                    webBuilder.UseStartup<Startup>();
+                });
+    }
+}

+ 12 - 0
TEAMModelOS.Grpc/Properties/launchSettings.json

@@ -0,0 +1,12 @@
+{
+  "profiles": {
+    "TEAMModelOS.Grpc": {
+      "commandName": "Project",
+      "launchBrowser": false,
+      "applicationUrl": "https://localhost:5001",
+      "environmentVariables": {
+        "ASPNETCORE_ENVIRONMENT": "Development"
+      }
+    }
+  }
+}

+ 21 - 0
TEAMModelOS.Grpc/Protos/greet.proto

@@ -0,0 +1,21 @@
+syntax = "proto3";
+
+option csharp_namespace = "TEAMModelOS.Grpc";
+
+package greet;
+
+// The greeting service definition.
+service Greeter {
+  // Sends a greeting
+  rpc SayHello (HelloRequest) returns (HelloReply);
+}
+
+// The request message containing the user's name.
+message HelloRequest {
+  string name = 1;
+}
+
+// The response message containing the greetings.
+message HelloReply {
+  string message = 1;
+}

+ 26 - 0
TEAMModelOS.Grpc/Services/GreeterService.cs

@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Grpc.Core;
+using Microsoft.Extensions.Logging;
+
+namespace TEAMModelOS.Grpc
+{
+    public class GreeterService : Greeter.GreeterBase
+    {
+        private readonly ILogger<GreeterService> _logger;
+        public GreeterService(ILogger<GreeterService> logger)
+        {
+            _logger = logger;
+        }
+
+        public override Task<HelloReply> SayHello(HelloRequest request, ServerCallContext context)
+        {
+            return Task.FromResult(new HelloReply
+            {
+                Message = "Hello " + request.Name
+            });
+        }
+    }
+}

+ 43 - 0
TEAMModelOS.Grpc/Startup.cs

@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.AspNetCore.Http;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
+
+namespace TEAMModelOS.Grpc
+{
+    public class Startup
+    {
+        // This method gets called by the runtime. Use this method to add services to the container.
+        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
+        public void ConfigureServices(IServiceCollection services)
+        {
+            services.AddGrpc();
+        }
+
+        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
+        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
+        {
+            if (env.IsDevelopment())
+            {
+                app.UseDeveloperExceptionPage();
+            }
+
+            app.UseRouting();
+
+            app.UseEndpoints(endpoints =>
+            {
+                endpoints.MapGrpcService<GreeterService>();
+
+                endpoints.MapGet("/", async context =>
+                {
+                    await context.Response.WriteAsync("Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");
+                });
+            });
+        }
+    }
+}

+ 23 - 0
TEAMModelOS.Grpc/TEAMModelOS.Grpc.csproj

@@ -0,0 +1,23 @@
+<Project Sdk="Microsoft.NET.Sdk.Web">
+
+  <PropertyGroup>
+    <TargetFramework>netcoreapp3.1</TargetFramework>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <Protobuf Include="Protos\greet.proto" GrpcServices="Server" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Grpc.AspNetCore" Version="2.27.0" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <Folder Include="Services\Core\" />
+    <Folder Include="Services\Courses\" />
+    <Folder Include="Services\Exam\" />
+    <Folder Include="Services\Learn\" />
+    <Folder Include="Services\Syllabus\" />
+  </ItemGroup>
+
+</Project>

+ 10 - 0
TEAMModelOS.Grpc/appsettings.Development.json

@@ -0,0 +1,10 @@
+{
+  "Logging": {
+    "LogLevel": {
+      "Default": "Debug",
+      "System": "Information",
+      "Grpc": "Information",
+      "Microsoft": "Information"
+    }
+  }
+}

+ 15 - 0
TEAMModelOS.Grpc/appsettings.json

@@ -0,0 +1,15 @@
+{
+  "Logging": {
+    "LogLevel": {
+      "Default": "Information",
+      "Microsoft": "Warning",
+      "Microsoft.Hosting.Lifetime": "Information"
+    }
+  },
+  "AllowedHosts": "*",
+  "Kestrel": {
+    "EndpointDefaults": {
+      "Protocols": "Http2"
+    }
+  }
+}

+ 2 - 2
TEAMModelOS.SDK/TEAMModelOS.SDK.csproj

@@ -13,8 +13,8 @@
     <PackageReference Include="ClouDASLibx" Version="1.1.4" />
     <PackageReference Include="Consul" Version="0.7.2.6" />
     <PackageReference Include="DocumentFormat.OpenXml" Version="2.10.1" />
-    <PackageReference Include="Grpc.AspNetCore.Server" Version="2.24.0" />
-    <PackageReference Include="Grpc.Core" Version="2.24.0" />
+    <PackageReference Include="Grpc.AspNetCore.Server" Version="2.27.0" />
+    <PackageReference Include="Grpc.Core" Version="2.27.0" />
     <PackageReference Include="HtmlAgilityPack" Version="1.11.23" />
     <PackageReference Include="IdentityModel" Version="4.2.0" />
     <PackageReference Include="Jaeger" Version="0.3.7" />

+ 6 - 0
TEAMModelOS.sln

@@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TEAMModelOS", "TEAMModelOS\
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TEAMModelOS.Service", "TEAMModelOS.Service\TEAMModelOS.Service.csproj", "{04508AB6-CD54-46B4-B96D-9672EB66761B}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TEAMModelOS.Grpc", "TEAMModelOS.Grpc\TEAMModelOS.Grpc.csproj", "{F74318E4-3FD9-4011-A4CE-07A1B576AC3D}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -27,6 +29,10 @@ Global
 		{04508AB6-CD54-46B4-B96D-9672EB66761B}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{04508AB6-CD54-46B4-B96D-9672EB66761B}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{04508AB6-CD54-46B4-B96D-9672EB66761B}.Release|Any CPU.Build.0 = Release|Any CPU
+		{F74318E4-3FD9-4011-A4CE-07A1B576AC3D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{F74318E4-3FD9-4011-A4CE-07A1B576AC3D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{F74318E4-3FD9-4011-A4CE-07A1B576AC3D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{F74318E4-3FD9-4011-A4CE-07A1B576AC3D}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE