Comments (10)
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.
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.
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.
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.
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.
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.
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.
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.
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.
from grpc-caller.
Related Issues (20)
- Namespace issue with same service name HOT 3
- Not work with package name HOT 1
- Clearly document how to read a streaming response HOT 5
- Is it a pure js module for grpc? HOT 6
- Absolute paths in includeDirs HOT 1
- What is serviceWrapper in the static example? HOT 6
- options.retry on the client is not working
- throw error when status code 0 HOT 1
- How to define client interceptors
- Use typescript Ctor is not a constructor HOT 2
- Return data is missing
- Question - TypeScript support and type declarations HOT 2
- How to set SetMaxMessageSize?
- Error: 2 UNKNOWN: Stream removed HOT 1
- need some hook
- replace `grpc` with `grpc-js`? HOT 2
- how to use dynamic client with nested protos?
- Cannot create a caller instance with retry options
- @grpc/grpc-js get error "Channel credentials must be a ChannelCredentials object" HOT 1
- Requirement on @grpc/grpc-js
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grpc-caller.