GithubHelp home page GithubHelp logo

metadata is not being sent about grpc-caller HOT 10 OPEN

bojand avatar bojand commented on May 20, 2024
metadata is not being sent

from grpc-caller.

Comments (10)

bojand avatar bojand commented on May 20, 2024

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.

from grpc-caller.

idangozlan avatar idangozlan commented on May 20, 2024

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: '[email protected]' }, { ip_address: '192.168.0.11' });
    console.log('RESPONSE: ', res);
  } catch (error) {
    console.log('ERROR: ', error);
  }

simple request, no stream.

from grpc-caller.

bojand avatar bojand commented on May 20, 2024

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.

from grpc-caller.

idangozlan avatar idangozlan commented on May 20, 2024

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();

from grpc-caller.

bojand avatar bojand commented on May 20, 2024

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!

from grpc-caller.

idangozlan avatar idangozlan commented on May 20, 2024

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

from grpc-caller.

bojand avatar bojand commented on May 20, 2024

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

from grpc-caller.

idangozlan avatar idangozlan commented on May 20, 2024

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..

from grpc-caller.

bojand avatar bojand commented on May 20, 2024

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

from grpc-caller.

idangozlan avatar idangozlan commented on May 20, 2024

from grpc-caller.

Related Issues (20)

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.