Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metadata is not being sent #10

Open
idangozlan opened this issue Apr 27, 2018 · 10 comments
Open

metadata is not being sent #10

idangozlan opened this issue Apr 27, 2018 · 10 comments
Assignees

Comments

@idangozlan
Copy link

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?

@bojand
Copy link
Owner

bojand commented Apr 27, 2018

Hello can you provide some source code please? There are lots of examples in the tests such as this for unary or for request stream or response stream call.

@idangozlan
Copy link
Author

idangozlan commented Apr 27, 2018

Sorry:

const PROTO_PATH = path.resolve(__dirname, './users.proto');
const client = caller('0.0.0.0:50051', PROTO_PATH, 'Users'); 
try {
    const res = await client.forgotPassword({ email: 'my@email.com' }, { ip_address: '192.168.0.11' });
    console.log('RESPONSE: ', res);
  } catch (error) {
    console.log('ERROR: ', error);
  }

simple request, no stream.

@bojand
Copy link
Owner

bojand commented Apr 28, 2018

I think that should work as evident by the tests. Please provide a reproducible example and some more details including the protocol buffer definition, server code, nodejs, and grpc library versions.

@idangozlan
Copy link
Author

There you go:

test.proto:

syntax = "proto3";

package helloworld;

// The greeting service definition.
service Greeter {
  // Sends a greeting
  rpc SayHello (HelloRequest) returns (HelloReply) {}
}

// The request message containing the user's name.
message HelloRequest {
  string name = 1;
}

// The response message containing the greetings
message HelloReply {
  string message = 1;
}

server.js:

const PROTO_PATH = `${__dirname}/test.proto`;

const grpc = require('grpc');

const helloProto = grpc.load(PROTO_PATH).helloworld;

/**
 * Implements the SayHello RPC method.
 */
function sayHello(call, callback) {
  console.log(call.request, call.metadata.getMap());
  callback(null, { message: `Hello ${call.request.name}` });
}

/**
 * Starts an RPC server that receives requests for the Greeter service at the
 * sample server port
 */
function main() {
  const server = new grpc.Server();
  server.addService(helloProto.Greeter.service, { sayHello });
  server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure());
  server.start();
}

main();

caller.js:

const PROTO_PATH = `${__dirname}/test.proto`;

const grpc = require('grpc');

const helloProto = grpc.load(PROTO_PATH).helloworld;

function main() {
  const client = new helloProto.Greeter(
    'localhost:50051',
    grpc.credentials.createInsecure(),
  );

  const meta = new grpc.Metadata();
  meta.add('ip_address', '192.168.0.11');

  client.sayHello({ name: 'world' }, meta, (err, response) => {
    console.log('Greeting:', response.message);
  });
}

main();

grpcCaller.js:

const PROTO_PATH = `${__dirname}/test.proto`;

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

function main() {
  const client = caller('0.0.0.0:50051', PROTO_PATH, 'Greeter');
  const meta = new grpc.Metadata();
  meta.add('ip_address', '192.168.0.11');

  client.sayHello({ name: 'world' }, meta, (err, response) => {
    console.log('Greeting:', response.message);
  });
}

main();

@bojand
Copy link
Owner

bojand commented Apr 28, 2018

Hmm I am still not able to reproduce this with latest master using Node 8.9. Can you maybe try the req_res branch of PR #11 and see if the problem still persists. Note that now you have to explicitly add grpc dependency in your package.json. Thanks!

@idangozlan
Copy link
Author

idangozlan commented Apr 28, 2018

I can reproduce it also with the req_res branch.. What is the console logs that you are getting on your running server terminal?

im running with node 8.10.0

@bojand bojand self-assigned this Apr 28, 2018
@bojand
Copy link
Owner

bojand commented Apr 28, 2018

client side:

~/dev/nodejs/grpc-caller-test node caller.js
Greeting: Hello world
~/dev/nodejs/grpc-caller-test

and on server:

~/dev/nodejs/grpc-caller-test node server.js
{ name: 'world' } { ip_address: '192.168.0.11',
  'user-agent': 'grpc-node/1.10.1 grpc-c/6.0.0-pre1 (osx; chttp2; glamorous)' }
^C
~/dev/nodejs/grpc-caller-test

@idangozlan
Copy link
Author

Haha, sure it will work, you are trying to run the original grpc caller :) try to run grpcCaller.js, the caller.js was just there to demonstrate how it should be..

@bojand
Copy link
Owner

bojand commented Apr 29, 2018

My apologies... I misread the code somehow heh. But still seems to works 😕

~/dev/nodejs/grpc-caller-test node grpcCaller.js
Greeting: Hello world
~/dev/nodejs/grpc-caller-test

and on the server side:

~/dev/nodejs/grpc-caller-test node server.js
{ name: 'world' } { ip_address: '192.168.0.11',
  'user-agent': 'grpc-node/1.10.1 grpc-c/6.0.0-pre1 (osx; chttp2; glamorous)' }
^C
~/dev/nodejs/grpc-caller-test

@idangozlan
Copy link
Author

idangozlan commented Apr 29, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants