Skip to content

Commit 85e85ef

Browse files
docs(microservices) move timeout from separate to basics page
1 parent 4ffb5d9 commit 85e85ef

File tree

5 files changed

+35
-50
lines changed

5 files changed

+35
-50
lines changed

content/microservices/basics.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,38 @@ export interface RequestContext<T = any> {
348348
```
349349

350350
The `data` property is the message payload sent by the message producer. The `pattern` property is the pattern used to identify an appropriate handler to handle the incoming message.
351+
352+
353+
### Timeout
354+
355+
Sometimes, microservices are down or not available. You can handle these cases using the `RxJS` timeout operator in the call. If the microservice does not respond to the request within a certain time, an Exception is thrown, which can be caught and handled appropriately.
356+
357+
To solve this problem you have to install [rxjs](https://github.com/ReactiveX/rxjs) package:
358+
359+
```bash
360+
npm install rxjs
361+
```
362+
363+
Then just add a call of timeout method to the pipe:
364+
365+
```typescript
366+
@@filename()
367+
import { timeout } from 'rxjs/operators';
368+
// ...
369+
this.client
370+
.send<TResult, TInput>(pattern, data)
371+
.pipe(timeout(5000))
372+
.toPromise();
373+
@@switch
374+
import { timeout } from 'rxjs/operators';
375+
// ...
376+
this.client
377+
.send(pattern, data)
378+
.pipe(timeout(5000))
379+
.toPromise();
380+
```
381+
382+
After 5 seconds, if microservice isn't responding, it will throw an error:
383+
```bash
384+
[Nest] 17544 - 05/24/2020, 8:08:27 AM [ExceptionsHandler] Timeout has occurred +5009ms
385+
```

content/microservices/timeout.md

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/app/homepage/menu/menu.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ export class MenuComponent implements OnInit {
153153
{ title: 'Pipes', path: '/microservices/pipes' },
154154
{ title: 'Guards', path: '/microservices/guards' },
155155
{ title: 'Interceptors', path: '/microservices/interceptors' },
156-
{ title: 'Timeout', path: '/microservices/timeout' },
157156
],
158157
},
159158
{

src/app/homepage/pages/microservices/microservices.module.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { MicroservicesPipesComponent } from './pipes/pipes.component';
1414
import { RabbitMQComponent } from './rabbitmq/rabbitmq.component';
1515
import { KafkaComponent } from './kafka/kafka.component';
1616
import { RedisComponent } from './redis/redis.component';
17-
import { MicroservicesTimeoutComponent } from './timeout/timeout.component';
1817

1918
const routes: Routes = [
2019
{
@@ -77,11 +76,6 @@ const routes: Routes = [
7776
component: CustomTransportComponent,
7877
data: { title: 'Custom Transport - Microservices' },
7978
},
80-
{
81-
path: 'timeout',
82-
component: MicroservicesTimeoutComponent,
83-
data: { title: 'Timeout - Microservices' },
84-
},
8579
];
8680

8781
@NgModule({
@@ -94,7 +88,6 @@ const routes: Routes = [
9488
MicroservicesPipesComponent,
9589
MicroservicesInterceptorsComponent,
9690
MicroservicesGuardsComponent,
97-
MicroservicesTimeoutComponent,
9891
MqttComponent,
9992
GrpcComponent,
10093
RabbitMQComponent,

src/app/homepage/pages/microservices/timeout/timeout.component.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)