Skip to content

Commit d8207d7

Browse files
docs(microservices) add microservices-timeout page
1 parent 6c81a93 commit d8207d7

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

content/microservices/timeout.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
### Timeout
2+
3+
Sometimes, microservices are down or not available. For such cases, a timeout is required. If the microservice does not respond to the request within a certain time, an Exception is thrown, which can be caught and an error message will be displayed.
4+
5+
To solve this problem you have to install [rxjs](https://github.com/ReactiveX/rxjs) package:
6+
7+
```bash
8+
npm install rxjs
9+
```
10+
11+
Then just add a call of timeout method to the pipe:
12+
13+
```typescript
14+
@@filename()
15+
import { timeout } from 'rxjs/operators';
16+
// ...
17+
this.client
18+
.send<TResult, TInput>(pattern, data)
19+
.pipe(timeout(5000))
20+
.toPromise();
21+
@@switch
22+
import { timeout } from 'rxjs/operators';
23+
// ...
24+
this.client
25+
.send(pattern, data)
26+
.pipe(timeout(5000))
27+
.toPromise();
28+
```
29+
30+
After 5 seconds, if microservice isn't responding, it will throw an error:
31+
```bash
32+
[Nest] 17544 - 05/24/2020, 8:08:27 AM [ExceptionsHandler] Timeout has occurred +5009ms
33+
```

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ 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' },
156157
],
157158
},
158159
{

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ 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';
1718

1819
const routes: Routes = [
1920
{
@@ -76,6 +77,11 @@ const routes: Routes = [
7677
component: CustomTransportComponent,
7778
data: { title: 'Custom Transport - Microservices' },
7879
},
80+
{
81+
path: 'timeout',
82+
component: MicroservicesTimeoutComponent,
83+
data: { title: 'Timeout - Microservices' },
84+
},
7985
];
8086

8187
@NgModule({
@@ -88,6 +94,7 @@ const routes: Routes = [
8894
MicroservicesPipesComponent,
8995
MicroservicesInterceptorsComponent,
9096
MicroservicesGuardsComponent,
97+
MicroservicesTimeoutComponent,
9198
MqttComponent,
9299
GrpcComponent,
93100
RabbitMQComponent,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { ChangeDetectionStrategy, Component } from '@angular/core';
2+
import { BasePageComponent } from '../../page/page.component';
3+
4+
@Component({
5+
selector: 'app-timeout',
6+
templateUrl: './timeout.component.html',
7+
changeDetection: ChangeDetectionStrategy.OnPush,
8+
})
9+
export class MicroservicesTimeoutComponent extends BasePageComponent {}

0 commit comments

Comments
 (0)