@rayondigital/nest-dapr 0.9.31 → 0.9.33
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.
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
import { DaprClient } from '@dapr/dapr';
|
|
2
2
|
import { OnApplicationShutdown } from '@nestjs/common';
|
|
3
3
|
import { DaprModuleOptions } from '../dapr.module';
|
|
4
|
+
import { PublishMessage } from './publish.message';
|
|
4
5
|
export declare class DaprPubSubClient implements OnApplicationShutdown {
|
|
5
6
|
private readonly options;
|
|
6
7
|
private readonly daprClient;
|
|
8
|
+
private readonly logger;
|
|
7
9
|
private readonly defaultName;
|
|
8
10
|
private readonly buffer;
|
|
9
11
|
private subscription;
|
|
10
12
|
private readonly bufferSize;
|
|
11
13
|
private readonly bufferTimeSpan;
|
|
14
|
+
private onError;
|
|
12
15
|
constructor(options: DaprModuleOptions, daprClient: DaprClient);
|
|
16
|
+
registerErrorHandler(handler: (messages: PublishMessage[], error: any) => void): void;
|
|
17
|
+
protected handleError(messages: PublishMessage[], error: any): Promise<void>;
|
|
13
18
|
onApplicationShutdown(signal?: string): Promise<void>;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
protected setupBufferSubscription(): void;
|
|
20
|
+
protected publishBulkDirectly(messages: PublishMessage[]): Promise<void>;
|
|
21
|
+
protected publishDirectly(name: string, topic: string, payload: any, producerId?: string, metadata?: any, fireAndForget?: boolean): Promise<void>;
|
|
17
22
|
publish(name: string, producerId: string, topic: string, payload: any, buffer: boolean, metadata?: any): Promise<void>;
|
|
18
23
|
publish(producerId: string, topic: string, payload: any, buffer: boolean, metadata?: any): Promise<void>;
|
|
19
24
|
publish(producerId: string, topic: string, payload: any): Promise<void>;
|
|
25
|
+
publishBulk(name: string, producerId: string, topic: string, payloads: any[], metadata?: any): Promise<void>;
|
|
26
|
+
publishBulk(producerId: string, topic: string, payloads: any[], metadata?: any): Promise<void>;
|
|
27
|
+
publishBulk(producerId: string, topic: string, payloads: any[]): Promise<void>;
|
|
20
28
|
}
|
|
@@ -20,6 +20,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
20
20
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
21
|
});
|
|
22
22
|
};
|
|
23
|
+
var DaprPubSubClient_1;
|
|
23
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
25
|
exports.DaprPubSubClient = void 0;
|
|
25
26
|
const dapr_1 = require("@dapr/dapr");
|
|
@@ -27,17 +28,29 @@ const common_1 = require("@nestjs/common");
|
|
|
27
28
|
const rxjs_1 = require("rxjs");
|
|
28
29
|
const operators_1 = require("rxjs/operators");
|
|
29
30
|
const dapr_module_1 = require("../dapr.module");
|
|
30
|
-
let DaprPubSubClient = class DaprPubSubClient {
|
|
31
|
+
let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
|
|
31
32
|
constructor(options, daprClient) {
|
|
32
33
|
var _a, _b;
|
|
33
34
|
this.options = options;
|
|
34
35
|
this.daprClient = daprClient;
|
|
36
|
+
this.logger = new common_1.Logger(DaprPubSubClient_1.name);
|
|
35
37
|
this.buffer = new rxjs_1.Subject();
|
|
36
38
|
this.bufferSize = 10;
|
|
37
39
|
this.bufferTimeSpan = 1000;
|
|
38
40
|
this.defaultName = (_b = (_a = this.options.pubsubOptions) === null || _a === void 0 ? void 0 : _a.defaultName) !== null && _b !== void 0 ? _b : 'pubsub';
|
|
39
41
|
this.setupBufferSubscription();
|
|
40
42
|
}
|
|
43
|
+
registerErrorHandler(handler) {
|
|
44
|
+
this.onError = handler;
|
|
45
|
+
}
|
|
46
|
+
handleError(messages, error) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
if (this.onError) {
|
|
49
|
+
yield this.onError(messages, error);
|
|
50
|
+
}
|
|
51
|
+
this.logger.error(`Error publishing ${messages.length ? 'message' : 'messages'} to pubsub`, error);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
41
54
|
onApplicationShutdown(signal) {
|
|
42
55
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43
56
|
this.subscription.unsubscribe();
|
|
@@ -95,28 +108,38 @@ let DaprPubSubClient = class DaprPubSubClient {
|
|
|
95
108
|
yield this.publishDirectly(name, topic, messages[0].payload, producerId, messages[0].metadata);
|
|
96
109
|
continue;
|
|
97
110
|
}
|
|
98
|
-
|
|
111
|
+
try {
|
|
112
|
+
yield this.daprClient.pubsub.publishBulk(name, topic, messages.map((m) => m.payload), producerId ? { metadata: { partitionKey: producerId } } : undefined);
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
yield this.handleError(messages, error);
|
|
116
|
+
}
|
|
99
117
|
}
|
|
100
118
|
});
|
|
101
119
|
}
|
|
102
120
|
publishDirectly(name, topic, payload, producerId, metadata, fireAndForget = false) {
|
|
103
121
|
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
-
|
|
105
|
-
name
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
122
|
+
try {
|
|
123
|
+
if (!name)
|
|
124
|
+
name = this.defaultName;
|
|
125
|
+
const options = {};
|
|
126
|
+
if (metadata) {
|
|
127
|
+
options['metadata'] = metadata;
|
|
128
|
+
}
|
|
129
|
+
if (producerId) {
|
|
130
|
+
options['metadata'] = Object.assign({ partitionKey: producerId }, metadata);
|
|
131
|
+
}
|
|
132
|
+
if (fireAndForget) {
|
|
133
|
+
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
yield this.daprClient.pubsub.publish(name, topic, payload, options);
|
|
135
|
+
}));
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
yield this.daprClient.pubsub.publish(name, topic, payload, options);
|
|
112
139
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
yield this.daprClient.pubsub.publish(name, topic, payload, options);
|
|
116
|
-
}));
|
|
117
|
-
return;
|
|
140
|
+
catch (error) {
|
|
141
|
+
yield this.handleError([{ producerId, name, topic, payload, metadata }], error);
|
|
118
142
|
}
|
|
119
|
-
yield this.daprClient.pubsub.publish(name, topic, payload, options);
|
|
120
143
|
});
|
|
121
144
|
}
|
|
122
145
|
publish(...args) {
|
|
@@ -143,8 +166,37 @@ let DaprPubSubClient = class DaprPubSubClient {
|
|
|
143
166
|
yield this.publishDirectly(name, topic, payload, producerId, true);
|
|
144
167
|
});
|
|
145
168
|
}
|
|
169
|
+
publishBulk(...args) {
|
|
170
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
171
|
+
let name;
|
|
172
|
+
let producerId;
|
|
173
|
+
let topic;
|
|
174
|
+
let payloads;
|
|
175
|
+
let metadata;
|
|
176
|
+
if (args.length === 5) {
|
|
177
|
+
[name, producerId, topic, payloads, metadata] = args;
|
|
178
|
+
}
|
|
179
|
+
else if (args.length === 4) {
|
|
180
|
+
[producerId, topic, payloads, metadata] = args;
|
|
181
|
+
name = this.defaultName;
|
|
182
|
+
}
|
|
183
|
+
else if (args.length === 3) {
|
|
184
|
+
[producerId, topic, payloads] = args;
|
|
185
|
+
name = this.defaultName;
|
|
186
|
+
}
|
|
187
|
+
if (!name)
|
|
188
|
+
name = this.defaultName;
|
|
189
|
+
if (payloads.length === 1) {
|
|
190
|
+
yield this.publishDirectly(name, topic, payloads[0], producerId, metadata);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
for (const payload of payloads) {
|
|
194
|
+
this.buffer.next({ name, producerId, topic, payload, metadata });
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
}
|
|
146
198
|
};
|
|
147
|
-
DaprPubSubClient = __decorate([
|
|
199
|
+
DaprPubSubClient = DaprPubSubClient_1 = __decorate([
|
|
148
200
|
(0, common_1.Injectable)(),
|
|
149
201
|
__param(0, (0, common_1.Inject)(dapr_module_1.DAPR_MODULE_OPTIONS_TOKEN)),
|
|
150
202
|
__metadata("design:paramtypes", [Object, dapr_1.DaprClient])
|
package/package.json
CHANGED