GithubHelp home page GithubHelp logo

bojand / grpc-caller Goto Github PK

View Code? Open in Web Editor NEW
183.0 183.0 34.0 643 KB

An improved Node.js gRPC client

Home Page: https://bojand.github.io/grpc-caller

License: Apache License 2.0

JavaScript 100.00%
grpc hacktoberfest

grpc-caller's Introduction

Hi there 👋

Just a curious software engineer building things in the ☁️.

grpc-caller's People

Contributors

bojand avatar craigforster avatar dmitrydodzin avatar greenkeeper[bot] avatar phuonghuynh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

grpc-caller's Issues

Requirement on @grpc/grpc-js

The requirement on @grpc/grpc-js is stated in the package file as a devDependancy, but it is used by the application itself (line 1, index.js).

An in-range update of google-protobuf is breaking the build 🚨

Version 3.6.1 of google-protobuf was just published.

Branch Build failing 🚨
Dependency google-protobuf
Current Version 3.6.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

google-protobuf is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Cannot create a caller instance with retry options

Hi,

It says in the README that I can pass a retry options, so I create an caller instance like this:

grpcCaller(
  "some-endpoint",
  "some.proto",
  "SomeService",
  null,
  { retry: { times: 3, interval: 200 } }
);

but it will throw an exception

TypeError: Channel options must be an object with string or number values
at new ChannelImplementation (/workspace/node_modules/@grpc/grpc-js/build/src/channel.js:82:23)
at new Client (/workspace/node_modules/@grpc/grpc-js/build/src/client.js:61:36)
at new ServiceClientImpl (/workspace/node_modules/@grpc/grpc-js/build/src/make-client.js:58:5)
at caller (/workspace/node_modules/grpc-caller/lib/index.js:85:18)

maybe the retry property should be omitted before creating an gRPC caller instance?

Is it a pure js module for grpc?

Hello,

I am new to grpc-caller, just would like to know if it is a pure js module with no need to compile native dependency things?

Thanks a lot.

Best regards, Jason

Error: 2 UNKNOWN: Stream removed

After the grpc-caller runs for a period of time in k8s, it throw error Error: 2 UNKNOWN: Stream removed. When I restart all the grpc-caller pod, the access is normal.

An in-range update of greenkeeper-lockfile is breaking the build 🚨

Version 1.15.1 of greenkeeper-lockfile was just published.

Branch Build failing 🚨
Dependency greenkeeper-lockfile
Current Version 1.15.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

greenkeeper-lockfile is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Release Notes v1.15.1

1.15.1 (2018-05-19)

Bug Fixes

Commits

The new version differs by 1 commits.

  • a89874f fix: force push when amending

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Retries do not support backoff

When calling a service with the retry option, it will immediately make a retry request after the first failure:

if (_.has(options, 'retry')) {
const retryOpts = options.retry
const callOpts = options ? _.omit(options, 'retry') : options
if (_.isFunction(fn)) {
async.retry(retryOpts, rCb => {
v.call(this.client, arg, metadata, callOpts, rCb)
}, fn)
} else {
return new Promise((resolve, reject) => {
async.retry(retryOpts, rCb => {
v.call(this.client, arg, metadata, callOpts, rCb)
}, (err, res) => {
if (err) reject(err)
else resolve(res)
})
})
}

General guidance is to implement backoffs when retrying to prevent overloading the server.

The suggestion is to support a function that returns the amount of time to delay before attempting the retry. This approach would support different approaches to backoffs (constant value, linear, exponential, jitter, no jitter).

Something similar to this:

/**
 * @param {number} requestAttempts Amount of times that the request has been made.
 */
function backoff(requestAttempts) {
  return (requestAttempts * 20);
}

Expose protoLoader options to caller

Summary

In 0.7.0 the default behavior of grpc-caller returned default values and kept case, without conversion to camelCase.

Starting with 0.8.0 these defaults changed, resulting in an empty object (if only defaults were returned from the server), and also introduced the expectation that arguments provided to the client are in camelCase instead of the field name in the message defintion.

For example, user_id is expected to be provided to the client as userId in 0.8.0.

Request

Expose the loadOptions that is declared within the constructor to allow input via arguments, so that the previous behavior can be achieved.
https://github.com/bojand/grpc-caller/blob/master/lib/index.js#L43-L50

Are the examples in the docs supposed to work?

Hi there,

I'm confused how some of these examples are to work:

client.sayHello({ name: 'Bob' })
  .then(res => console.log(res))

I'm using gRPC with protoc, and each of the methods on the original generated client requires a specific message instance. So instead, I'd have to do something like:

const message = new HelloMessage();
message.setName('Bob');
client.sayHello(message)
  .then(res => console.log(res))

Are the examples just supposed to be pseudocode, or is there a way of enabling the nicer syntax that I'm not aware of? Thanks!

Error undefined

When I hit error at client.sayHello() I got undefined err:

try {
 const res = await client.sayHello({ name: 'Bob' })
} catch (err) {
  throw err
}

Anyway of getting what is the error I am hitting?

Question - TypeScript support and type declarations

I'm trying to use this in my TS project but I couldn't find the type declarations. Is TS not supported yet?

In case this isn't already there, I'm willing to do a PR to add type defs. Please let me know. Thanks.

options.retry on the client is not working

I want to define the retries in one place on the client and then all methods should respect the retry number however this is not working as expected. Here is what I am doing:

const caller = require('grpc-caller');

const client = caller(
      host,
      proto,
      name,
      undefined,
      {
        retry: 3, // This number is not respected and retry will default to 5
      },
    );
const getMethod1 = client.Request('GetMethod1', {}).exec();
const getMethod2 = client.Request('GetMethod2', {}).exec();

The only way I found to get rid of this issue is to define the retry on every single method as follow:

const caller = require('grpc-caller');

const client = caller(
      host,
      proto,
      name,
      undefined,
    );
const getMethod1 = client.Request('GetMethod1', {}).withRetry(3).exec();
const getMethod2 = client.Request('GetMethod2', {}).withRetry(3).exec();

It would be really nice to define the retry one time only instead of writing it on every single method.

Namespace issue with same service name

I have some .proto files in same directory. These files have difference package name and same service name.
When this grpc-caller calls with includeDirs of loadOptions that return error 12 UNIMPLEMENTED: unknown service foo.BarService.

So, I read the source code of this grpc-caller.
I found the following problem.

https://github.com/bojand/grpc-caller/blob/master/lib/index.js#L54

This loaded variable include nested object with namespace.
However, grpc-caller call method can not set namespace that means grpc-inspect does not work as intended.
The grpc-inspect merged same name services in here.
https://github.com/bojand/grpc-inspect/blob/master/lib/inspect.js#L92

I added the namespace as below and it worked fine.

    const descriptor = gi(loaded['foo'])

I think that should add namespace option into caller of grpc-caller.
What do you think? Or am I doing something wrong?

An in-range update of grpc is breaking the build 🚨

Version 1.13.0 of grpc was just published.

Branch Build failing 🚨
Dependency grpc
Current Version 1.12.4
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

grpc is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Use typescript Ctor is not a constructor

I used static client and typescript

const services = require('./static/helloworld_grpc_pb')
const client = caller('localhost:50051', services.GreeterClient)

but when create client

D:\ming2\Desktop\work\cawi-cloud\web-api-gateway\node_modules\grpc-caller\lib\index.js:85
  const client = new Ctor(host, credentials || grpc.credentials.createInsecure(), options)

                 ^

TypeError: Ctor is not a constructor

What shall I do?

Not work with package name

If proto file contains package name, services not find.
Error: 12 UNIMPLEMENTED: RPC method not implemented /config.ConfigService/sendConfig
const PROTO_PATH = path.join(__dirname, '..', 'proto', 'main.proto'); const ConfiguratorHost = config.services.configurator; const client = caller(ConfiguratorHost, PROTO_PATH, 'ConfigService');

syntax = "proto3"; package config; service ConfigService { rpc sendConfig(ConfigRequest) returns (NullResponse); rpc writeSystemDeviceInfo (SystemDeviceInfo) returns (NullResponse); }

Absolute paths in includeDirs

Not work because "@grpc/proto-loader": "^0.3.0" not check targer absolute path. If update to "@grpc/proto-loader": "^0.4.0" all work.

An in-range update of grpc is breaking the build 🚨

Version 1.12.2 of grpc was just published.

Branch Build failing 🚨
Dependency grpc
Current Version 1.12.1
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

grpc is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Cannot create twice a client that uses stream

I have some code which is using the static way to promisify the gRPC calls. However if I do them twice in a raw the second time, the streaming APIs don't work. After debugging I found that the grpc Client object is being modified in such a way that it drops some of the fields of the original service object.

Simply try:

const services = require('./static/helloworld_grpc_pb');
var client = caller('localhost:50051', services.GreeterClient); // Client works for both normal and streaming gRPC calls.
client = caller('localhost:50051', services.GreeterClient);yar     // Client works for normal gRPC calls but not for streaming.

Where GreeterClient has some APIs using streams.

metadata is not being sent

I've tried all the possible variation of metadata (grpc metadata, row json), tried with callback, without callback (await), but it's seems like it's not sending any metadata.

On the official gRPC caller there is no any problem and I can see the metadata on the grpc server, so it's definitely problem of grpc-caller.
I tried to debug it but I got blocked at some point (out of my understanding and I have no time to dig deep - sorry).

Is there any known issue about that which I missed?

Return data is missing

I started a grpc service. One of the services will return an object with a code and msg field, but the result is that the code field is missing in the returned object.

code:

const client = new caller('0.0.0.0:50051', '../proto/login.proto', 'login')
client.login({ userName: 'Bob', password: '123' }, (err, res) => {
  console.log(res)
})

proto:

syntax = "proto3";
package login;
service login{
    rpc login(pingRequest) returns (pingReply) {};
    rpc signUp(pingRequest) returns (pingReply) {}
}
message pingRequest {
    string userName = 1;
    string password = 2;
}
message pingReply {
    int32 code = 1;
    string msg = 2;
}

result:
{ msg: 'login' }

Expected result:
{ code: 0, msg: 'login!' }
I look forward to your answer.Thank you.

@grpc/grpc-js get error "Channel credentials must be a ChannelCredentials object"

Thanks for great library

I have been using this for old "grpc" and it just works nice
Now, I update to new "@grpc/grpc-js" but getting this error, my code as bellow

const client = caller(
      serviceUrl,
      protoPath,
      'com.datalocker.safecrypt.grpc.VaultService',
      grpc.credentials.createInsecure(),
    );

I tested without "grpc.credentials.createInsecure()" ; then it works. I have no idea how to fix it since I would like to pass my SSL credentials to "caller" function. Any though on this?

Tested with both Node 10x and Node 14x. But no luck to me.

Expose response status and metadata

Currently for unary and request stream calls there is no easy way to get metadata and status if we want those

Server:

function sayHello(call, callback) {
  const md = new grpc.Metadata()
  md.set('foo', 'bar')
  call.sendMetadata(md)

  const smd = new grpc.Metadata()
  smd.set('biz', 'baz')
  callback(null, { message: 'Hello ' + call.request.name }, smd);
}

With the core client:

const call = client.sayHello({ name: user }, function (err, response) {
  console.log('response')
  console.log(response)
});

call.on('metadata', m => {
  console.log('metadata')
  console.dir(m, {depth: 4, colors: true})
})

call.on('status', m => {
  console.log('status')
  console.dir(m, {depth: 4, colors: true})
})
metadata
Metadata { _internal_repr: { foo: [ 'bar' ] } }
response
{ message: 'Hello world' }
status
{ code: 0,
  details: 'OK',
  metadata: Metadata { _internal_repr: { biz: [ 'baz' ] } } }

how to use dynamic client with nested protos?

I might be missing something simple, but if I have a proto file that has import statements to pull in other proto files, how can I import all of them for use in the dynamic client at runtime?

An in-range update of google-protobuf is breaking the build 🚨

Version 3.6.0 of google-protobuf was just published.

Branch Build failing 🚨
Dependency [google-protobuf](https://www.npmjs.com/package/google-protobuf)
Current Version 3.5.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

google-protobuf is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

What is serviceWrapper in the static example?

I'm using static client with metadata, tried codes below but didn't work.

const HelloService = require('./static/Hello_grpc_pb');
const client = caller('localhost: 50051', HelloService.HelloServiceClient);
const result = await HelloService.queryList({ name: 'tom' }, { node_id: 1 });
const HelloService = require('./static/Hello_grpc_pb');
let client = caller('localhost: 50051', HelloService.HelloServiceClient);
client = caller.wrap(client, { node_id: 1 });
const result = await HelloService.queryList({ name: 'tom' });

{ node_id: 1 } is my metadata.

image

I can't understand what is serviceWrapper in the document, how to define it?

Thanks!

throw error when status code 0

I call in try catch, and used Request API to show status code.
The status code is as follows, OK.

Response {
  call:
   ClientUnaryCall {
     _events:
      [Object: null prototype] { metadata: [Function], status: [Function] },
     _eventsCount: 2,
     _maxListeners: undefined,
     call:
      InterceptingCall { next_call: [InterceptingCall], requester: undefined } },
  response: {},
  metadata: Metadata { _internal_repr: {} },
  status:
   { code: 0,
     details: '',
     metadata: Metadata { _internal_repr: {} } } }

But throw UNAVAILABLE ERROR. What a strange question.

{ Error: 14 UNAVAILABLE: Connect Failed
    at Object.exports.createStatusError (D:\ming2\Desktop\work\cawi-cloud\web-api-gateway\node_modules\grpc\src\common.js:91:15)
    at Object.onReceiveStatus (D:\ming2\Desktop\work\cawi-cloud\web-api-gateway\node_modules\grpc\src\client_interceptors.js:1204:28)
    at InterceptingListener._callNext (D:\ming2\Desktop\work\cawi-cloud\web-api-gateway\node_modules\grpc\src\client_interceptors.js:568:42)
    at InterceptingListener.onReceiveStatus (D:\ming2\Desktop\work\cawi-cloud\web-api-gateway\node_modules\grpc\src\client_interceptors.js:618:8)
    at callback (D:\ming2\Desktop\work\cawi-cloud\web-api-gateway\node_modules\grpc\src\client_interceptors.js:845:24)
  code: 14,
  metadata: Metadata { _internal_repr: {} },
  details: 'Connect Failed' }

The introduction of proto-loader causes breaking changes

Since the introduction of @grpc/proto-loader, breaking changes are introduced due to the default options that module uses.

I would suggest you either perform a major version bump and provide an npm warning to users who consume versions of grpc-caller since the change was introduced, or you maintain the previous functionality by passing in default options as shown on https://github.com/grpc/grpc-node/tree/master/packages/grpc-protobufjs

const options = {
  keepCase: true,
  longs: String,
  enums: String,
  defaults: true,
  oneofs: true
}

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml
  • The new Node.js version is in-range for the engines in 1 of your package.json files, so that was left alone

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

replace `grpc` with `grpc-js`?

As official stated, the grpc package is planned to be deprecated, just wondering if the changes will be applied to this package?

It will be nice if there's a native-binary-free version to save the troublesome deployment stuff.

need some hook

consider supply some hook ? . ex. before call remote function or after call.
i expect use this able to add opentracing logic

How to define client interceptors

The documentation that describes how to add interceptors is confusing and contradicts what is shown in your test. For example, you have something that says

const options = grpc.credentials.createInsecure()
options.interceptors = [ bestInterceptorEver ] }

Which seems wrong, because you are adding the attribute "interceptors" to the createInsecure option.

Can you please provide a better example that includes what an interceptor would look like?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.