Skip to content

Commit c5e6dab

Browse files
author
alex
committed
docs(microservices): move instruction to use transport in MessagePattern to hybrid application section
1 parent eabef6c commit c5e6dab

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

content/faq/hybrid-application.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,30 @@ const microserviceRedis = app.connectMicroservice<MicroserviceOptions>({
3434
await app.startAllMicroservicesAsync();
3535
await app.listen(3001);
3636
```
37+
38+
For bind `@MessagePattern()` only to one transport of microservices in hybrid application with multiple microservices can use second argument which should get value from `Transport` enum
39+
40+
```typescript
41+
@@filename()
42+
@MessagePattern('time.us.*', Transport.NAST)
43+
getDate(@Payload() data: number[], @Ctx() context: NatsContext) {
44+
console.log(`Subject: ${context.getSubject()}`); // e.g. "time.us.east"
45+
return new Date().toLocaleTimeString(...);
46+
}
47+
@MessagePattern({ cmd: 'time.us' }, Transport.TCP)
48+
getTCPDate(@Payload() data: number[]) {
49+
return new Date().toLocaleTimeString(...);
50+
}
51+
@@switch
52+
@Bind(Payload(), Ctx())
53+
@MessagePattern('time.us.*', Transport.NAST)
54+
getDate(data, context) {
55+
console.log(`Subject: ${context.getSubject()}`); // e.g. "time.us.east"
56+
return new Date().toLocaleTimeString(...);
57+
}
58+
@Bind(Payload(), Ctx())
59+
@MessagePattern({ cmd: 'time.us' }, Transport.TCP)
60+
getTCPDate(data, context) {
61+
return new Date().toLocaleTimeString(...);
62+
}
63+
```

content/microservices/basics.md

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -205,33 +205,6 @@ getDate(data, context) {
205205
}
206206
```
207207

208-
For bind `@MessagePattern()` only to one transport of microservices in hybrid application with multiple microservices can use second argument which should get value from `Transport` enum
209-
210-
```typescript
211-
@@filename()
212-
@MessagePattern('time.us.*', Transport.NAST)
213-
getDate(@Payload() data: number[], @Ctx() context: NatsContext) {
214-
console.log(`Subject: ${context.getSubject()}`); // e.g. "time.us.east"
215-
return new Date().toLocaleTimeString(...);
216-
}
217-
@MessagePattern({ cmd: 'time.us' }, Transport.TCP)
218-
getTCPDate(@Payload() data: number[]) {
219-
return new Date().toLocaleTimeString(...);
220-
}
221-
@@switch
222-
@Bind(Payload(), Ctx())
223-
@MessagePattern('time.us.*', Transport.NAST)
224-
getDate(data, context) {
225-
console.log(`Subject: ${context.getSubject()}`); // e.g. "time.us.east"
226-
return new Date().toLocaleTimeString(...);
227-
}
228-
@Bind(Payload(), Ctx())
229-
@MessagePattern({ cmd: 'time.us' }, Transport.TCP)
230-
getTCPDate(data, context) {
231-
return new Date().toLocaleTimeString(...);
232-
}
233-
```
234-
235208
> info **Hint** `@Payload()`, `@Ctx()`, `Transport` and `NatsContext` are imported from `@nestjs/microservices`.
236209
237210
#### Client

0 commit comments

Comments
 (0)