Closed r3m4k3 closed 4 years ago
Okay, I guess I found the issue.
It's kinda strange, but changing the type from Observablemessages: any
instead of messages: Observable<any>
or messages: Observable<RatingInterface>
.
Please find the code presented below:
@GrpcStreamMethod('RatingsRpcService')
async findByIdStream(messages: any, metadata: any): Promise<Observable<RatingInterface>> {
const subject = new Subject<RatingInterface>();
messages.subscribe({
next: async (dto: GetRatingDto) => {
const item = await this.ratingsService.findById(dto.id);
subject.next(item);
},
error: (err: any) => {
throw new RpcException('Could not process stream.')
},
complete: () => subject.complete()
});
return subject.asObservable();
}
Please, use our Discord channel (support) for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.
I understand this, I know the purpose of GH issues, however, it seems like a bug to me or the official docs is outdated. Please read the thread once again before you answer.
Hi guys,
I was trying to use streams with grpc. But when I use the below published code, it says that subscribe is not a functions. It seems like Nestjs/microservice does not create an observable from a stream. Could you please publish up-to-date example with grpc? Because the method in the docs is kind of outdated.
My code - proto file:
And the controller file:
And the error I get:
TypeError: msg.subscribe is not a function
Versions:
Did I miss something?