nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
67.29k stars 7.59k forks source link

gRPC deadline setting (add options) #1366

Closed jnst closed 2 years ago

jnst commented 5 years ago

I'm submitting a...


[ ] Regression
[ ] Bug report
[x] Feature request
[x] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

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.  

jnst commented 5 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);
      });
    });
  }
}
dariodavi commented 4 years ago

hi there, any news?

ssilve1989 commented 3 years ago

Would also like to see this available

kamilmysliwiec commented 2 years ago

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.