I've set up a nestjs server that handles gRPC requests. In order to do some ad-hoc debugging, I'm trying to use postman. However, whenever I try to send a request, postman returns the following error: Received RST_STREAM with code 2 triggered by internal client error: Protocol error.
This is my app.controller.ts file:
import { Metadata, ServerUnaryCall } from '@grpc/grpc-js';
import { Controller } from '@nestjs/common';
import { GrpcMethod } from '@nestjs/microservices';
import { BaseLoggingService } from './common/baseLogging.service';
import { CreateLogRequest, CreateLogResponse } from './generated/logs';
@Controller()
export class AppController {
constructor(private baseLoggingService: BaseLoggingService) {}
@GrpcMethod('LogService', 'CreateLog')
async createLog(
req: CreateLogRequest,
metadata: Metadata,
call: ServerUnaryCall<CreateLogRequest, CreateLogResponse>,
): Promise<CreateLogResponse> {
return await this.baseLoggingService.createLog(req);
}
}
The interfaces CreateLogRequest and CreateLogResponse are generated by protobuf-ts/plugin, and are based on the following .proto file:
/**
* Definitions of shared interfaces
**/
syntax = "proto3";
package logs;
enum LogLevel {
INFO = 0;
WARN = 1;
ERROR = 2;
DEBUG = 3;
}
message LogContext {
string sessionId = 1;
string requestId = 2;
string hostname = 3;
string podName = 4;
string grpcMethodName = 5;
uint32 durationMs = 6;
}
message ErrorData {
string name = 1;
string notificationCode = 2;
string stack = 3;
}
message CreateLogRequest {
LogLevel level = 1;
string service = 2;
int32 timestamp = 3;
string message = 4;
LogContext context = 5;
ErrorData errorData = 6;
}
message CreateLogResponse {
LogLevel level = 1;
string service = 2;
int32 code = 3;
}
service LogService {
rpc CreateLog (CreateLogRequest) returns (CreateLogResponse) {}
}
The server instance is running on a remote machine, so I am using ssh-tunneling to send the requests. Here is the postman request and response. There is no authentication in place.
I used server logs and the controller's createLog function does not get triggered at all when making the request. I even tried using grpcurl, which fails again, albeit for a differently inexplicable reason:
grpcurl -plaintext -d '{
"context": {
"durationMs": 4100079420,
"grpcMethodName": "magna ut commodo",
"hostname": "exercitation dolor",
"podName": "ad Duis non",
"requestId": "do",
"sessionId": "nostrud"
},
"errorData": {
"name": "nostrud enim Lorem consectetur",
"notificationCode": "in anim",
"stack": "incididunt"
},
"level": 0,
"message": "eu qui dolore laborum eiusmod",
"service": "sunt",
"timestamp": -499959849
}' localhost:6666 LogService/CreateLog
Failed to dial target host "localhost:6666": context deadline exceeded
