-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathmicroservice.controller.ts
More file actions
28 lines (25 loc) · 826 Bytes
/
microservice.controller.ts
File metadata and controls
28 lines (25 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { Controller } from '@nestjs/common';
import { MessagePattern } from '@nestjs/microservices';
import * as Sentry from '@sentry/nestjs';
@Controller()
export class MicroserviceController {
@MessagePattern({ cmd: 'sum' })
sum(data: { numbers: number[] }): number {
return Sentry.startSpan({ name: 'microservice-sum-operation' }, () => {
return data.numbers.reduce((a, b) => a + b, 0);
});
}
@MessagePattern({ cmd: 'exception' })
exception(data: { id: string }): never {
throw new Error(`Microservice exception with id ${data.id}`);
}
@MessagePattern({ cmd: 'manual-capture' })
manualCapture(): { success: boolean } {
try {
throw new Error('Manually captured microservice error');
} catch (e) {
Sentry.captureException(e);
}
return { success: true };
}
}