question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Explain the magic used in the microservice package

See original GitHub issue

I’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:

  1. 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?
  2. What happens if the connection could not be established? Does it have something like a writecache or how does it work right now?
  3. 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:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
weecocommented, May 13, 2018

@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.

3reactions
kamilmysliwieccommented, May 11, 2018

100% agree, I’ll update the docs before v5 release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

@magic-microservices/magic - npm
Start using @magic-microservices/magic in your project by running `npm i ... TypeScript icon, indicating that this package has built-in type ...
Read more >
Microservices with Spring
If you are not familiar with Spring Boot, this explains some of the “magic”! View Templating Engines. The Eureka dashboard (inside ...
Read more >
What are microservices? | MuleSoft
A microservices architectural style leverages the ideology of developing a single application as a suite of small, narrowly focused, independently deployable ...
Read more >
The magic trick of CQRS: decoupling of microservice data
Even if it is used in a non-microservice architecture application, CQRS can ... this article will discuss the problems encountered in data ...
Read more >
Service meshes in a microservices architecture - Google Cloud
What are the new problems in microservices architecture? ... assess, and plan the use of service meshes in their architecture.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found