@tc-libs/rmq 3.5.0 → 3.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +70 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,70 @@
|
|
|
1
|
-
# rmq
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
# @tc-libs/rmq
|
|
2
|
+
|
|
3
|
+
Helper NestJS per RabbitMQ. Il package copre due esigenze:
|
|
4
|
+
|
|
5
|
+
- registrare client RMQ tramite `ClientsModule`
|
|
6
|
+
- costruire opzioni server/consumer e fare `ack` dei messaggi
|
|
7
|
+
|
|
8
|
+
## Registrazione del client
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
RmqModule.register('EMAIL', {
|
|
12
|
+
url: 'amqp://guest:guest@localhost:5672',
|
|
13
|
+
});
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
La queue usata dal client viene normalizzata come `RMQ_<QUEUE>_QUEUE`.
|
|
17
|
+
|
|
18
|
+
Versione async:
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
RmqModule.registerAsync('EMAIL', {
|
|
22
|
+
imports: [ConfigModule],
|
|
23
|
+
inject: [ConfigService],
|
|
24
|
+
useFactory: async (config: ConfigService) => ({
|
|
25
|
+
url: config.getOrThrow<string>('RMQ_URL'),
|
|
26
|
+
}),
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Servizio
|
|
31
|
+
|
|
32
|
+
`RmqService` espone:
|
|
33
|
+
|
|
34
|
+
- `getOptions(urls, queue, prefetchCount?, noAck?)`
|
|
35
|
+
- `ack(context)`
|
|
36
|
+
|
|
37
|
+
Esempio consumer:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
@MessagePattern('email.send')
|
|
41
|
+
async handle(@Ctx() context: RmqContext) {
|
|
42
|
+
// processa il messaggio
|
|
43
|
+
this.rmqService.ack(context);
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Esempio bootstrap microservice:
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
app.connectMicroservice(
|
|
51
|
+
this.rmqService.getOptions(
|
|
52
|
+
['amqp://guest:guest@localhost:5672'],
|
|
53
|
+
'RMQ_EMAIL_QUEUE',
|
|
54
|
+
10,
|
|
55
|
+
),
|
|
56
|
+
);
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Note operative
|
|
60
|
+
|
|
61
|
+
- Il modulo e `@Global()`.
|
|
62
|
+
- `ack` usa il channel e il messaggio originali esposti da `RmqContext`.
|
|
63
|
+
- `getOptions` imposta `persistent: true`.
|
|
64
|
+
|
|
65
|
+
## Sviluppo
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
nx build rmq
|
|
69
|
+
nx test rmq
|
|
70
|
+
```
|