ASPNET/Grpc
gRPC - Configuration
yogingang
2022. 5. 23. 00:00
반응형
Server 옵션 정의
Startup.ConfigureServices에서 AddGrpc 호출에 옵션 대리자를 제공하여
모든 서비스에 대해 옵션을 구성할 수 있습니다.
...
builder.Services.AddGrpc(options =>
{
options.EnableDetailedErrors = true;
options.MaxReceiveMessageSize = 2 * 1024 * 1024; // 2 MB
options.MaxSendMessageSize = 5 * 1024 * 1024; // 5 MB
});
...
단일서비스에 옵션 적용하기
// 단일 서비스에 옵션 적용하기
builder.Services.AddGrpc().AddServiceOptions<GreeterService>(options =>
{
options.MaxReceiveMessageSize = 2 * 1024 * 1024; // 2 MB
options.MaxSendMessageSize = 5 * 1024 * 1024; // 5 MB
});
인터셉터는 기본적으로 Transient 형태의 lifetime 을 가지고 있다.
다음과 같이 수명을 재정의 할 수 있다.
// 인터셉터 수명 재정의
builder.Services.AddGrpc(options =>
{
options.Interceptors.Add<LoggingInterceptor>();
});
services.AddSingleton<LoggingInterceptor>();
Client 옵션 정의
채널의 최대 송심 및 수신 메시지 크기 설정
// 채널의 최대 송신 및 수신 메시지 크기 설정
var channel = GrpcChannel.ForAddress("https://localhost:7253", new GrpcChannelOptions
{
MaxReceiveMessageSize = 5 * 1024 * 1024, // 5 MB
MaxSendMessageSize = 2 * 1024 * 1024 // 2 MB
});
인터셉터 설정
...
var callInvoker = channel.Intercept(new LoggingInterceptor());
var client = new Greeter.GreeterClient(callInvoker);
...
관련영상
반응형