I can't find a way neither with serialization method in your options while starting the server like RMQ nor a transform-interceptor.
I read there are ways:
https://github.com/protocolbuffers/protobuf/issues/4891
https://developers.google.com/protocol-buffers/docs/proto3#any
But nothing is provided to get the raw message only pre-formated.
If I use google.protobuf.Any in my *.proto file it return a empty object in my message while I give a object with params and value's.
*.proto
syntax = "proto3";
package inventory;
import "google/protobuf/any.proto";
message CrudRequest {
string crudRequest = 1;
Any crudRequestTyped = 2;
}
Interface
interface ProductServiceRpc {
findOne(req: { crudRequest: string, crudRequestTyped: CrudRequest }): Observable<any>;
}
Method in Client
I want to remove the JSON.stringify and replace it with crudRequestTyped
getOne(req: CrudRequest): Promise<any> {
const test = this.productServiceRpc.findOne({ crudRequest: JSON.stringify(req), crudRequestTyped: req });
return test.toPromise();
}
Result in Server
{ crudRequest:
'{"parsed":{"fields":[],"paramsFilter":[{"field":"id","operator":"$eq","value":"5e8e7232-5bc7-437b-9972-a2f12440877a"}],"search":{"$and":[null,{"id":{"$eq":"5e8e7232-5bc7-437b-9972-a2f12440877a"}},{}]},"filter":[],"or":[],"join":[],"sort":[]},"options":{"query":{"alwaysPaginate":false},"routes":{"getManyBase":{"interceptors":[],"decorators":[]},"getOneBase":{"interceptors":[],"decorators":[]},"createOneBase":{"interceptors":[],"decorators":[],"returnShallow":false},"createManyBase":{"interceptors":[],"decorators":[]},"updateOneBase":{"interceptors":[],"decorators":[],"allowParamsOverride":false,"returnShallow":false},"replaceOneBase":{"interceptors":[],"decorators":[],"allowParamsOverride":false,"returnShallow":false},"deleteOneBase":{"interceptors":[],"decorators":[],"returnDeleted":false}},"params":{"id":{"field":"id","type":"uuid","primary":true}}}}',
crudRequestTyped: {} <-------- is always empty
Thx Imi.
Please, use our Discord channel (support) for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.
@imi187 hello, did you solve this yet, I have the same issue with you, and already try to ask on discord, but I still not get an answer.
(@imtosss123 )
Nope, I did not.
I put the label "Question" on it so they told me to ask it on Discord.
I don't want to use discord for technical things like this.
I spent time on it to write it proper in Github so it could help others to.
After a long search I did not find a way to get the raw message in NestJS
I don't have time for a feature request/bug report so I used RPC over RabitMQ
(@golevelup/nestjs-rabbitmq)
For the moment it helps but we will have to change it in the future.
Because this is not what I want.
Proto needs to know your type to reserve memory for that specific type.
(Example: fixed32 in proto will result in a uint32 in C++ (Four bytes (32bit)))
They provided a google.protobuf.Any. But you can only buffer it.
You can always use the library in node proto3 without using NestJs.
(I did not test it!)
Hope It helps.
@imtosss123 @imi187 In the future, it would be helpful to have a minimum reproduction and not jsut code snippets. Something that can be cloned, have its dependencies installed, and ran. I ended up making a reproduction to test this morning, and while I saw the problem you're facing, I also found this issue from the @grpc/proto-loader library which states that it doesn't handle ANY by itself, so you'll have to come up with some way to serialize and deserialize the binary blob on your own. This isn;'t an issue with Nest per se, but with a library Nest is using under the hood. You can always change the proto loader using the protoLoader option in the microservices options object.