@nitra/nats 4.2.1 → 4.2.3
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/package.json +1 -1
- package/src/consumer.js +6 -5
package/package.json
CHANGED
package/src/consumer.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { millis, nanos } from '@nats-io/nats-core'
|
|
2
2
|
import { log } from '@nitra/pino'
|
|
3
|
-
import {
|
|
3
|
+
import { jsm } from './nats.js'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Створює або оновлює consumer.
|
|
@@ -10,6 +10,7 @@ import { nanos, millis } from '@nats-io/nats-core'
|
|
|
10
10
|
* @param {string[]} spec.filterSubjects - масив subject-ів для фільтрації
|
|
11
11
|
* @param {string} spec.deliverPolicy - політика доставки
|
|
12
12
|
* @param {string} spec.ackPolicy - політика підтвердження
|
|
13
|
+
* @param {string} spec.ackWait - час очікування підтвердження в мілісекундах
|
|
13
14
|
* @returns {Promise<void>}
|
|
14
15
|
*/
|
|
15
16
|
export async function ensureConsumer(spec) {
|
|
@@ -52,13 +53,13 @@ export async function ensureConsumer(spec) {
|
|
|
52
53
|
// якщо filter_subjects не відповідають spec, то оновлюємо consumer
|
|
53
54
|
else if (
|
|
54
55
|
compareArrays(spec.filterSubjects, filter_subjects) &&
|
|
55
|
-
(spec.ackWait === undefined || spec.ackWait === millis(ack_wait ?? 0))
|
|
56
|
+
(spec.ackWait === undefined || Number(spec.ackWait) === millis(ack_wait ?? 0))
|
|
56
57
|
) {
|
|
57
58
|
log.info(`✅ Consumer «${spec.durableName}» - no changes`)
|
|
58
59
|
} else {
|
|
59
60
|
await jsm.consumers.update(spec.streamName, spec.durableName, preparedSpec)
|
|
60
61
|
|
|
61
|
-
log.info(`🔥 Consumer «${spec.durableName}» filter_subjects - updated
|
|
62
|
+
log.info(`🔥 Consumer «${spec.durableName}» filter_subjects - updated`, preparedSpec)
|
|
62
63
|
}
|
|
63
64
|
} else {
|
|
64
65
|
await jsm.consumers.add(spec.streamName, preparedSpec)
|
|
@@ -79,7 +80,7 @@ function prepareSpec(spec) {
|
|
|
79
80
|
deliver_policy: spec.deliverPolicy // 'all' - всі непрочитані повідомлення
|
|
80
81
|
}
|
|
81
82
|
if (spec.ackWait) {
|
|
82
|
-
preparedSpec.ack_wait = nanos(spec.ackWait)
|
|
83
|
+
preparedSpec.ack_wait = nanos(Number(spec.ackWait))
|
|
83
84
|
}
|
|
84
85
|
return preparedSpec
|
|
85
86
|
}
|