Skip to content

Commit

Permalink
Merge pull request #5 from yileicn/feature/aspnetcore3.0
Browse files Browse the repository at this point in the history
Feature/aspnetcore3.0
  • Loading branch information
yileicn authored Apr 30, 2020
2 parents 4382238 + 77b2d14 commit b97ace8
Show file tree
Hide file tree
Showing 17 changed files with 131 additions and 8 deletions.
9 changes: 8 additions & 1 deletion Grpc.Extensions.sln
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Grpc.Extension.AspNetCore",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MathServer.AspNetCore", "examples\CodeFirst\MathServer.AspNetCore\MathServer.AspNetCore.csproj", "{CF0443B5-DC32-4C80-B80E-A3F8D6E1792B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GreeterClientTest", "examples\Greeter\GreeterClientTest\GreeterClientTest.csproj", "{ACCF4597-3748-4117-8633-1CB767F8CCC3}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GreeterClientHost", "examples\Greeter\GreeterClientHost\GreeterClientHost.csproj", "{ACCF4597-3748-4117-8633-1CB767F8CCC3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GreeterClient", "examples\Greeter\GreeterClient\GreeterClient.csproj", "{724DFC8C-4B57-4C3F-811C-0463BE2A2829}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AspNetCore3.0", "AspNetCore3.0", "{291086F1-5608-46C9-9976-BD969B8C8256}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MathClientHost", "examples\CodeFirst\MathClientHost\MathClientHost.csproj", "{5B3DC8DC-AC90-4BF2-9E1C-DE46F9782160}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -103,6 +105,10 @@ Global
{724DFC8C-4B57-4C3F-811C-0463BE2A2829}.Debug|Any CPU.Build.0 = Debug|Any CPU
{724DFC8C-4B57-4C3F-811C-0463BE2A2829}.Release|Any CPU.ActiveCfg = Release|Any CPU
{724DFC8C-4B57-4C3F-811C-0463BE2A2829}.Release|Any CPU.Build.0 = Release|Any CPU
{5B3DC8DC-AC90-4BF2-9E1C-DE46F9782160}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5B3DC8DC-AC90-4BF2-9E1C-DE46F9782160}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5B3DC8DC-AC90-4BF2-9E1C-DE46F9782160}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5B3DC8DC-AC90-4BF2-9E1C-DE46F9782160}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -119,6 +125,7 @@ Global
{CF0443B5-DC32-4C80-B80E-A3F8D6E1792B} = {BE41EB1C-CB4F-4EDD-9E47-17D54308B014}
{ACCF4597-3748-4117-8633-1CB767F8CCC3} = {94B12F76-D786-4D94-A9F4-8DD7DD73685F}
{724DFC8C-4B57-4C3F-811C-0463BE2A2829} = {94B12F76-D786-4D94-A9F4-8DD7DD73685F}
{5B3DC8DC-AC90-4BF2-9E1C-DE46F9782160} = {BE41EB1C-CB4F-4EDD-9E47-17D54308B014}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {89FBBEF6-DF3C-43D4-BD32-075D5E3D14F2}
Expand Down
25 changes: 25 additions & 0 deletions examples/CodeFirst/MathClientHost/MathClientHost.csproj
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>
68 changes: 68 additions & 0 deletions examples/CodeFirst/MathClientHost/Program.cs
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);
}
}
}
17 changes: 17 additions & 0 deletions examples/CodeFirst/MathClientHost/config/appsettings.json
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
}
}
}
3 changes: 3 additions & 0 deletions examples/Greeter/GreeterClientHost/config/hostsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"environment": "Development"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<Version>1.4.5</Version>
<PackageId>Grpc.Extensions.AspNetCore</PackageId>
<Version>1.4.6</Version>
<PackageId>FM.Grpc.Extensions.AspNetCore</PackageId>
<Authors>RabbitYi</Authors>
<Description>一个基于GRPC的简单微服务框架
1.服务注册和发现
Expand Down
4 changes: 3 additions & 1 deletion src/Grpc.Extension.Client/Grpc.Extension.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
5.DashBoard(远程调用,手动熔断,日志输出控制)
6.Grpc CodeFirst</Description>
<Company />
<Version>1.4.5</Version>
<Version>1.4.6</Version>
<RepositoryType>git</RepositoryType>
<PackageTags>grpc,dashboard,consul,micorservice,opentracing,polly</PackageTags>
<RepositoryUrl>https://github.com/yileicn/Grpc.Extensions/</RepositoryUrl>
<AssemblyVersion>1.4.6.0</AssemblyVersion>
<FileVersion>1.4.6.0</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
3 changes: 2 additions & 1 deletion src/Grpc.Extension.Client/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public static class ServiceCollectionExtensions
public static IServiceCollection AddGrpcClientExtensions(this IServiceCollection services, IConfiguration conf)
{
//注入配制
services.Configure<GrpcClientOptions>(conf.GetSection("GrpcClient"));
var key = conf["GrpcServer:ServiceAddress"] != null ? "GrpcServer" : "GrpcClient";
services.Configure<GrpcClientOptions>(conf.GetSection(key));
//GrpcClientApp
services.AddSingleton<GrpcClientApp>();
//添加客户端中间件的CallInvoker
Expand Down
6 changes: 3 additions & 3 deletions src/Grpc.Extension/Grpc.Extension.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>1.4.5</Version>
<Version>1.4.6</Version>
<Description>一个基于GRPC的简单微服务框架
1.服务注册和发现
2.服务自动负载均衡
Expand All @@ -16,8 +16,8 @@
<Product>Grpc.Extensions</Product>
<Company></Company>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<AssemblyVersion>1.4.1.0</AssemblyVersion>
<FileVersion>1.4.1.0</FileVersion>
<AssemblyVersion>1.4.6.0</AssemblyVersion>
<FileVersion>1.4.6.0</FileVersion>
<RepositoryType>git</RepositoryType>
<PackageTags>grpc,dashboard,consul,micorservice,opentracing,polly</PackageTags>
<PackageProjectUrl>https://github.com/yileicn/Grpc.Extensions/</PackageProjectUrl>
Expand Down

0 comments on commit b97ace8

Please sign in to comment.