Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(microservices): add docs about binding patterns for custom transporter #2247

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions content/faq/hybrid-application.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ await app.startAllMicroservices();
await app.listen(3001);
```

To bind `@MessagePattern()` to only one transport strategy (for example, MQTT) in a hybrid application with multiple microservices, we can pass the second argument of type `Transport` which is an enum with all the built-in transport strategies defined.
To bind `@MessagePattern()` to only one transport strategy (for example, MQTT) in a hybrid application with multiple microservices, we can pass the second argument with either of below:
1. a `Transport` which is an enum with all the built-in transport strategies defined.
2. a Symbol which is the `transportId` in the Custom Transporter server.


```typescript
@@filename()
Expand All @@ -48,6 +51,10 @@ getDate(@Payload() data: number[], @Ctx() context: NatsContext) {
getTCPDate(@Payload() data: number[]) {
return new Date().toLocaleTimeString(...);
}
@MessagePattern('topic.time.us', XYZServer.Transport) // suppose we have a custom Transporter XYZ
getXYZDate(@Payload() data: number[]) {
return new Date().toLocaleTimeString(...);
}
@@switch
@Bind(Payload(), Ctx())
@MessagePattern('time.us.*', Transport.NATS)
Expand All @@ -60,9 +67,15 @@ getDate(data, context) {
getTCPDate(data, context) {
return new Date().toLocaleTimeString(...);
}

@Bind(Payload(), Ctx())
@MessagePattern('topic.time.us', XYZServer.Transport)
getXYZDate(data, context) {
return new Date().toLocaleTimeString(...);
}
```

> info **Hint** `@Payload()`, `@Ctx()`, `Transport` and `NatsContext` are imported from `@nestjs/microservices`.
> info **Hint** `@Payload()`, `@Ctx()`, `Transport` and `NatsContext` are imported from `@nestjs/microservices`; `XYZServer.Transport` is imported from the Custom Transport, it should be a Symbol that set the `transportId` of `XYZServer`.

#### Sharing configuration

Expand Down