njs icon indicating copy to clipboard operation
njs copied to clipboard

use gRPC client like ngx.fetch without subrequest

Open ivanitskiy opened this issue 1 year ago • 3 comments

It would be beneficial to create a gRPC client in NJS similar ngx.fetch in the context of using it js_content or js_periodic to communicate with the external world. A reference to LUA experimental capabilities: https://github.com/api7/grpc-client-nginx-module/blob/main/README.md

Here is an example of a node code using a gRPC client: https://github.com/grpc/grpc-node/blob/%40grpc/grpc-js%401.9.0/examples/helloworld/dynamic_codegen/greeter_client.js

ivanitskiy avatar Sep 15 '23 21:09 ivanitskiy

@ivanitskiy

    local gcli = require("resty.grpc")
    assert(gcli.load("t/testdata/rpc.proto"))

It looks like it will parse a proto file on every request. I think, better to use something like pbjs

drsm avatar Sep 15 '23 22:09 drsm

@ivanitskiy

    local gcli = require("resty.grpc")
    assert(gcli.load("t/testdata/rpc.proto"))

It looks like it will parse a proto file on every request. I think, better to use something like pbjs

i'm not suggesting the exact thing, this is just a reference to the JS tutorial guide from gRPC project

ivanitskiy avatar Sep 15 '23 22:09 ivanitskiy

I've been trying to do some experiences with pbjs and njs as well, but IMHO the way to get it working is too complex (a lot of steps prone to errors, browserfy the js, etc).

Also I wasn't able (my fault 99% sure) to make something useful like a simple grpc client, generating the frame and calling via subrequest a gRPC upstream so having something simpler on njs would be amazing.

I think generating the full js with pbjs is fine, but having something that we can do as simple as possible gRPC calls (or even generating njs compatible js, preloading it and calling the upstream) amazing!

Thanks for the hard work on it, njs is amazing

rikatz avatar Sep 21 '23 02:09 rikatz