@rayondigital/nest-dapr 0.9.48 → 0.9.50
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.
|
@@ -17,12 +17,8 @@ export declare class DaprPubSubClient implements OnApplicationShutdown {
|
|
|
17
17
|
onApplicationShutdown(signal?: string): Promise<void>;
|
|
18
18
|
protected setupBufferSubscription(): void;
|
|
19
19
|
protected publishBulkDirectly(messages: PublishMessage[]): Promise<void>;
|
|
20
|
-
protected publishDirectly(
|
|
21
|
-
publish(
|
|
22
|
-
|
|
23
|
-
publish(id: string, producerId: string, topic: string, payload: any): Promise<boolean>;
|
|
24
|
-
publishBulk(name: string, producerId: string, topic: string, payloads: any[], metadata?: any, contentType?: string): Promise<boolean>;
|
|
25
|
-
publishBulk(producerId: string, topic: string, payloads: any[], metadata?: any, contentType?: string): Promise<boolean>;
|
|
26
|
-
publishBulk(producerId: string, topic: string, payloads: any[]): Promise<boolean>;
|
|
20
|
+
protected publishDirectly(pubSubName: string, topic: string, payload: any, producerId?: string, metadata?: any, fireAndForget?: boolean, contentType?: string): Promise<boolean>;
|
|
21
|
+
publish(pubSubName: string, producerId: string, topic: string, payload: any, buffer?: boolean, metadata?: any, contentType?: string): Promise<boolean>;
|
|
22
|
+
publishBulk(pubSubName: string, producerId: string, topic: string, payloads: any[], metadata?: any, contentType?: string): Promise<boolean>;
|
|
27
23
|
private getMessageId;
|
|
28
24
|
}
|
|
@@ -89,11 +89,11 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
|
|
|
89
89
|
return __awaiter(this, void 0, void 0, function* () {
|
|
90
90
|
if (messages.length === 1) {
|
|
91
91
|
const message = messages[0];
|
|
92
|
-
yield this.publishDirectly(message.
|
|
92
|
+
yield this.publishDirectly(message.pubSubName, message.topic, message.payload, message.producerId, message.metadata, false, message.contentType);
|
|
93
93
|
return;
|
|
94
94
|
}
|
|
95
95
|
const grouped = messages.reduce((acc, message) => {
|
|
96
|
-
const key = `${message.
|
|
96
|
+
const key = `${message.pubSubName}:${message.topic}:${message.producerId}`;
|
|
97
97
|
if (!acc[key]) {
|
|
98
98
|
acc[key] = [];
|
|
99
99
|
}
|
|
@@ -101,24 +101,23 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
|
|
|
101
101
|
return acc;
|
|
102
102
|
}, {});
|
|
103
103
|
for (const key in grouped) {
|
|
104
|
-
const [
|
|
104
|
+
const [pubSubName, topic, producerId] = key.split(':');
|
|
105
105
|
const messages = grouped[key];
|
|
106
106
|
if (messages.length === 1) {
|
|
107
|
-
yield this.publishDirectly(
|
|
107
|
+
yield this.publishDirectly(pubSubName, topic, messages[0].payload, producerId, messages[0].metadata, false, messages[0].contentType);
|
|
108
108
|
continue;
|
|
109
109
|
}
|
|
110
110
|
try {
|
|
111
111
|
const contentType = (_a = messages[0].contentType) !== null && _a !== void 0 ? _a : 'application/json';
|
|
112
|
-
const response = yield this.daprClient.pubsub.publishBulk(
|
|
112
|
+
const response = yield this.daprClient.pubsub.publishBulk(pubSubName, topic, messages.map((m) => m.payload), producerId ? { metadata: { partitionKey: producerId, PartitionKey: producerId }, contentType } : undefined);
|
|
113
113
|
if (response !== undefined && response.failedMessages && response.failedMessages.length > 0) {
|
|
114
114
|
const error = (_c = (_b = response.failedMessages[0]) === null || _b === void 0 ? void 0 : _b.error) !== null && _c !== void 0 ? _c : new Error('Unable to publish message');
|
|
115
|
-
const failedMessages = response.failedMessages.map((m
|
|
115
|
+
const failedMessages = response.failedMessages.map((m) => {
|
|
116
116
|
var _a;
|
|
117
|
-
const messageId = this.getMessageId(m.message.event, m.message.entryID);
|
|
118
117
|
return {
|
|
119
|
-
|
|
120
|
-
name,
|
|
118
|
+
pubSubName: pubSubName,
|
|
121
119
|
topic,
|
|
120
|
+
producerId,
|
|
122
121
|
payload: m.message.event,
|
|
123
122
|
metadata: m.message.metadata,
|
|
124
123
|
contentType: (_a = m.message.contentType) !== null && _a !== void 0 ? _a : contentType,
|
|
@@ -133,11 +132,11 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
|
|
|
133
132
|
}
|
|
134
133
|
});
|
|
135
134
|
}
|
|
136
|
-
publishDirectly(
|
|
135
|
+
publishDirectly(pubSubName, topic, payload, producerId, metadata, fireAndForget = false, contentType) {
|
|
137
136
|
return __awaiter(this, void 0, void 0, function* () {
|
|
138
137
|
try {
|
|
139
|
-
if (!
|
|
140
|
-
|
|
138
|
+
if (!pubSubName)
|
|
139
|
+
pubSubName = this.defaultName;
|
|
141
140
|
if (!contentType)
|
|
142
141
|
contentType = 'application/json';
|
|
143
142
|
const options = {
|
|
@@ -147,94 +146,60 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
|
|
|
147
146
|
options['metadata'] = metadata;
|
|
148
147
|
}
|
|
149
148
|
if (producerId) {
|
|
150
|
-
options['metadata'] = Object.assign({ partitionKey: producerId }, metadata);
|
|
149
|
+
options['metadata'] = Object.assign({ partitionKey: producerId, PartitionKey: producerId }, metadata);
|
|
151
150
|
}
|
|
152
151
|
if (fireAndForget) {
|
|
153
152
|
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
154
153
|
try {
|
|
155
|
-
const response = yield this.daprClient.pubsub.publish(
|
|
154
|
+
const response = yield this.daprClient.pubsub.publish(pubSubName, topic, payload, options);
|
|
156
155
|
if (response !== undefined && response.error) {
|
|
157
156
|
throw response.error;
|
|
158
157
|
}
|
|
159
158
|
}
|
|
160
159
|
catch (error) {
|
|
161
|
-
yield this.handleError([{
|
|
160
|
+
yield this.handleError([{ producerId, pubSubName, topic, payload, metadata }], error);
|
|
162
161
|
return false;
|
|
163
162
|
}
|
|
164
163
|
}));
|
|
165
164
|
return true;
|
|
166
165
|
}
|
|
167
|
-
const response = yield this.daprClient.pubsub.publish(
|
|
166
|
+
const response = yield this.daprClient.pubsub.publish(pubSubName, topic, payload, options);
|
|
168
167
|
if (response !== undefined && response.error) {
|
|
169
168
|
throw response.error;
|
|
170
169
|
}
|
|
171
170
|
return true;
|
|
172
171
|
}
|
|
173
172
|
catch (error) {
|
|
174
|
-
yield this.handleError([{
|
|
173
|
+
yield this.handleError([{ producerId, pubSubName, topic, payload, metadata }], error);
|
|
175
174
|
return false;
|
|
176
175
|
}
|
|
177
176
|
});
|
|
178
177
|
}
|
|
179
|
-
publish(
|
|
178
|
+
publish(pubSubName, producerId, topic, payload, buffer = true, metadata, contentType) {
|
|
180
179
|
return __awaiter(this, void 0, void 0, function* () {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
let producerId;
|
|
184
|
-
let topic;
|
|
185
|
-
let payload;
|
|
186
|
-
let buffer;
|
|
187
|
-
let metadata;
|
|
188
|
-
let contentType;
|
|
189
|
-
if (args.length === 8) {
|
|
190
|
-
[id, name, producerId, topic, payload, buffer, metadata, contentType] = args;
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
[id, producerId, topic, payload, buffer, metadata, contentType] = args;
|
|
194
|
-
name = this.defaultName;
|
|
195
|
-
}
|
|
196
|
-
if (!name)
|
|
197
|
-
name = this.defaultName;
|
|
180
|
+
if (!pubSubName)
|
|
181
|
+
pubSubName = this.defaultName;
|
|
198
182
|
if (!contentType)
|
|
199
183
|
contentType = 'application/json';
|
|
200
184
|
if (buffer === undefined || buffer) {
|
|
201
|
-
this.buffer.next({
|
|
185
|
+
this.buffer.next({ pubSubName, producerId, topic, payload, metadata, contentType });
|
|
202
186
|
return;
|
|
203
187
|
}
|
|
204
|
-
return yield this.publishDirectly(
|
|
188
|
+
return yield this.publishDirectly(pubSubName, topic, payload, producerId, metadata, true, contentType);
|
|
205
189
|
});
|
|
206
190
|
}
|
|
207
|
-
publishBulk(
|
|
191
|
+
publishBulk(pubSubName, producerId, topic, payloads, metadata, contentType) {
|
|
208
192
|
return __awaiter(this, void 0, void 0, function* () {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
let topic;
|
|
212
|
-
let payloads;
|
|
213
|
-
let metadata;
|
|
214
|
-
let contentType;
|
|
215
|
-
if (args.length === 6) {
|
|
216
|
-
[name, producerId, topic, payloads, metadata, contentType] = args;
|
|
217
|
-
}
|
|
218
|
-
else if (args.length === 5) {
|
|
219
|
-
[producerId, topic, payloads, metadata, contentType] = args;
|
|
220
|
-
name = this.defaultName;
|
|
221
|
-
}
|
|
222
|
-
else {
|
|
223
|
-
[producerId, topic, payloads] = args;
|
|
224
|
-
name = this.defaultName;
|
|
225
|
-
}
|
|
226
|
-
if (!name)
|
|
227
|
-
name = this.defaultName;
|
|
193
|
+
if (!pubSubName)
|
|
194
|
+
pubSubName = this.defaultName;
|
|
228
195
|
if (!contentType)
|
|
229
196
|
contentType = 'application/json';
|
|
230
197
|
if (payloads.length === 1) {
|
|
231
|
-
|
|
232
|
-
return yield this.publishDirectly(messageId, name, topic, payloads[0], producerId, metadata, true, contentType);
|
|
198
|
+
return yield this.publishDirectly(pubSubName, topic, payloads[0], producerId, metadata, true, contentType);
|
|
233
199
|
}
|
|
234
200
|
for (const payload of payloads) {
|
|
235
201
|
this.buffer.next({
|
|
236
|
-
|
|
237
|
-
name,
|
|
202
|
+
pubSubName,
|
|
238
203
|
producerId,
|
|
239
204
|
topic,
|
|
240
205
|
payload,
|
package/package.json
CHANGED