Explain the magic used in the microservice package
See original GitHub issueI’m submitting a…
[ ] Regression
[ ] Bug report
[ ] Feature request
[X] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
The documentation should be more detailed about how the microservice communication works internally. Specifically I am surprised that one can assign the ClientProxy via a decorator:
@Client({ transport: Transport.TCP })
client: ClientProxy;
Arised questions:
- The connect process is an asynchronous task, where/when does it connect and what happens if you try to send something before it is connected?
- What happens if the connection could not be established? Does it have something like a writecache or how does it work right now?
- Maybe something for the future: The client.send method takes just one generic type for the response. What do you think about adding another generic which is supposed to define the structure of the payload. Thought behind this: I am expecting a specific format on the microservice and I want the publisher to comply with this format. If I plan to refactor this message structure at some point I want to make sure all publishers will also update the to be sent messages. I have published a npm package which abstracts the RPC logic away for RabbitMQ, maybe that gives you some inspiration so that we can enforce better type safety across microservices: https://github.com/weeco/rabbitmq-plus
Edit: Actually I just tried it and get my hands dirty. Probably there is something missing in the documentation, but I when I tried to call this.client.send()
I noticed the client is null.
(I created a RequestScheduler module for dispatching the RPC messages):
@Injectable()
export class RequestSchedulerService {
@Client({ transport: Transport.TCP })
private client: ClientProxy;
public getPlayerProfile(playerName: string): Observable<IPlayerStats> {
const pattern = { cmd: 'getPlayerProfile' };
const data = { playerName };
return this.client.send<IPlayerStats>(pattern, data);
}
}
So my question: Why is the client null here? Is it because there is no microservice connected? I hope to see a lot more documentation about how microservices work with NestJS. The samples about microservice seem to be outdated (v4) as well.
Edit 2: Somewhere in the outdated samples I saw there is a connectMicroservice() method which I have called as well. That does at least explain why the client could be assigned via a decorator (simply because it had been connected right after the Nest instance has been connected). However the assigned client decorator was still null. I hope to see an improved documentation or an up-to-date in depth example using microservices (then I could create a PR for the documentation).
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:7 (3 by maintainers)
@kamilmysliwiec I just read the updated docs, is there more to come? Because it still doesn’t answer some of my questions and nor does it tell me why my above example doesn’t work at all (the client is null). The microservice samples is also still outdated.
100% agree, I’ll update the docs before v5 release.