@lakutata/nats 1.6.0 → 1.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/CHANGELOG.md +8 -0
- package/dist/CommonExports.d.ts +3 -1
- package/dist/CommonExports.d.ts.map +1 -1
- package/dist/CommonExports.js +11 -4
- package/dist/components/NATS.d.ts +3 -2
- package/dist/components/NATS.d.ts.map +1 -1
- package/dist/components/NATS.js +8 -3
- package/dist/providers/Task.d.ts +16 -4
- package/dist/providers/Task.d.ts.map +1 -1
- package/dist/providers/Task.js +79 -17
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.6.1](https://github.com/lakutata/lakutata-packages/compare/@lakutata/nats@1.6.0...@lakutata/nats@1.6.1) (2026-01-17)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @lakutata/nats
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# [1.6.0](https://github.com/lakutata/lakutata-packages/compare/@lakutata/nats@1.5.2...@lakutata/nats@1.6.0) (2026-01-16)
|
|
7
15
|
|
|
8
16
|
|
package/dist/CommonExports.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { SetupNatsServiceEntrypoint } from './entrypoints/SetupNatsServiceEntrypoint';
|
|
2
2
|
export { ServiceProxy, BuildServiceProxy, type BuildServiceProxyOptions } from './providers/ServiceProxy';
|
|
3
|
-
export {
|
|
3
|
+
export { TaskOptions } from './providers/Task';
|
|
4
|
+
export { default as Task } from './providers/Task';
|
|
5
|
+
export { RetentionPolicy } from 'nats';
|
|
4
6
|
export { NATS, buildNatsClientOptions } from './components/NATS';
|
|
5
7
|
export { JSONCodec } from './codecs/JSONCodec';
|
|
6
8
|
export { MessagePackCodec } from './codecs/MessagePackCodec';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommonExports.d.ts","sourceRoot":"","sources":["../src/CommonExports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,0BAA0B,EAAC,MAAM,0CAA0C,CAAA;AACnF,OAAO,EAAC,YAAY,EAAE,iBAAiB,EAAE,KAAK,wBAAwB,EAAC,MAAM,0BAA0B,CAAA;AACvG,OAAO,EAAC,IAAI,EAAC,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"CommonExports.d.ts","sourceRoot":"","sources":["../src/CommonExports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,0BAA0B,EAAC,MAAM,0CAA0C,CAAA;AACnF,OAAO,EAAC,YAAY,EAAE,iBAAiB,EAAE,KAAK,wBAAwB,EAAC,MAAM,0BAA0B,CAAA;AACvG,OAAO,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAA;AAC5C,OAAO,EAAC,OAAO,IAAI,IAAI,EAAC,MAAM,kBAAkB,CAAA;AAChD,OAAO,EAAC,eAAe,EAAC,MAAM,MAAM,CAAA;AACpC,OAAO,EAAC,IAAI,EAAE,sBAAsB,EAAC,MAAM,mBAAmB,CAAA;AAC9D,OAAO,EAAC,SAAS,EAAC,MAAM,oBAAoB,CAAA;AAC5C,OAAO,EAAC,gBAAgB,EAAC,MAAM,2BAA2B,CAAA;AAC1D,OAAO,EAAC,WAAW,EAAC,MAAM,MAAM,CAAA;AAChC,YAAY,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CAAA;AAC9D,YAAY,EAAC,YAAY,EAAE,KAAK,EAAC,MAAM,MAAM,CAAA;AAC7C,YAAY,EAAC,iBAAiB,EAAC,MAAM,gCAAgC,CAAA;AACrE,OAAO,EAAC,uBAAuB,EAAC,MAAM,sCAAsC,CAAA;AAC5E,OAAO,EAAC,sBAAsB,EAAC,MAAM,qCAAqC,CAAA;AAC1E,OAAO,EAAC,2BAA2B,EAAC,MAAM,0CAA0C,CAAA;AACpF,OAAO,EAAC,kCAAkC,EAAC,MAAM,iDAAiD,CAAA;AAClG,OAAO,EAAC,qBAAqB,EAAC,MAAM,oCAAoC,CAAA;AACxE,OAAO,EAAC,2BAA2B,EAAC,MAAM,0CAA0C,CAAA"}
|
package/dist/CommonExports.js
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NatsRequestTimeoutException = exports.NatsNotFoundException = exports.NatsNoRespondersAvailableException = exports.NatsInternalServerException = exports.NatsForbiddenException = exports.NatsBadRequestException = exports.StringCodec = exports.MessagePackCodec = exports.JSONCodec = exports.buildNatsClientOptions = exports.NATS = exports.Task = exports.BuildServiceProxy = exports.ServiceProxy = exports.SetupNatsServiceEntrypoint = void 0;
|
|
6
|
+
exports.NatsRequestTimeoutException = exports.NatsNotFoundException = exports.NatsNoRespondersAvailableException = exports.NatsInternalServerException = exports.NatsForbiddenException = exports.NatsBadRequestException = exports.StringCodec = exports.MessagePackCodec = exports.JSONCodec = exports.buildNatsClientOptions = exports.NATS = exports.RetentionPolicy = exports.Task = exports.TaskOptions = exports.BuildServiceProxy = exports.ServiceProxy = exports.SetupNatsServiceEntrypoint = void 0;
|
|
4
7
|
var SetupNatsServiceEntrypoint_1 = require("./entrypoints/SetupNatsServiceEntrypoint");
|
|
5
8
|
Object.defineProperty(exports, "SetupNatsServiceEntrypoint", { enumerable: true, get: function () { return SetupNatsServiceEntrypoint_1.SetupNatsServiceEntrypoint; } });
|
|
6
9
|
var ServiceProxy_1 = require("./providers/ServiceProxy");
|
|
7
10
|
Object.defineProperty(exports, "ServiceProxy", { enumerable: true, get: function () { return ServiceProxy_1.ServiceProxy; } });
|
|
8
11
|
Object.defineProperty(exports, "BuildServiceProxy", { enumerable: true, get: function () { return ServiceProxy_1.BuildServiceProxy; } });
|
|
9
12
|
var Task_1 = require("./providers/Task");
|
|
10
|
-
Object.defineProperty(exports, "
|
|
13
|
+
Object.defineProperty(exports, "TaskOptions", { enumerable: true, get: function () { return Task_1.TaskOptions; } });
|
|
14
|
+
var Task_2 = require("./providers/Task");
|
|
15
|
+
Object.defineProperty(exports, "Task", { enumerable: true, get: function () { return __importDefault(Task_2).default; } });
|
|
16
|
+
var nats_1 = require("nats");
|
|
17
|
+
Object.defineProperty(exports, "RetentionPolicy", { enumerable: true, get: function () { return nats_1.RetentionPolicy; } });
|
|
11
18
|
var NATS_1 = require("./components/NATS");
|
|
12
19
|
Object.defineProperty(exports, "NATS", { enumerable: true, get: function () { return NATS_1.NATS; } });
|
|
13
20
|
Object.defineProperty(exports, "buildNatsClientOptions", { enumerable: true, get: function () { return NATS_1.buildNatsClientOptions; } });
|
|
@@ -15,8 +22,8 @@ var JSONCodec_1 = require("./codecs/JSONCodec");
|
|
|
15
22
|
Object.defineProperty(exports, "JSONCodec", { enumerable: true, get: function () { return JSONCodec_1.JSONCodec; } });
|
|
16
23
|
var MessagePackCodec_1 = require("./codecs/MessagePackCodec");
|
|
17
24
|
Object.defineProperty(exports, "MessagePackCodec", { enumerable: true, get: function () { return MessagePackCodec_1.MessagePackCodec; } });
|
|
18
|
-
var
|
|
19
|
-
Object.defineProperty(exports, "StringCodec", { enumerable: true, get: function () { return
|
|
25
|
+
var nats_2 = require("nats");
|
|
26
|
+
Object.defineProperty(exports, "StringCodec", { enumerable: true, get: function () { return nats_2.StringCodec; } });
|
|
20
27
|
var NatsBadRequestException_1 = require("./exceptions/NatsBadRequestException");
|
|
21
28
|
Object.defineProperty(exports, "NatsBadRequestException", { enumerable: true, get: function () { return NatsBadRequestException_1.NatsBadRequestException; } });
|
|
22
29
|
var NatsForbiddenException_1 = require("./exceptions/NatsForbiddenException");
|
|
@@ -2,7 +2,7 @@ import { Application, Component, ComponentOptionsBuilder } from 'lakutata';
|
|
|
2
2
|
import { type Codec, Subscription } from 'nats';
|
|
3
3
|
import { SubscribeOptions } from '../types/SubscribeOptions';
|
|
4
4
|
import { NatsClientOptions } from '../interfaces/NatsClientOptions';
|
|
5
|
-
import {
|
|
5
|
+
import Task, { TaskOptions } from '../providers/Task';
|
|
6
6
|
export declare const buildNatsClientOptions: ComponentOptionsBuilder<NatsClientOptions>;
|
|
7
7
|
export declare class NATS extends Component {
|
|
8
8
|
#private;
|
|
@@ -114,8 +114,9 @@ export declare class NATS extends Component {
|
|
|
114
114
|
* Create task provider
|
|
115
115
|
* @param subject
|
|
116
116
|
* @param handler
|
|
117
|
+
* @param options
|
|
117
118
|
*/
|
|
118
|
-
createTask(subject: string, handler?: (data: any) => void | Promise<void
|
|
119
|
+
createTask(subject: string, handler?: (data: any) => void | Promise<void>, options?: TaskOptions): Promise<Task>;
|
|
119
120
|
/**
|
|
120
121
|
* Publishes the specified data to the specified subject.
|
|
121
122
|
* @param subject
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NATS.d.ts","sourceRoot":"","sources":["../../src/components/NATS.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,SAAS,EAET,uBAAuB,EAE1B,MAAM,UAAU,CAAA;AAEjB,OAAO,EAAC,KAAK,KAAK,EAAgC,YAAY,EAAC,MAAM,MAAM,CAAA;AAC3E,OAAO,EAAC,gBAAgB,EAAC,MAAM,2BAA2B,CAAA;AAO1D,OAAO,EAAC,iBAAiB,EAAC,MAAM,iCAAiC,CAAA;AAGjE,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"NATS.d.ts","sourceRoot":"","sources":["../../src/components/NATS.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,SAAS,EAET,uBAAuB,EAE1B,MAAM,UAAU,CAAA;AAEjB,OAAO,EAAC,KAAK,KAAK,EAAgC,YAAY,EAAC,MAAM,MAAM,CAAA;AAC3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GAAG,IAAI;IAMhE;;;;;;OAMG;IACI,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,EAAE,wBAAwB,GAAE,OAAe,GAAG,IAAI;IAYhJ;;;;;OAKG;IACI,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,IAAI;IAavG;;;;;OAKG;IACI,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,IAAI;CAW1G"}
|
package/dist/components/NATS.js
CHANGED
|
@@ -8,6 +8,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.NATS = exports.buildNatsClientOptions = void 0;
|
|
13
16
|
const lakutata_1 = require("lakutata");
|
|
@@ -21,7 +24,7 @@ const NatsNoRespondersAvailableException_1 = require("../exceptions/NatsNoRespon
|
|
|
21
24
|
const NatsInternalServerException_1 = require("../exceptions/NatsInternalServerException");
|
|
22
25
|
const ServiceEventCodec_1 = require("../lib/ServiceEventCodec");
|
|
23
26
|
const MessagePackCodec_1 = require("../codecs/MessagePackCodec");
|
|
24
|
-
const Task_1 = require("../providers/Task");
|
|
27
|
+
const Task_1 = __importDefault(require("../providers/Task"));
|
|
25
28
|
const buildNatsClientOptions = (options) => {
|
|
26
29
|
return {
|
|
27
30
|
class: NATS,
|
|
@@ -88,12 +91,14 @@ class NATS extends lakutata_1.Component {
|
|
|
88
91
|
* Create task provider
|
|
89
92
|
* @param subject
|
|
90
93
|
* @param handler
|
|
94
|
+
* @param options
|
|
91
95
|
*/
|
|
92
|
-
async createTask(subject, handler) {
|
|
93
|
-
return await this.buildObject(Task_1.
|
|
96
|
+
async createTask(subject, handler, options) {
|
|
97
|
+
return await this.buildObject(Task_1.default, {
|
|
94
98
|
jetStreamManager: await this.#conn.jetstreamManager(),
|
|
95
99
|
jetStream: this.#conn.jetstream(),
|
|
96
100
|
codec: this.codec,
|
|
101
|
+
options: options || {},
|
|
97
102
|
subject: subject,
|
|
98
103
|
handler: handler
|
|
99
104
|
});
|
package/dist/providers/Task.d.ts
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
|
-
import { Provider } from 'lakutata';
|
|
2
|
-
import { type Codec, type JetStreamClient, type JetStreamManager } from 'nats';
|
|
3
|
-
export declare class
|
|
1
|
+
import { DTO, Provider } from 'lakutata';
|
|
2
|
+
import { type Codec, RetentionPolicy, type JetStreamClient, type JetStreamManager } from 'nats';
|
|
3
|
+
export declare class TaskOptions extends DTO {
|
|
4
|
+
retention?: RetentionPolicy;
|
|
5
|
+
maxMessages?: number;
|
|
6
|
+
maxAgeMs?: number;
|
|
7
|
+
maxBytes?: number;
|
|
8
|
+
maxMessageSize?: number;
|
|
9
|
+
duplicateWindowMs?: number;
|
|
10
|
+
concurrentTask?: number;
|
|
11
|
+
}
|
|
12
|
+
declare class Task extends Provider {
|
|
4
13
|
#private;
|
|
5
14
|
protected readonly jetStreamManager: JetStreamManager;
|
|
6
15
|
protected readonly jetStream: JetStreamClient;
|
|
7
16
|
protected readonly subject: string;
|
|
17
|
+
protected readonly options: TaskOptions;
|
|
8
18
|
protected readonly handler?: (data: any) => void | Promise<void>;
|
|
9
19
|
/**
|
|
10
20
|
* NATS message codec
|
|
@@ -30,7 +40,9 @@ export declare class Task extends Provider {
|
|
|
30
40
|
/**
|
|
31
41
|
* Publish task
|
|
32
42
|
* @param payload
|
|
43
|
+
* @param id
|
|
33
44
|
*/
|
|
34
|
-
publish(payload: any): Promise<void>;
|
|
45
|
+
publish(payload: any, id?: string): Promise<void>;
|
|
35
46
|
}
|
|
47
|
+
export default Task;
|
|
36
48
|
//# sourceMappingURL=Task.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Task.d.ts","sourceRoot":"","sources":["../../src/providers/Task.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"Task.d.ts","sourceRoot":"","sources":["../../src/providers/Task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAC,MAAM,UAAU,CAAA;AAEtC,OAAO,EAEH,KAAK,KAAK,EAEV,eAAe,EAEf,KAAK,eAAe,EACpB,KAAK,gBAAgB,EAMxB,MAAM,MAAM,CAAA;AAIb,qBAAa,WAAY,SAAQ,GAAG;IAEzB,SAAS,CAAC,EAAE,eAAe,CAAA;IAG3B,WAAW,CAAC,EAAE,MAAM,CAAA;IAGpB,QAAQ,CAAC,EAAE,MAAM,CAAA;IAGjB,QAAQ,CAAC,EAAE,MAAM,CAAA;IAGjB,cAAc,CAAC,EAAE,MAAM,CAAA;IAGvB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAG1B,cAAc,CAAC,EAAE,MAAM,CAAA;CACjC;AAED,cAAM,IAAK,SAAQ,QAAQ;;IAKvB,SAAS,CAAC,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB,CAAA;IAGrD,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,eAAe,CAAA;IAG7C,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IAGlC,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAA;IAGvC,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAEhE;;;OAGG;IAKH,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,CAAA;IAExC,SAAS,KAAK,UAAU,IAAI,MAAM,CAEjC;IAED;;;OAGG;cACa,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IA6DrC;;;OAGG;cACa,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxC;;;OAGG;cACa,mBAAmB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAQ7D;;;;OAIG;IACU,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGjE;AAED,eAAe,IAAI,CAAA"}
|
package/dist/providers/Task.js
CHANGED
|
@@ -9,11 +9,43 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.TaskOptions = void 0;
|
|
13
13
|
const lakutata_1 = require("lakutata");
|
|
14
14
|
const di_1 = require("lakutata/decorator/di");
|
|
15
15
|
const nats_1 = require("nats");
|
|
16
16
|
const helper_1 = require("lakutata/helper");
|
|
17
|
+
const dto_1 = require("lakutata/decorator/dto");
|
|
18
|
+
class TaskOptions extends lakutata_1.DTO {
|
|
19
|
+
}
|
|
20
|
+
exports.TaskOptions = TaskOptions;
|
|
21
|
+
__decorate([
|
|
22
|
+
(0, dto_1.Expect)(lakutata_1.DTO.String().allow('limits', 'interest', 'workqueue').only().optional()),
|
|
23
|
+
__metadata("design:type", String)
|
|
24
|
+
], TaskOptions.prototype, "retention", void 0);
|
|
25
|
+
__decorate([
|
|
26
|
+
(0, dto_1.Expect)(lakutata_1.DTO.Number().integer().allow(0).min(-1).optional()),
|
|
27
|
+
__metadata("design:type", Number)
|
|
28
|
+
], TaskOptions.prototype, "maxMessages", void 0);
|
|
29
|
+
__decorate([
|
|
30
|
+
(0, dto_1.Expect)(lakutata_1.DTO.Number().integer().allow(0).min(0).optional()),
|
|
31
|
+
__metadata("design:type", Number)
|
|
32
|
+
], TaskOptions.prototype, "maxAgeMs", void 0);
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, dto_1.Expect)(lakutata_1.DTO.Number().integer().allow(0).min(-1).optional()),
|
|
35
|
+
__metadata("design:type", Number)
|
|
36
|
+
], TaskOptions.prototype, "maxBytes", void 0);
|
|
37
|
+
__decorate([
|
|
38
|
+
(0, dto_1.Expect)(lakutata_1.DTO.Number().integer().allow(0).min(-1).optional()),
|
|
39
|
+
__metadata("design:type", Number)
|
|
40
|
+
], TaskOptions.prototype, "maxMessageSize", void 0);
|
|
41
|
+
__decorate([
|
|
42
|
+
(0, dto_1.Expect)(lakutata_1.DTO.Number().allow(0).min(0).optional()),
|
|
43
|
+
__metadata("design:type", Number)
|
|
44
|
+
], TaskOptions.prototype, "duplicateWindowMs", void 0);
|
|
45
|
+
__decorate([
|
|
46
|
+
(0, dto_1.Expect)(lakutata_1.DTO.Number().integer().min(1).optional()),
|
|
47
|
+
__metadata("design:type", Number)
|
|
48
|
+
], TaskOptions.prototype, "concurrentTask", void 0);
|
|
17
49
|
class Task extends lakutata_1.Provider {
|
|
18
50
|
#requestTask = true;
|
|
19
51
|
get streamName() {
|
|
@@ -25,19 +57,34 @@ class Task extends lakutata_1.Provider {
|
|
|
25
57
|
*/
|
|
26
58
|
async init() {
|
|
27
59
|
let streamName = await this.getExistsStreamName();
|
|
60
|
+
const streamConfig = {
|
|
61
|
+
subjects: [this.subject],
|
|
62
|
+
retention: this.options.retention || nats_1.RetentionPolicy.Workqueue,
|
|
63
|
+
max_msgs: this.options.maxMessages !== undefined ? this.options.maxMessages : -1,
|
|
64
|
+
max_age: (0, nats_1.nanos)(this.options.maxAgeMs || 0),
|
|
65
|
+
max_bytes: this.options.maxBytes !== undefined ? this.options.maxBytes : -1,
|
|
66
|
+
max_msg_size: this.options.maxMessageSize !== undefined ? this.options.maxMessageSize : -1,
|
|
67
|
+
no_ack: false,
|
|
68
|
+
duplicate_window: (0, nats_1.nanos)(this.options.duplicateWindowMs ? this.options.duplicateWindowMs : 0)
|
|
69
|
+
};
|
|
28
70
|
if (!streamName) {
|
|
71
|
+
//Add stream
|
|
29
72
|
const streamInfo = await this.jetStreamManager.streams.add({
|
|
30
73
|
name: this.streamName,
|
|
31
|
-
|
|
32
|
-
retention: nats_1.RetentionPolicy.Workqueue,
|
|
33
|
-
max_msgs: -1,
|
|
34
|
-
max_age: 0,
|
|
35
|
-
max_bytes: -1,
|
|
36
|
-
max_msg_size: -1,
|
|
37
|
-
no_ack: false
|
|
74
|
+
...streamConfig
|
|
38
75
|
});
|
|
39
76
|
streamName = streamInfo.config.name;
|
|
40
77
|
}
|
|
78
|
+
else {
|
|
79
|
+
//Update stream
|
|
80
|
+
let streamInfo = await this.jetStreamManager.streams.info(streamName);
|
|
81
|
+
const updateConfig = {
|
|
82
|
+
...streamInfo.config,
|
|
83
|
+
...streamConfig
|
|
84
|
+
};
|
|
85
|
+
streamInfo = await this.jetStreamManager.streams.update(streamName, updateConfig);
|
|
86
|
+
streamName = streamInfo.config.name;
|
|
87
|
+
}
|
|
41
88
|
if (this.handler) {
|
|
42
89
|
const consumerInfo = await this.jetStreamManager.consumers.add(streamName, {
|
|
43
90
|
durable_name: this.streamName,
|
|
@@ -46,15 +93,25 @@ class Task extends lakutata_1.Provider {
|
|
|
46
93
|
deliver_group: this.streamName
|
|
47
94
|
});
|
|
48
95
|
const consumer = await this.jetStream.consumers.get(consumerInfo.stream_name, consumerInfo.name);
|
|
96
|
+
const concurrentTask = this.options.concurrentTask || 1;
|
|
49
97
|
setImmediate(async () => {
|
|
50
98
|
while (this.#requestTask) {
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
99
|
+
const msgs = await consumer.consume({ max_messages: concurrentTask });
|
|
100
|
+
const batchTasks = [];
|
|
101
|
+
for await (const msg of msgs) {
|
|
102
|
+
batchTasks.push(new Promise(async (resolve, reject) => {
|
|
103
|
+
try {
|
|
104
|
+
await this.handler(this.codec.decode(msg.data));
|
|
105
|
+
msg.ack();
|
|
106
|
+
return resolve();
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
msg.nak();
|
|
110
|
+
return reject(e);
|
|
111
|
+
}
|
|
112
|
+
}));
|
|
55
113
|
}
|
|
56
|
-
await
|
|
57
|
-
msg.ack();
|
|
114
|
+
await Promise.all(batchTasks);
|
|
58
115
|
}
|
|
59
116
|
await consumer.delete();
|
|
60
117
|
});
|
|
@@ -82,12 +139,12 @@ class Task extends lakutata_1.Provider {
|
|
|
82
139
|
/**
|
|
83
140
|
* Publish task
|
|
84
141
|
* @param payload
|
|
142
|
+
* @param id
|
|
85
143
|
*/
|
|
86
|
-
async publish(payload) {
|
|
87
|
-
await this.jetStream.publish(this.subject, this.codec.encode(payload));
|
|
144
|
+
async publish(payload, id) {
|
|
145
|
+
await this.jetStream.publish(this.subject, this.codec.encode(payload), { msgID: id });
|
|
88
146
|
}
|
|
89
147
|
}
|
|
90
|
-
exports.Task = Task;
|
|
91
148
|
__decorate([
|
|
92
149
|
(0, di_1.Configurable)(),
|
|
93
150
|
__metadata("design:type", Object)
|
|
@@ -100,6 +157,10 @@ __decorate([
|
|
|
100
157
|
(0, di_1.Configurable)(lakutata_1.DTO.String().required()),
|
|
101
158
|
__metadata("design:type", String)
|
|
102
159
|
], Task.prototype, "subject", void 0);
|
|
160
|
+
__decorate([
|
|
161
|
+
(0, di_1.Configurable)(TaskOptions.Schema().default({})),
|
|
162
|
+
__metadata("design:type", TaskOptions)
|
|
163
|
+
], Task.prototype, "options", void 0);
|
|
103
164
|
__decorate([
|
|
104
165
|
(0, di_1.Configurable)(lakutata_1.DTO.Function().optional()),
|
|
105
166
|
__metadata("design:type", Function)
|
|
@@ -111,3 +172,4 @@ __decorate([
|
|
|
111
172
|
}).required()),
|
|
112
173
|
__metadata("design:type", Object)
|
|
113
174
|
], Task.prototype, "codec", void 0);
|
|
175
|
+
exports.default = Task;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lakutata/nats",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "Lakutata NATS Client",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lakutata",
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"lakutata": "^2.0.119",
|
|
33
33
|
"nats": "^2.29.3"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "86e17bba9fee65388de9e6ae8343fbded81404a0"
|
|
36
36
|
}
|