From ea612fb4729429385aa5688559aa4e4c6b64d5de Mon Sep 17 00:00:00 2001 From: Xavier Zhou Date: Thu, 17 Mar 2022 10:18:00 +0800 Subject: [PATCH 1/2] docs(microservices): add docs about binding patterns for custom transporter --- content/faq/hybrid-application.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/content/faq/hybrid-application.md b/content/faq/hybrid-application.md index 2f1ea6ee12..59a3f3f039 100644 --- a/content/faq/hybrid-application.md +++ b/content/faq/hybrid-application.md @@ -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() @@ -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) @@ -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 From 76855f1a15c4b1904f623673bbc9e81822568454 Mon Sep 17 00:00:00 2001 From: Xavier Zhou Date: Thu, 17 Mar 2022 20:04:04 +0800 Subject: [PATCH 2/2] Update content/faq/hybrid-application.md Co-authored-by: Antonio T. Gex --- content/faq/hybrid-application.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/faq/hybrid-application.md b/content/faq/hybrid-application.md index 59a3f3f039..b90cd0b529 100644 --- a/content/faq/hybrid-application.md +++ b/content/faq/hybrid-application.md @@ -35,7 +35,7 @@ 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 with either of below, +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.