@rayondigital/nest-dapr 0.9.31 → 0.9.32

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,15 +1,20 @@
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: (message: PublishMessage, error: any) => void): void;
17
+ handleError(message: PublishMessage, error: any): Promise<void>;
13
18
  onApplicationShutdown(signal?: string): Promise<void>;
14
19
  private setupBufferSubscription;
15
20
  private publishBulkDirectly;
@@ -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(message, error) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ if (this.onError) {
49
+ yield this.onError(message, error);
50
+ }
51
+ this.logger.error(`Error publishing message to ${message.name}:${message.topic}`, 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,40 @@ let DaprPubSubClient = class DaprPubSubClient {
95
108
  yield this.publishDirectly(name, topic, messages[0].payload, producerId, messages[0].metadata);
96
109
  continue;
97
110
  }
98
- yield this.daprClient.pubsub.publishBulk(name, topic, messages.map((m) => m.payload), producerId ? { metadata: { partitionKey: producerId } } : undefined);
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
+ for (const message of messages) {
116
+ yield this.handleError(message, error);
117
+ }
118
+ }
99
119
  }
100
120
  });
101
121
  }
102
122
  publishDirectly(name, topic, payload, producerId, metadata, fireAndForget = false) {
103
123
  return __awaiter(this, void 0, void 0, function* () {
104
- if (!name)
105
- name = this.defaultName;
106
- const options = {};
107
- if (metadata) {
108
- options['metadata'] = metadata;
109
- }
110
- if (producerId) {
111
- options['metadata'] = Object.assign({ partitionKey: producerId }, metadata);
124
+ try {
125
+ if (!name)
126
+ name = this.defaultName;
127
+ const options = {};
128
+ if (metadata) {
129
+ options['metadata'] = metadata;
130
+ }
131
+ if (producerId) {
132
+ options['metadata'] = Object.assign({ partitionKey: producerId }, metadata);
133
+ }
134
+ if (fireAndForget) {
135
+ setTimeout(() => __awaiter(this, void 0, void 0, function* () {
136
+ yield this.daprClient.pubsub.publish(name, topic, payload, options);
137
+ }));
138
+ return;
139
+ }
140
+ yield this.daprClient.pubsub.publish(name, topic, payload, options);
112
141
  }
113
- if (fireAndForget) {
114
- setTimeout(() => __awaiter(this, void 0, void 0, function* () {
115
- yield this.daprClient.pubsub.publish(name, topic, payload, options);
116
- }));
117
- return;
142
+ catch (error) {
143
+ yield this.handleError({ producerId, name, topic, payload, metadata }, error);
118
144
  }
119
- yield this.daprClient.pubsub.publish(name, topic, payload, options);
120
145
  });
121
146
  }
122
147
  publish(...args) {
@@ -144,7 +169,7 @@ let DaprPubSubClient = class DaprPubSubClient {
144
169
  });
145
170
  }
146
171
  };
147
- DaprPubSubClient = __decorate([
172
+ DaprPubSubClient = DaprPubSubClient_1 = __decorate([
148
173
  (0, common_1.Injectable)(),
149
174
  __param(0, (0, common_1.Inject)(dapr_module_1.DAPR_MODULE_OPTIONS_TOKEN)),
150
175
  __metadata("design:paramtypes", [Object, dapr_1.DaprClient])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rayondigital/nest-dapr",
3
- "version": "0.9.31",
3
+ "version": "0.9.32",
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",