@rayondigital/nest-dapr 0.9.32 → 0.9.34

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.
@@ -13,13 +13,16 @@ export declare class DaprPubSubClient implements OnApplicationShutdown {
13
13
  private readonly bufferTimeSpan;
14
14
  private onError;
15
15
  constructor(options: DaprModuleOptions, daprClient: DaprClient);
16
- registerErrorHandler(handler: (message: PublishMessage, error: any) => void): void;
17
- handleError(message: PublishMessage, error: any): Promise<void>;
16
+ registerErrorHandler(handler: (messages: PublishMessage[], error: Error) => void): void;
17
+ protected handleError(messages: PublishMessage[], error: Error): Promise<void>;
18
18
  onApplicationShutdown(signal?: string): Promise<void>;
19
- private setupBufferSubscription;
20
- private publishBulkDirectly;
21
- private publishDirectly;
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>;
22
22
  publish(name: string, producerId: string, topic: string, payload: any, buffer: boolean, metadata?: any): Promise<void>;
23
23
  publish(producerId: string, topic: string, payload: any, buffer: boolean, metadata?: any): Promise<void>;
24
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>;
25
28
  }
@@ -43,12 +43,12 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
43
43
  registerErrorHandler(handler) {
44
44
  this.onError = handler;
45
45
  }
46
- handleError(message, error) {
46
+ handleError(messages, error) {
47
47
  return __awaiter(this, void 0, void 0, function* () {
48
48
  if (this.onError) {
49
- yield this.onError(message, error);
49
+ yield this.onError(messages, error);
50
50
  }
51
- this.logger.error(`Error publishing message to ${message.name}:${message.topic}`, error);
51
+ this.logger.error(`Error publishing ${messages.length ? 'message' : 'messages'} to pubsub`, error);
52
52
  });
53
53
  }
54
54
  onApplicationShutdown(signal) {
@@ -112,9 +112,7 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
112
112
  yield this.daprClient.pubsub.publishBulk(name, topic, messages.map((m) => m.payload), producerId ? { metadata: { partitionKey: producerId } } : undefined);
113
113
  }
114
114
  catch (error) {
115
- for (const message of messages) {
116
- yield this.handleError(message, error);
117
- }
115
+ yield this.handleError(messages, error);
118
116
  }
119
117
  }
120
118
  });
@@ -140,7 +138,7 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
140
138
  yield this.daprClient.pubsub.publish(name, topic, payload, options);
141
139
  }
142
140
  catch (error) {
143
- yield this.handleError({ producerId, name, topic, payload, metadata }, error);
141
+ yield this.handleError([{ producerId, name, topic, payload, metadata }], error);
144
142
  }
145
143
  });
146
144
  }
@@ -168,6 +166,35 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
168
166
  yield this.publishDirectly(name, topic, payload, producerId, true);
169
167
  });
170
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
+ }
171
198
  };
172
199
  DaprPubSubClient = DaprPubSubClient_1 = __decorate([
173
200
  (0, common_1.Injectable)(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rayondigital/nest-dapr",
3
- "version": "0.9.32",
3
+ "version": "0.9.34",
4
4
  "description": "Develop NestJs microservices using Dapr pubsub, actors and other bindings",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",