@lakutata/nats 1.5.2 → 1.6.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 +12 -0
- package/dist/CommonExports.d.ts +1 -0
- package/dist/CommonExports.d.ts.map +1 -1
- package/dist/CommonExports.js +3 -1
- package/dist/components/NATS.d.ts +7 -0
- package/dist/components/NATS.d.ts.map +1 -1
- package/dist/components/NATS.js +15 -0
- package/dist/providers/Task.d.ts +36 -0
- package/dist/providers/Task.d.ts.map +1 -0
- package/dist/providers/Task.js +113 -0
- package/dist/tests/NatsTest.spec.js +11 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
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.0](https://github.com/lakutata/lakutata-packages/compare/@lakutata/nats@1.5.2...@lakutata/nats@1.6.0) (2026-01-16)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **nats:** add task provider and update NATS component ([3ec7114](https://github.com/lakutata/lakutata-packages/commit/3ec7114af0aed0e548728339b44d21bc42e0e210))
|
|
12
|
+
* **nats:** add Task provider to CommonExports ([ad07ee9](https://github.com/lakutata/lakutata-packages/commit/ad07ee9cff6306bbc77ccc9ce1fa3c025df04ee5))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
6
18
|
## [1.5.2](https://github.com/lakutata/lakutata-packages/compare/@lakutata/nats@1.5.1...@lakutata/nats@1.5.2) (2026-01-11)
|
|
7
19
|
|
|
8
20
|
**Note:** Version bump only for package @lakutata/nats
|
package/dist/CommonExports.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { SetupNatsServiceEntrypoint } from './entrypoints/SetupNatsServiceEntrypoint';
|
|
2
2
|
export { ServiceProxy, BuildServiceProxy, type BuildServiceProxyOptions } from './providers/ServiceProxy';
|
|
3
|
+
export { Task } from './providers/Task';
|
|
3
4
|
export { NATS, buildNatsClientOptions } from './components/NATS';
|
|
4
5
|
export { JSONCodec } from './codecs/JSONCodec';
|
|
5
6
|
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,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"}
|
|
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;AACrC,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,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
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.BuildServiceProxy = exports.ServiceProxy = exports.SetupNatsServiceEntrypoint = void 0;
|
|
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;
|
|
4
4
|
var SetupNatsServiceEntrypoint_1 = require("./entrypoints/SetupNatsServiceEntrypoint");
|
|
5
5
|
Object.defineProperty(exports, "SetupNatsServiceEntrypoint", { enumerable: true, get: function () { return SetupNatsServiceEntrypoint_1.SetupNatsServiceEntrypoint; } });
|
|
6
6
|
var ServiceProxy_1 = require("./providers/ServiceProxy");
|
|
7
7
|
Object.defineProperty(exports, "ServiceProxy", { enumerable: true, get: function () { return ServiceProxy_1.ServiceProxy; } });
|
|
8
8
|
Object.defineProperty(exports, "BuildServiceProxy", { enumerable: true, get: function () { return ServiceProxy_1.BuildServiceProxy; } });
|
|
9
|
+
var Task_1 = require("./providers/Task");
|
|
10
|
+
Object.defineProperty(exports, "Task", { enumerable: true, get: function () { return Task_1.Task; } });
|
|
9
11
|
var NATS_1 = require("./components/NATS");
|
|
10
12
|
Object.defineProperty(exports, "NATS", { enumerable: true, get: function () { return NATS_1.NATS; } });
|
|
11
13
|
Object.defineProperty(exports, "buildNatsClientOptions", { enumerable: true, get: function () { return NATS_1.buildNatsClientOptions; } });
|
|
@@ -2,6 +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 { Task } from '../providers/Task';
|
|
5
6
|
export declare const buildNatsClientOptions: ComponentOptionsBuilder<NatsClientOptions>;
|
|
6
7
|
export declare class NATS extends Component {
|
|
7
8
|
#private;
|
|
@@ -109,6 +110,12 @@ export declare class NATS extends Component {
|
|
|
109
110
|
* @protected
|
|
110
111
|
*/
|
|
111
112
|
protected destroy(): Promise<void>;
|
|
113
|
+
/**
|
|
114
|
+
* Create task provider
|
|
115
|
+
* @param subject
|
|
116
|
+
* @param handler
|
|
117
|
+
*/
|
|
118
|
+
createTask(subject: string, handler?: (data: any) => void | Promise<void>): Promise<Task>;
|
|
112
119
|
/**
|
|
113
120
|
* Publishes the specified data to the specified subject.
|
|
114
121
|
* @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;
|
|
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,IAAI,EAAC,MAAM,mBAAmB,CAAA;AAEtC,eAAO,MAAM,sBAAsB,EAAE,uBAAuB,CAAC,iBAAiB,CAkB7E,CAAA;AAED,qBAAa,IAAK,SAAQ,SAAS;;IAC/B;;;OAGG;IAEH,SAAS,CAAC,QAAQ,CAA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AG,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
|
@@ -21,6 +21,7 @@ const NatsNoRespondersAvailableException_1 = require("../exceptions/NatsNoRespon
|
|
|
21
21
|
const NatsInternalServerException_1 = require("../exceptions/NatsInternalServerException");
|
|
22
22
|
const ServiceEventCodec_1 = require("../lib/ServiceEventCodec");
|
|
23
23
|
const MessagePackCodec_1 = require("../codecs/MessagePackCodec");
|
|
24
|
+
const Task_1 = require("../providers/Task");
|
|
24
25
|
const buildNatsClientOptions = (options) => {
|
|
25
26
|
return {
|
|
26
27
|
class: NATS,
|
|
@@ -83,6 +84,20 @@ class NATS extends lakutata_1.Component {
|
|
|
83
84
|
async destroy() {
|
|
84
85
|
await this.#conn.close();
|
|
85
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Create task provider
|
|
89
|
+
* @param subject
|
|
90
|
+
* @param handler
|
|
91
|
+
*/
|
|
92
|
+
async createTask(subject, handler) {
|
|
93
|
+
return await this.buildObject(Task_1.Task, {
|
|
94
|
+
jetStreamManager: await this.#conn.jetstreamManager(),
|
|
95
|
+
jetStream: this.#conn.jetstream(),
|
|
96
|
+
codec: this.codec,
|
|
97
|
+
subject: subject,
|
|
98
|
+
handler: handler
|
|
99
|
+
});
|
|
100
|
+
}
|
|
86
101
|
/**
|
|
87
102
|
* Publishes the specified data to the specified subject.
|
|
88
103
|
* @param subject
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Provider } from 'lakutata';
|
|
2
|
+
import { type Codec, type JetStreamClient, type JetStreamManager } from 'nats';
|
|
3
|
+
export declare class Task extends Provider {
|
|
4
|
+
#private;
|
|
5
|
+
protected readonly jetStreamManager: JetStreamManager;
|
|
6
|
+
protected readonly jetStream: JetStreamClient;
|
|
7
|
+
protected readonly subject: string;
|
|
8
|
+
protected readonly handler?: (data: any) => void | Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* NATS message codec
|
|
11
|
+
* @protected
|
|
12
|
+
*/
|
|
13
|
+
protected readonly codec: Codec<unknown>;
|
|
14
|
+
protected get streamName(): string;
|
|
15
|
+
/**
|
|
16
|
+
* Initializer
|
|
17
|
+
* @protected
|
|
18
|
+
*/
|
|
19
|
+
protected init(): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Destroyer
|
|
22
|
+
* @protected
|
|
23
|
+
*/
|
|
24
|
+
protected destroy(): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Get exists stream name
|
|
27
|
+
* @protected
|
|
28
|
+
*/
|
|
29
|
+
protected getExistsStreamName(): Promise<string | null>;
|
|
30
|
+
/**
|
|
31
|
+
* Publish task
|
|
32
|
+
* @param payload
|
|
33
|
+
*/
|
|
34
|
+
publish(payload: any): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=Task.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Task.d.ts","sourceRoot":"","sources":["../../src/providers/Task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAM,QAAQ,EAAC,MAAM,UAAU,CAAA;AAEtC,OAAO,EAEH,KAAK,KAAK,EAIV,KAAK,eAAe,EACpB,KAAK,gBAAgB,EAIxB,MAAM,MAAM,CAAA;AAGb,qBAAa,IAAK,SAAQ,QAAQ;;IAK9B,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,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;IAsCrC;;;OAGG;cACa,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxC;;;OAGG;cACa,mBAAmB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAQ7D;;;OAGG;IACU,OAAO,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;CAGpD"}
|
|
@@ -0,0 +1,113 @@
|
|
|
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.Task = 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
|
+
class Task extends lakutata_1.Provider {
|
|
18
|
+
#requestTask = true;
|
|
19
|
+
get streamName() {
|
|
20
|
+
return (0, helper_1.MD5)(this.subject).toString('hex');
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Initializer
|
|
24
|
+
* @protected
|
|
25
|
+
*/
|
|
26
|
+
async init() {
|
|
27
|
+
let streamName = await this.getExistsStreamName();
|
|
28
|
+
if (!streamName) {
|
|
29
|
+
const streamInfo = await this.jetStreamManager.streams.add({
|
|
30
|
+
name: this.streamName,
|
|
31
|
+
subjects: [this.subject],
|
|
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
|
|
38
|
+
});
|
|
39
|
+
streamName = streamInfo.config.name;
|
|
40
|
+
}
|
|
41
|
+
if (this.handler) {
|
|
42
|
+
const consumerInfo = await this.jetStreamManager.consumers.add(streamName, {
|
|
43
|
+
durable_name: this.streamName,
|
|
44
|
+
deliver_policy: nats_1.DeliverPolicy.All,
|
|
45
|
+
ack_policy: nats_1.AckPolicy.Explicit,
|
|
46
|
+
deliver_group: this.streamName
|
|
47
|
+
});
|
|
48
|
+
const consumer = await this.jetStream.consumers.get(consumerInfo.stream_name, consumerInfo.name);
|
|
49
|
+
setImmediate(async () => {
|
|
50
|
+
while (this.#requestTask) {
|
|
51
|
+
const msg = await consumer.next();
|
|
52
|
+
if (!msg) {
|
|
53
|
+
await (0, helper_1.Delay)(10);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
await this.handler(this.codec.decode(msg.data));
|
|
57
|
+
msg.ack();
|
|
58
|
+
}
|
|
59
|
+
await consumer.delete();
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Destroyer
|
|
65
|
+
* @protected
|
|
66
|
+
*/
|
|
67
|
+
async destroy() {
|
|
68
|
+
this.#requestTask = false;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Get exists stream name
|
|
72
|
+
* @protected
|
|
73
|
+
*/
|
|
74
|
+
async getExistsStreamName() {
|
|
75
|
+
try {
|
|
76
|
+
return await this.jetStreamManager.streams.find(this.subject);
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Publish task
|
|
84
|
+
* @param payload
|
|
85
|
+
*/
|
|
86
|
+
async publish(payload) {
|
|
87
|
+
await this.jetStream.publish(this.subject, this.codec.encode(payload));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.Task = Task;
|
|
91
|
+
__decorate([
|
|
92
|
+
(0, di_1.Configurable)(),
|
|
93
|
+
__metadata("design:type", Object)
|
|
94
|
+
], Task.prototype, "jetStreamManager", void 0);
|
|
95
|
+
__decorate([
|
|
96
|
+
(0, di_1.Configurable)(),
|
|
97
|
+
__metadata("design:type", Object)
|
|
98
|
+
], Task.prototype, "jetStream", void 0);
|
|
99
|
+
__decorate([
|
|
100
|
+
(0, di_1.Configurable)(lakutata_1.DTO.String().required()),
|
|
101
|
+
__metadata("design:type", String)
|
|
102
|
+
], Task.prototype, "subject", void 0);
|
|
103
|
+
__decorate([
|
|
104
|
+
(0, di_1.Configurable)(lakutata_1.DTO.Function().optional()),
|
|
105
|
+
__metadata("design:type", Function)
|
|
106
|
+
], Task.prototype, "handler", void 0);
|
|
107
|
+
__decorate([
|
|
108
|
+
(0, di_1.Configurable)(lakutata_1.DTO.Object({
|
|
109
|
+
encode: lakutata_1.DTO.Function().arity(1).required(),
|
|
110
|
+
decode: lakutata_1.DTO.Function().arity(1).required()
|
|
111
|
+
}).required()),
|
|
112
|
+
__metadata("design:type", Object)
|
|
113
|
+
], Task.prototype, "codec", void 0);
|
|
@@ -62,6 +62,15 @@ 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
|
+
}
|
|
65
74
|
}
|
|
66
75
|
}
|
|
67
76
|
__decorate([
|
|
@@ -112,7 +121,8 @@ lakutata_1.Application.run({
|
|
|
112
121
|
service: (0, CommonExports_1.SetupNatsServiceEntrypoint)('nats')
|
|
113
122
|
}),
|
|
114
123
|
nats: (0, CommonExports_1.buildNatsClientOptions)({
|
|
115
|
-
servers: '127.0.0.1:4222'
|
|
124
|
+
// servers: '127.0.0.1:4222'
|
|
125
|
+
servers: '10.11.11.21:30422'
|
|
116
126
|
}),
|
|
117
127
|
test: {
|
|
118
128
|
class: TestComponent
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lakutata/nats",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Lakutata NATS Client",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lakutata",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"url": "https://github.com/lakutata/lakutata-packages/issues"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"lakutata": "^2.0.
|
|
32
|
+
"lakutata": "^2.0.119",
|
|
33
33
|
"nats": "^2.29.3"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "1437a1996b23ce0459eb6468fa77b35bd0294acd"
|
|
36
36
|
}
|