@lakutata/nats 1.6.2 → 2.0.0
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 +16 -0
- package/dist/CommonExports.d.ts +0 -2
- package/dist/CommonExports.d.ts.map +1 -1
- package/dist/CommonExports.js +1 -8
- package/dist/components/NATS.d.ts +0 -8
- package/dist/components/NATS.d.ts.map +1 -1
- package/dist/components/NATS.js +0 -20
- package/dist/tests/NatsTest.spec.js +0 -9
- package/package.json +2 -2
- package/dist/providers/Task.d.ts +0 -48
- package/dist/providers/Task.d.ts.map +0 -1
- package/dist/providers/Task.js +0 -201
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
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
|
+
# [2.0.0](https://github.com/lakutata/lakutata-packages/compare/@lakutata/nats@1.6.2...@lakutata/nats@2.0.0) (2026-03-02)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Code Refactoring
|
|
10
|
+
|
|
11
|
+
* **nats:** remove Task provider and simplify NATS component ([7eb57ac](https://github.com/lakutata/lakutata-packages/commit/7eb57ac4f7b89c1619a3042cbaca8869c0a8f8d2))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### BREAKING CHANGES
|
|
15
|
+
|
|
16
|
+
* **nats:** Task provider and related exports have been removed. Applications using the Task functionality will need to implement their own task management solution.
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
6
22
|
## [1.6.2](https://github.com/lakutata/lakutata-packages/compare/@lakutata/nats@1.6.1...@lakutata/nats@1.6.2) (2026-01-17)
|
|
7
23
|
|
|
8
24
|
**Note:** Version bump only for package @lakutata/nats
|
package/dist/CommonExports.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
export { SetupNatsServiceEntrypoint } from './entrypoints/SetupNatsServiceEntrypoint';
|
|
2
2
|
export { ServiceProxy, BuildServiceProxy, type BuildServiceProxyOptions } from './providers/ServiceProxy';
|
|
3
|
-
export { TaskOptions } from './providers/Task';
|
|
4
|
-
export { default as Task } from './providers/Task';
|
|
5
3
|
export { RetentionPolicy } from 'nats';
|
|
6
4
|
export { NATS, buildNatsClientOptions } from './components/NATS';
|
|
7
5
|
export { JSONCodec } from './codecs/JSONCodec';
|
|
@@ -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,
|
|
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,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,18 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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.
|
|
3
|
+
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.BuildServiceProxy = exports.ServiceProxy = exports.SetupNatsServiceEntrypoint = void 0;
|
|
7
4
|
var SetupNatsServiceEntrypoint_1 = require("./entrypoints/SetupNatsServiceEntrypoint");
|
|
8
5
|
Object.defineProperty(exports, "SetupNatsServiceEntrypoint", { enumerable: true, get: function () { return SetupNatsServiceEntrypoint_1.SetupNatsServiceEntrypoint; } });
|
|
9
6
|
var ServiceProxy_1 = require("./providers/ServiceProxy");
|
|
10
7
|
Object.defineProperty(exports, "ServiceProxy", { enumerable: true, get: function () { return ServiceProxy_1.ServiceProxy; } });
|
|
11
8
|
Object.defineProperty(exports, "BuildServiceProxy", { enumerable: true, get: function () { return ServiceProxy_1.BuildServiceProxy; } });
|
|
12
|
-
var Task_1 = require("./providers/Task");
|
|
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
9
|
var nats_1 = require("nats");
|
|
17
10
|
Object.defineProperty(exports, "RetentionPolicy", { enumerable: true, get: function () { return nats_1.RetentionPolicy; } });
|
|
18
11
|
var NATS_1 = require("./components/NATS");
|
|
@@ -2,7 +2,6 @@ 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 Task, { TaskOptions } from '../providers/Task';
|
|
6
5
|
export declare const buildNatsClientOptions: ComponentOptionsBuilder<NatsClientOptions>;
|
|
7
6
|
export declare class NATS extends Component {
|
|
8
7
|
#private;
|
|
@@ -110,13 +109,6 @@ export declare class NATS extends Component {
|
|
|
110
109
|
* @protected
|
|
111
110
|
*/
|
|
112
111
|
protected destroy(): Promise<void>;
|
|
113
|
-
/**
|
|
114
|
-
* Create task provider
|
|
115
|
-
* @param subject
|
|
116
|
-
* @param handler
|
|
117
|
-
* @param options
|
|
118
|
-
*/
|
|
119
|
-
createTask(subject: string, handler?: (data: any) => void | Promise<void>, options?: TaskOptions): Promise<Task>;
|
|
120
112
|
/**
|
|
121
113
|
* Publishes the specified data to the specified subject.
|
|
122
114
|
* @param subject
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NATS.d.ts","sourceRoot":"","sources":["../../src/components/NATS.ts"],"names":[],"mappings":"AAAA,O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AC,IAAI,EAAE,GAAG,KAAK,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,EAAE,gBAAgB,CAAC,EAAE,gBAAgB,GAAG,YAAY;IAwBjI;;;;OAIG;IACI,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,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,9 +8,6 @@ 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
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
exports.NATS = exports.buildNatsClientOptions = void 0;
|
|
16
13
|
const lakutata_1 = require("lakutata");
|
|
@@ -24,7 +21,6 @@ const NatsNoRespondersAvailableException_1 = require("../exceptions/NatsNoRespon
|
|
|
24
21
|
const NatsInternalServerException_1 = require("../exceptions/NatsInternalServerException");
|
|
25
22
|
const ServiceEventCodec_1 = require("../lib/ServiceEventCodec");
|
|
26
23
|
const MessagePackCodec_1 = require("../codecs/MessagePackCodec");
|
|
27
|
-
const Task_1 = __importDefault(require("../providers/Task"));
|
|
28
24
|
const buildNatsClientOptions = (options) => {
|
|
29
25
|
return {
|
|
30
26
|
class: NATS,
|
|
@@ -87,22 +83,6 @@ class NATS extends lakutata_1.Component {
|
|
|
87
83
|
async destroy() {
|
|
88
84
|
await this.#conn.close();
|
|
89
85
|
}
|
|
90
|
-
/**
|
|
91
|
-
* Create task provider
|
|
92
|
-
* @param subject
|
|
93
|
-
* @param handler
|
|
94
|
-
* @param options
|
|
95
|
-
*/
|
|
96
|
-
async createTask(subject, handler, options) {
|
|
97
|
-
return await this.buildObject(Task_1.default, {
|
|
98
|
-
jetStreamManager: await this.#conn.jetstreamManager(),
|
|
99
|
-
jetStream: this.#conn.jetstream(),
|
|
100
|
-
codec: this.codec,
|
|
101
|
-
options: options || {},
|
|
102
|
-
subject: subject,
|
|
103
|
-
handler: handler
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
86
|
/**
|
|
107
87
|
* Publishes the specified data to the specified subject.
|
|
108
88
|
* @param subject
|
|
@@ -62,15 +62,6 @@ class TestComponent extends lakutata_1.Component {
|
|
|
62
62
|
// console.error(JSON.parse(JSON.stringify(e)))
|
|
63
63
|
console.error(e);
|
|
64
64
|
}
|
|
65
|
-
try {
|
|
66
|
-
const task = await this.nats.createTask('tasks.test1', async (data) => {
|
|
67
|
-
console.log('task2:', data);
|
|
68
|
-
});
|
|
69
|
-
await task.publish({ time: Date.now() });
|
|
70
|
-
}
|
|
71
|
-
catch (e) {
|
|
72
|
-
console.error(e);
|
|
73
|
-
}
|
|
74
65
|
}
|
|
75
66
|
}
|
|
76
67
|
__decorate([
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lakutata/nats",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
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": "915ec114a0bc9bbfb7fd352b53189f085b6989c1"
|
|
36
36
|
}
|
package/dist/providers/Task.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
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 {
|
|
13
|
-
#private;
|
|
14
|
-
protected readonly jetStreamManager: JetStreamManager;
|
|
15
|
-
protected readonly jetStream: JetStreamClient;
|
|
16
|
-
protected readonly subject: string;
|
|
17
|
-
protected readonly options: TaskOptions;
|
|
18
|
-
protected readonly handler?: (data: any) => void | Promise<void>;
|
|
19
|
-
/**
|
|
20
|
-
* NATS message codec
|
|
21
|
-
* @protected
|
|
22
|
-
*/
|
|
23
|
-
protected readonly codec: Codec<unknown>;
|
|
24
|
-
protected get streamName(): string;
|
|
25
|
-
/**
|
|
26
|
-
* Initializer
|
|
27
|
-
* @protected
|
|
28
|
-
*/
|
|
29
|
-
protected init(): Promise<void>;
|
|
30
|
-
/**
|
|
31
|
-
* Destroyer
|
|
32
|
-
* @protected
|
|
33
|
-
*/
|
|
34
|
-
protected destroy(): Promise<void>;
|
|
35
|
-
/**
|
|
36
|
-
* Get exists stream name
|
|
37
|
-
* @protected
|
|
38
|
-
*/
|
|
39
|
-
protected getExistsStreamName(): Promise<string | null>;
|
|
40
|
-
/**
|
|
41
|
-
* Publish task
|
|
42
|
-
* @param payload
|
|
43
|
-
* @param id
|
|
44
|
-
*/
|
|
45
|
-
publish(payload: any, id?: string): Promise<void>;
|
|
46
|
-
}
|
|
47
|
-
export default Task;
|
|
48
|
-
//# sourceMappingURL=Task.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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;IAwFrC;;;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
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.TaskOptions = void 0;
|
|
13
|
-
const lakutata_1 = require("lakutata");
|
|
14
|
-
const di_1 = require("lakutata/decorator/di");
|
|
15
|
-
const nats_1 = require("nats");
|
|
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);
|
|
49
|
-
class Task extends lakutata_1.Provider {
|
|
50
|
-
#requestTask = true;
|
|
51
|
-
get streamName() {
|
|
52
|
-
return (0, helper_1.MD5)(this.subject).toString('hex');
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Initializer
|
|
56
|
-
* @protected
|
|
57
|
-
*/
|
|
58
|
-
async init() {
|
|
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
|
-
};
|
|
70
|
-
if (!streamName) {
|
|
71
|
-
//Add stream
|
|
72
|
-
const streamInfo = await this.jetStreamManager.streams.add({
|
|
73
|
-
name: this.streamName,
|
|
74
|
-
...streamConfig
|
|
75
|
-
});
|
|
76
|
-
streamName = streamInfo.config.name;
|
|
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
|
-
}
|
|
88
|
-
if (this.handler) {
|
|
89
|
-
const consumerInfo = await this.jetStreamManager.consumers.add(streamName, {
|
|
90
|
-
durable_name: this.streamName,
|
|
91
|
-
deliver_policy: nats_1.DeliverPolicy.All,
|
|
92
|
-
ack_policy: nats_1.AckPolicy.Explicit,
|
|
93
|
-
deliver_group: this.streamName
|
|
94
|
-
});
|
|
95
|
-
const consumer = await this.jetStream.consumers.get(consumerInfo.stream_name, consumerInfo.name);
|
|
96
|
-
const concurrentTask = this.options.concurrentTask || 1;
|
|
97
|
-
// setImmediate(async () => {
|
|
98
|
-
// while (this.#requestTask) {
|
|
99
|
-
// const msgs: ConsumerMessages = await consumer.consume({max_messages: concurrentTask})
|
|
100
|
-
// const batchTasks: Promise<void>[] = []
|
|
101
|
-
// for await (const msg of msgs) {
|
|
102
|
-
// batchTasks.push(new Promise<void>(async (resolve, reject) => {
|
|
103
|
-
// try {
|
|
104
|
-
// await this.handler!(this.codec.decode(msg.data))
|
|
105
|
-
// msg.ack()
|
|
106
|
-
// return resolve()
|
|
107
|
-
// } catch (e) {
|
|
108
|
-
// msg.nak()
|
|
109
|
-
// return reject(e)
|
|
110
|
-
// }
|
|
111
|
-
// }))
|
|
112
|
-
// }
|
|
113
|
-
// await Promise.all(batchTasks)
|
|
114
|
-
// }
|
|
115
|
-
// await consumer.delete()
|
|
116
|
-
// })
|
|
117
|
-
const taskSet = new Set();
|
|
118
|
-
setImmediate(async () => {
|
|
119
|
-
while (this.#requestTask) {
|
|
120
|
-
if (taskSet.size >= concurrentTask) {
|
|
121
|
-
await (0, helper_1.Delay)(10);
|
|
122
|
-
continue;
|
|
123
|
-
}
|
|
124
|
-
const msg = await consumer.next();
|
|
125
|
-
if (!msg) {
|
|
126
|
-
await (0, helper_1.Delay)(10);
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
const task = new Promise(async (resolve, reject) => {
|
|
130
|
-
try {
|
|
131
|
-
await this.handler(this.codec.decode(msg.data));
|
|
132
|
-
msg.ack();
|
|
133
|
-
taskSet.delete(task);
|
|
134
|
-
return resolve();
|
|
135
|
-
}
|
|
136
|
-
catch (e) {
|
|
137
|
-
return reject(e);
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
taskSet.add(task);
|
|
141
|
-
}
|
|
142
|
-
await consumer.delete();
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Destroyer
|
|
148
|
-
* @protected
|
|
149
|
-
*/
|
|
150
|
-
async destroy() {
|
|
151
|
-
this.#requestTask = false;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Get exists stream name
|
|
155
|
-
* @protected
|
|
156
|
-
*/
|
|
157
|
-
async getExistsStreamName() {
|
|
158
|
-
try {
|
|
159
|
-
return await this.jetStreamManager.streams.find(this.subject);
|
|
160
|
-
}
|
|
161
|
-
catch (e) {
|
|
162
|
-
return null;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Publish task
|
|
167
|
-
* @param payload
|
|
168
|
-
* @param id
|
|
169
|
-
*/
|
|
170
|
-
async publish(payload, id) {
|
|
171
|
-
await this.jetStream.publish(this.subject, this.codec.encode(payload), { msgID: id });
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
__decorate([
|
|
175
|
-
(0, di_1.Configurable)(),
|
|
176
|
-
__metadata("design:type", Object)
|
|
177
|
-
], Task.prototype, "jetStreamManager", void 0);
|
|
178
|
-
__decorate([
|
|
179
|
-
(0, di_1.Configurable)(),
|
|
180
|
-
__metadata("design:type", Object)
|
|
181
|
-
], Task.prototype, "jetStream", void 0);
|
|
182
|
-
__decorate([
|
|
183
|
-
(0, di_1.Configurable)(lakutata_1.DTO.String().required()),
|
|
184
|
-
__metadata("design:type", String)
|
|
185
|
-
], Task.prototype, "subject", void 0);
|
|
186
|
-
__decorate([
|
|
187
|
-
(0, di_1.Configurable)(TaskOptions.Schema().default({})),
|
|
188
|
-
__metadata("design:type", TaskOptions)
|
|
189
|
-
], Task.prototype, "options", void 0);
|
|
190
|
-
__decorate([
|
|
191
|
-
(0, di_1.Configurable)(lakutata_1.DTO.Function().optional()),
|
|
192
|
-
__metadata("design:type", Function)
|
|
193
|
-
], Task.prototype, "handler", void 0);
|
|
194
|
-
__decorate([
|
|
195
|
-
(0, di_1.Configurable)(lakutata_1.DTO.Object({
|
|
196
|
-
encode: lakutata_1.DTO.Function().arity(1).required(),
|
|
197
|
-
decode: lakutata_1.DTO.Function().arity(1).required()
|
|
198
|
-
}).required()),
|
|
199
|
-
__metadata("design:type", Object)
|
|
200
|
-
], Task.prototype, "codec", void 0);
|
|
201
|
-
exports.default = Task;
|