grpc test - grpcui

2022. 5. 20. 00:00ASPNET/Grpc

반응형

테스트를 하기 전에 해당 Test tool 을 설치 하기 위해 Go language sdk 를 설치 하자

https://go.dev/dl/

 

Downloads - The Go Programming Language

Downloads After downloading a binary release suitable for your system, please follow the installation instructions. If you are building from source, follow the source installation instructions. See the release history for more information about Go releases

go.dev

 

그리고 다음을 설치 하자

https://github.com/fullstorydev/grpcui#installation

 

GitHub - fullstorydev/grpcui: An interactive web UI for gRPC, along the lines of postman

An interactive web UI for gRPC, along the lines of postman - GitHub - fullstorydev/grpcui: An interactive web UI for gRPC, along the lines of postman

github.com

go install github.com/fullstorydev/grpcui/cmd/grpcui@latest

이전에 생성한 Grpc Server With Aspnet 을 열자

https://yogingang.tistory.com/230

서버를 실행 하고 아래 명령을 실행 하자

grpcui localhost:7253

 

 

 

그럼 아래와 같은 화면의 web page 로 자동으로 연결된다. 

Request Data 의 name 을 check 하고 아무 문자열이나 입력하자

아래쪽  Request Timeout. 은 입력하지 않아도 된다. 

 

그후  Invoke 를 누르자

 

 

 

 

 

이를 이용하여 OpenAPI 를 문서화 하고 Test 가능하게 하는 Swagger 의 기능을 대체할 수 있다. 

 

GrpcUI 는 기본적으로 reflection 을 이용하여 grpc server 에서 test 정보를 만들어 낸다. 

 

 

reflection 설정은 다음과 같이 한다. 

 

개발자 명령 프롬프트에서 .csproj 가 있는 폴더로 이동하여 아래를 실행하자

dotnet add package Grpc.AspNetCore.Server.Reflection

 

Program.cs 수정

using GrpcServerWithASPNet.Services;

var builder = WebApplication.CreateBuilder(args);

// 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

// Add services to the container.
builder.Services.AddGrpc();
builder.Services.AddGrpcReflection(); // <--- 추가
builder.Services.AddCors(o => o.AddPolicy("AllowAll", builder =>
{
    builder.AllowAnyOrigin()
           .AllowAnyMethod()
           .AllowAnyHeader()
           .WithExposedHeaders("Grpc-Status", "Grpc-Message", "Grpc-Encoding", "Grpc-Accept-Encoding");
}));

var app = builder.Build();

if(app.Environment.IsDevelopment()) // <--- 추가
    app.MapGrpcReflectionService(); // <--- 추가

// Configure the HTTP request pipeline.
app.MapGrpcService<GreeterService>().RequireCors("AllowAll"); ;
app.MapGet("/", () => "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");

app.Run();

 

** 만약 리플렉션을 지원 하지 않는 서버에서 사용하려면 .proto 파일을 사용하면 된다. 

 

 

관련영상

https://youtu.be/SfbT6al83W0

 

 

반응형

'ASPNET > Grpc' 카테고리의 다른 글

gRPC - JWT Token 을 통한 인증 처리  (16) 2022.05.24
gRPC - Configuration  (0) 2022.05.23
grpc test - grpcurl  (0) 2022.05.19
grpc with aspnet core  (0) 2022.05.18
grpc - console client  (0) 2022.05.17