Comments (9)
As stated in the release notes, detailed information about that feature can be found in gRFC L112. All of the information you need can be found there. If you have specific questions feel free to follow up.
from grpc-node.
Is there any document, I can referrer for configuring in Js , not typescript, please let me know Thanks
Note: interceptors will only be called when a request to a registered method is made.
This note says we have to register a request , so does this support JavaScript. If so Can you please add an example for configuration
from grpc-node.
The API for JavaScript is the same as for TypeScript, except that you don't use any types.
This example demonstrates registering a service, specifically on this line
from grpc-node.
I have followed adding a server interceptor in the below code. But when you call service from client , console log in server interceptor it is not logged. Please let me know how to configure listener , where is start method in responder to configure
// Server code
const listener = (new grpc.ServerListenerBuilder())
.withOnReceiveMetadata(function (metadata, next) {
logger.log(metadata);
next(metadata);
})
.withOnReceiveMessage(function (message, next) {
logger.log(message);
next(message);
})
.build();
const serverInterceptor = {
start :(next) => {
next(listener)
}
}
const requester = (new grpc.ResponderBuilder())
.withSendMetadata(function (metadata, next) {
logger.log(metadata);
next(metadata);
})
.withSendMessage(function (message, next) {
logger.log(message);
next(message);
})
.build();
const interceptors = function interceptor(methodDescriptor, call) {
return new grpc.ServerInterceptingCall(serverInterceptor, requester);
}
const server = new grpc.Server([interceptors])
server.addService(linksProto.LinkService.service, {
ListLinks: listLinks
})
server.bindAsync(
"localhost:30043",
grpc.ServerCredentials.createInsecure(), () => {
server.start()
console.log(`Server running at ${serverAddress}`)
})
// Client code
function main() {
let metadata = new grpc.Metadata();
metadata.add('authorization', 'test Data')
let client = new LinkService("localhost:30043", grpc.credentials.createInsecure());
client.ListLinks({"parent":"partners/partner-1"},metadata,(err,data) => {
if(!err){
console.log('data', JSON.stringify(data));
}
else{
console.log('error', err);
}
});
}
from grpc-node.
I think need a document on how to configure serverListener. Please check above server code and client code, when I call service interceptors are not called. Please let me know if any suggestions
from grpc-node.
Your server constructor call should be
const server = new grpc.Server({interceptors: [interceptors]});
from grpc-node.
Your server constructor call should be
const server = new grpc.Server({interceptors: [interceptors]});
Thank you for pointing out the issue, I am able to configure interceptors and log metadata and message in listener.
I have one query regarding handling metadata, usually metadata is handled for validating tokens, if the token is invalid. how do you handle , I don't see the call back function to throw an error. if I throw an error inside as below code. server is getting aborted here. please let me know how to handle the scenarios to stop further and throw back error to client
ex : withOnReceiveMetadata(function (metadata, next) {
console.log('meta data Received', metadata);
if(!token){
throw new Error('Invalid token authentication failed')
}
next(metadata);
})
from grpc-node.
To do that, you would need to interact with the call passed in to the interceptor function, and call call.sendStatus
. Here is an example in the tests.
from grpc-node.
Thank you @murgatroid99.
from grpc-node.
Related Issues (20)
- grpc-js not supporting the namedpipe communication HOT 15
- proto-loader-gen-types Warning: **/*.proto not found in any of the include paths ../protos HOT 2
- @grpc/reflection Not working after bundling HOT 1
- @grpc/grpc-health-check Not working after bundling HOT 1
- cannot pass jwt token
- gRPC Keepalive Behavior in Serverless Environments HOT 1
- gRPC client xDS failing to reconnect after MaxConnectionIdle HOT 2
- Server restart in v1.10.0 - regression? HOT 4
- Critical performance bottleneck with high-throughput GRPC stream handling HOT 10
- change grpc_tools_node_protoc_plugin binary name to protoc-gen-js-grpc
- @grpc/reflection writes wanings to console for .proto files with no package declaration HOT 9
- Received RST_STREAM with code 2 triggered by internal client error: Session closed with error code 2 HOT 1
- ssl not working with test certs HOT 2
- The order of server stream events has changed since 1.10.0 HOT 5
- loadObject() throwing the same error as load() HOT 1
- Possible duplicates of function declarations in service interface
- Adding more context to error stack traces HOT 2
- Requests seem not to respond anymore after upgrading to 1.10.2 HOT 14
- "New streams cannot be created after receiving a GOAWAY" and CANCELLED errors during service deployments HOT 11
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-node.