Closed jnst closed 2 years ago
Since I can not write practical code unless I can specify deadline, I currently write client code with grpc-tools
generated code without using @client
as below.
syntax = "proto3";
package ranking;
service Ranking {
rpc Get (GetRequest) returns (GetResponse) {}
}
const TIMEOUT = 1000;
@Injectable()
export class RankingGrpc {
constructor(
@Inject(RankingConstant.TOKEN_RANKING_CLIENT) private readonly client: RankingClient,
private readonly logger: AppLogger
) {}
async get(key: string, userId: number): Promise<RankingUser> {
return new Promise<RankingUser>((resolve, _reject) => {
const req = new GetRequest();
req.setKey(key);
req.setId(userId);
const metadata = new grpc.Metadata();
const options: Partial<grpc.CallOptions> = {deadline: DateTime.utc().toMillis() + TIMEOUT};
this.client.get(req, metadata, options, (err: grpc.ServiceError, res: GetResponse) => {
if (err) {
this.logger.error(`[${this.constructor.name}] ${err.message}`);
return resolve(null);
}
resolve(res.toObject().rankingUser);
});
});
}
}
hi there, any news?
Would also like to see this available
Thanks for your suggestion!
There are no plans to implement it in the foreseeable future.
If you think your request could live outside Nest's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.
I'm submitting a...
Minimal reproduction of the problem with instructions
How to set gRPC Deadlines. There is no document in gRPC - Microservices | NestJS and sample code too.
or no feature? I could not find the source code like that.