-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from yileicn/feature/aspnetcore3.0
Feature/aspnetcore3.0
- Loading branch information
Showing
17 changed files
with
131 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.2.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\src\Grpc.Extension.Client\Grpc.Extension.Client.csproj" /> | ||
<ProjectReference Include="..\MathClient\MathClient.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="config\appsettings.json"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using Grpc.Extension.Client; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using System; | ||
using System.IO; | ||
using static MathGrpc.MathGrpc; | ||
using Grpc.Extension.Abstract.Model; | ||
|
||
namespace MathClientTest | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
//使用配制文件 | ||
var configPath = Path.Combine(AppContext.BaseDirectory, "config"); | ||
var host = new HostBuilder() | ||
.ConfigureAppConfiguration((ctx, conf) => | ||
{ | ||
conf.SetBasePath(configPath); | ||
conf.AddJsonFile("appsettings.json", false, true); | ||
}) | ||
.ConfigureServices((ctx, services)=> { | ||
services.AddGrpcClientExtensions(ctx.Configuration);//注入GrpcClientExtensions | ||
services.AddGrpcClient<MathGrpcClient>("Math.Test");//注入grpc client | ||
}) | ||
.Build(); | ||
|
||
var provider = host.Services; | ||
//配制GrpcClientApp | ||
var clientApp = provider.GetService<GrpcClientApp>(); | ||
clientApp. | ||
//使用日志(默认使用LoggerFactory) | ||
UseLogger((log) => | ||
{ | ||
log.LoggerMonitor += (msg, type) => Console.WriteLine(GetLogTypeName(type) + ":" + msg); | ||
log.LoggerError += (ex, type) => Console.WriteLine(GetLogTypeName(type) + ":" + ex); | ||
}).Run(); | ||
|
||
//从容器获取client | ||
var client = provider.GetService<MathGrpcClient>(); | ||
|
||
Console.WriteLine("start:"); | ||
try | ||
{ | ||
for (int i = 0; i < 10; i++) | ||
{ | ||
var reply = client.Add(new MathGrpc.AddRequest() { Num1 = 1, Num2 = i}); | ||
Console.WriteLine($"Add {i.ToString()}: {reply.Value}"); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(ex); | ||
} | ||
|
||
|
||
Console.WriteLine("Press any key to exit..."); | ||
Console.ReadKey(); | ||
} | ||
|
||
private static string GetLogTypeName(LogType logtype) | ||
{ | ||
return Enum.GetName(typeof(LogType), logtype); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"GrpcClient": { | ||
//服务发现服务器地址 | ||
"DiscoveryUrl": "http://192.168.8.6:8500", | ||
//服务地址缓存时间(秒) | ||
"ServiceAddressCacheTime": 10, | ||
//默认的错误码 | ||
"DefaultErrorCode": 4200000, | ||
//Jaeger配制(OpenTracing) | ||
"Jaeger": { | ||
//Jaeger上的服务名 | ||
"ServiceName": "MathClient", | ||
"AgentIp": "192.168.8.11", | ||
"AgentPort": 5775 | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"environment": "Development" | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters