-
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 #13 from yileicn/grpc/reflection
Grpc/reflection
- Loading branch information
Showing
24 changed files
with
3,766 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# 使用两种方法对接DashBoard | ||
## 方法1:实现FMGrpcExtensions.proto协议 | ||
### dotnet对接GrpcDashBoard | ||
使用FM.Grpc.Extensions或者FM.Droplet | ||
|
||
### 其它语言对接GrpcDashBoard | ||
需要自己实现FMGrpcExtensions.proto协议 | ||
|
||
## 方法2:使用GrpcReflection | ||
### dotnet对接GrpcDashBoard | ||
netcore1.x-2.x | ||
https://github.com/grpc/grpc/blob/master/doc/csharp/server_reflection.md | ||
netcore3.x-5.x | ||
https://docs.microsoft.com/en-us/aspnet/core/grpc/test-tools?view=aspnetcore-3.0 | ||
|
||
### java对接GrpcDashBoard | ||
https://github.com/grpc/grpc-java/blob/master/documentation/server-reflection-tutorial.md | ||
|
||
### golang对接GrpcDashBoard | ||
https://github.com/grpc/grpc-go/blob/master/Documentation/server-reflection-tutorial.md | ||
|
||
### python对接GrpcDashBoard | ||
https://github.com/grpc/grpc/blob/master/doc/python/server_reflection.md |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
FROM microsoft/aspnetcore:2.0.0 | ||
WORKDIR /app | ||
COPY ./ /app | ||
COPY ./ /app | ||
COPY ./grpcurl /usr/bin/ | ||
ENTRYPOINT ["dotnet", "FM.GrpcDashboard.dll"] |
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,34 @@ | ||
#sln init | ||
PROJECT = FM.GrpcDashboard | ||
SOLUTION_NAME = ${PROJECT_NAME}.sln | ||
|
||
#service build | ||
SRV_NAME = cs-grpc_dashboard-web | ||
CURRENT_VERSION := `head -1 CHANGELOG ` | ||
TIME = $(shell date +%y%m%d%H%M) | ||
|
||
SRV_FULL_NAME := $(SRV_NAME):$(CURRENT_VERSION).$(TIME) | ||
|
||
build:clean | ||
dotnet publish ./src/$(PROJECT)/$(PROJECT).csproj -c Release -o ./dist | ||
|
||
clean: | ||
rm -rf dist/ | ||
|
||
# 仅编译镜像,不推 | ||
build-image:build | ||
cp Dockerfile ./dist/Dockerfile | ||
docker build -f ./dist/Dockerfile --no-cache --rm -t $(SRV_FULL_NAME) ./dist | ||
|
||
# 发布项目 | ||
publish:build-image | ||
docker tag $(SRV_FULL_NAME) $(DH_URL)$(SRV_FULL_NAME) | ||
docker login -u $(DH_USER) -p $(DH_PASS) $(DH_URL) && docker push $(DH_URL)$(SRV_FULL_NAME) | ||
|
||
test: | ||
echo $(DH_USER) | ||
echo $(DH_PASS) | ||
echo $(DH_URL) | ||
|
||
.PHONY: gen build build-image publish clean test | ||
|
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
41 changes: 41 additions & 0 deletions
41
src/FM.GrpcDashboard/src/FM.GrpcDashboard/Common/ProtobufSerialization.cs
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,41 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
using ProtoBuf; | ||
|
||
namespace System | ||
{ | ||
/// <summary> | ||
/// ProtobufExtensions | ||
/// </summary> | ||
public class ProtobufExtensions | ||
{ | ||
/// <summary> | ||
/// 序列化 | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <param name="input"></param> | ||
/// <returns></returns> | ||
public static byte[] Serialize<T>(T input) | ||
{ | ||
using (MemoryStream memoryStream = new MemoryStream()) | ||
{ | ||
Serializer.Serialize<T>((Stream)memoryStream, input); | ||
return memoryStream.ToArray(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// 反序列化 | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <param name="data"></param> | ||
/// <returns></returns> | ||
public static T Deserialize<T>(byte[] data) | ||
{ | ||
using (MemoryStream memoryStream = new MemoryStream(data)) | ||
return Serializer.Deserialize<T>((Stream)memoryStream); | ||
} | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
src/FM.GrpcDashboard/src/FM.GrpcDashboard/Common/ShellHelper.cs
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,75 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
|
||
namespace System | ||
{ | ||
public static class ShellHelper | ||
{ | ||
public static string Bash(this string cmd) | ||
{ | ||
var escapedArgs = cmd.Replace("\"", "\\\""); | ||
|
||
var process = new Process() | ||
{ | ||
StartInfo = new ProcessStartInfo | ||
{ | ||
FileName = "bash", | ||
Arguments = $"-c \"{escapedArgs}\" 2>&1", | ||
RedirectStandardOutput = true, | ||
RedirectStandardError = true, | ||
UseShellExecute = false, | ||
CreateNoWindow = true, | ||
} | ||
}; | ||
process.Start(); | ||
string result = process.StandardOutput.ReadToEnd(); | ||
string error = process.StandardError.ReadToEnd(); | ||
|
||
process.WaitForExit(); | ||
return !string.IsNullOrWhiteSpace(result) ? result : error; | ||
} | ||
|
||
public static string Cmd(this string cmd) | ||
{ | ||
var escapedArgs = cmd.Replace("\"", "\\\""); | ||
|
||
var process = new Process() | ||
{ | ||
StartInfo = new ProcessStartInfo | ||
{ | ||
FileName = "cmd", | ||
Arguments = $"/c \"{escapedArgs}\" 2>&1", | ||
RedirectStandardOutput = true, | ||
UseShellExecute = false, | ||
CreateNoWindow = true, | ||
} | ||
}; | ||
process.Start(); | ||
string result = process.StandardOutput.ReadToEnd(); | ||
|
||
process.WaitForExit(); | ||
return result; | ||
} | ||
|
||
public static string Execute(this string exeFileName, string arguments) | ||
{ | ||
var process = new Process() | ||
{ | ||
StartInfo = new ProcessStartInfo | ||
{ | ||
FileName = exeFileName, | ||
Arguments = arguments, | ||
RedirectStandardOutput = true, | ||
UseShellExecute = false, | ||
CreateNoWindow = true, | ||
} | ||
}; | ||
process.Start(); | ||
string result = process.StandardOutput.ReadToEnd(); | ||
process.WaitForExit(); | ||
return result; | ||
} | ||
} | ||
} |
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
67 changes: 67 additions & 0 deletions
67
src/FM.GrpcDashboard/src/FM.GrpcDashboard/GrpcClient/FMGrpcExtensions.proto
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,67 @@ | ||
syntax = "proto3"; | ||
option csharp_namespace = "Grpc"; | ||
package grpc; | ||
|
||
|
||
service BaseService { | ||
//服务基本信息(方法列表) | ||
rpc Info(InfoRQ) returns(InfoRS); | ||
//服务方法的详细信息 | ||
rpc MethodInfo(MethodInfoRQ) returns(MethodInfoRS); | ||
//服务方法调用 | ||
rpc MethodInvoke(MethodInvokeRQ) returns(MethodInvokeRS); | ||
|
||
//添加删除截流的method | ||
rpc AddDelThrottle(AddDelThrottleRQ) returns(CmdRS); | ||
//添加删除是否允许保存响应的method | ||
rpc AddDelSaveResponseEnable(AddDelSaveResponseEnableRQ) returns(CmdRS); | ||
} | ||
|
||
message AddDelThrottleRQ { | ||
string MethodName = 1; | ||
bool IsDel = 2; | ||
} | ||
|
||
message AddDelSaveResponseEnableRQ { | ||
string MethodName = 1; | ||
bool IsDel = 2; | ||
} | ||
|
||
message InfoRQ { | ||
string MethodName = 1; | ||
} | ||
|
||
message MethodInfoRQ { | ||
string FullName = 1; | ||
} | ||
|
||
message MethodInvokeRQ { | ||
string FullName = 1; | ||
string RequestJson = 2; | ||
} | ||
|
||
message CmdRS { | ||
bool Result = 1; | ||
string Message = 2; | ||
} | ||
|
||
message InfoRS { | ||
string IpAndPort = 1; | ||
int64 StartTime = 2; | ||
repeated MethodInfo MethodInfos = 3; | ||
} | ||
|
||
message MethodInfo { | ||
bool IsThrottled = 1; | ||
string Name = 2; | ||
bool SaveResponseEnable = 3; | ||
} | ||
|
||
message MethodInfoRS { | ||
string RequestJson = 1; | ||
string ResponseJson = 2; | ||
} | ||
|
||
message MethodInvokeRS { | ||
string ResponseJson = 1; | ||
} |
Oops, something went wrong.