Comments (16)
I have similar issue. I'm as grpc client have to add jwt token to each request to grpc server and I don't understand how to do it. Help please :)
from docs.nestjs.com.
@Joshgallagher I'll recommend to have a look at https://github.com/stephenh/ts-proto and use their NestJS support: https://github.com/stephenh/ts-proto/blob/master/NESTJS.markdown
You'll get all the messages and gRPC call stups generated - including metadata option.
from docs.nestjs.com.
This doc illustrates the use of ts-proto package to generate ts files from .proto schemas.
here is an example script to generate for user.proto schema
# nestJs - /gen-nestjs-proto.sh
generate_nestjs_proto_definitions() {
# remove directory if exists
rm -r ./src/proto/nestjs
# make directory
mkdir ./src/proto/nestjs
# generate definitions
protoc --plugin=./node_modules/.bin/protoc-gen-ts_proto --ts_proto_opt=addGrpcMetadata=true --ts_proto_opt=nestJs=true --ts_proto_out=./src/proto/nestjs ./src/proto/user.proto
}
from docs.nestjs.com.
I have two application, the one is an graphql api application for frontend, the other is a microservice using grpc.
How can I pass the request instance to the rpc call, because I want to use it to show these request trace.
Or is there any way to trace the whole req/res chain?
@kamilmysliwiec Hello kamil, is there any solution for my issue? I am waitting for your reply, thanks a lot!
from docs.nestjs.com.
@kamilmysliwiec Is this related to this nestjs/nest#747? Will this issue resolve the need to have an example with a separated client and server instead of some hybrid thingy which calls itself?
from docs.nestjs.com.
Is metadata implemented in nest? Or is it a feature to be added?
If it is implemented, is there any docs on how to use it within nest?
from docs.nestjs.com.
@Joshgallagher it's implemented. There are no docs yet though :(
from docs.nestjs.com.
@kamilmysliwiec can you point me in the direction of a resource or some sort of rough implementation?
I can make a PR to examples with an example using metadata.
from docs.nestjs.com.
Also, to clarify:
- Can we create metadata from a client and send it to the gRPC service?
- Can we create metadata from the gRPC service itself, for use on the client?
from docs.nestjs.com.
@kamilmysliwiec Any updates? I'm using MaliJS until metadata is documented in Nest.
from docs.nestjs.com.
@Joshgallagher To pass metadata from client to service I found that you need to pass a grpc.Metadata
instance as second parameter to the client service call, it doesn't work with plain objects.
const meta = new grpc.Metadata();
meta.set('context', JSON.stringify(ctx));
this.client.getService('SomeService').someMethod(payload, meta);
it seems that the opposite (meta from service to client) is not supported
https://github.com/nestjs/nest/blob/master/packages/microservices/server/server-grpc.ts#L210
I think this is a grpc.sendUnaryData
callback that accepts a grpc.Metadata
instance as third argument
from docs.nestjs.com.
I have a nestjs instance acting as GRPC-Client sending metadata to another nestjs instance that is acting as a GRPC-Server as you described.
But: Seems like the metadata got lost or overwritten somehow.
Edit:
The example above works for me too. Just make sure to use the official grpc.Metadata from https://www.npmjs.com/package/grpc and not accidentally import it from another package.
from docs.nestjs.com.
Is there an update or a roadmap on this (adding metadata on the service)?
from docs.nestjs.com.
@kamilmysliwiec Is there any update on the docs providing information on gRPC (nest) microservices returning Metadata?
from docs.nestjs.com.
@sjkummer from my quick glimpse at that package is doesn't add support for gRPC metadata from the server. Correct me if I am wrong though.
from docs.nestjs.com.
@Joshgallagher Nestjs already supports gRPC metadata - it's just not well documented, how to declare the methods. You can use generated stubs from ts-proto
or write your own declarations by following https://docs.nestjs.com/microservices/grpc
from docs.nestjs.com.
Related Issues (20)
- Navigating to articles for previous versions redirects the user to the home page. HOT 1
- Suggestion for Document Function Display HOT 2
- Enhanced AI Access for NestJS Documentation HOT 1
- Update Queues docs guide to use bullmq instead of bull package HOT 2
- Difficulty in navigating topics on a page HOT 1
- Add docs on typescript-only features of `nest generate` commmand HOT 1
- WebSocketServer decorator gives unexpected value HOT 1
- Document the `type` and `disposition` options of `StreamableFile`
- Ads cover content HOT 2
- Better docs for implicit request scoped providers HOT 7
- [Docs] Small update to CLI Plugin page for clarity HOT 1
- How can I send header with kafka clientKafka=>send HOT 2
- [Docs] missing link in 'Devtools - CI/CD integration' HOT 1
- how to correctly do versioning with express adapter? HOT 2
- Unknown authentication strategy "jwt" HOT 1
- Dynamic modules exports confusion HOT 1
- [Authentication] Docs should address how to handle logging out, as well as logging in
- Issues and PR Summary HOT 1
- Documentation Issue: Missing explanation for statement HOT 2
- Documentation Issue/Discussion: Business logic in the exception filter? HOT 2
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 docs.nestjs.com.