@lad-tech/nsc-toolkit 1.22.4 → 1.22.5

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 CHANGED
@@ -1,6 +1,6 @@
1
- ## [1.22.4](https://github.com/lad-tech/nsc-toolkit/compare/v1.22.3...v1.22.4) (2024-09-05)
1
+ ## [1.22.5](https://github.com/lad-tech/nsc-toolkit/compare/v1.22.4...v1.22.5) (2024-09-08)
2
2
 
3
3
 
4
4
  ### Bug Fixes
5
5
 
6
- * Drop error if failed subscribe to subject ([#122](https://github.com/lad-tech/nsc-toolkit/issues/122)) ([edc4580](https://github.com/lad-tech/nsc-toolkit/commit/edc4580df2b3ae4e12b530d822e6cb60ce89ca1d))
6
+ * Error for create same consumer ([#124](https://github.com/lad-tech/nsc-toolkit/issues/124)) ([8664809](https://github.com/lad-tech/nsc-toolkit/commit/8664809486f0d59c4a04a62cb0690f09d9cf9d97))
@@ -13,6 +13,7 @@ class StreamManager extends Root_1.Root {
13
13
  this.GREATER_WILDCARD = '>';
14
14
  this.TWO_WEEKS_IN_SECOND = 1209600;
15
15
  this.ONE_DAY_IN_SECOND = 86400;
16
+ this.CONSUMER_NOT_FOUND = 'consumer not found';
16
17
  this.defaultStreamOption = {
17
18
  storage: 'file',
18
19
  retentionPolicy: 'limits',
@@ -105,7 +106,15 @@ class StreamManager extends Root_1.Root {
105
106
  throw new Error(`Error creating consumer ${consumerName}. Stream for subject ${subject} not found`);
106
107
  }
107
108
  if ((0, types_1.isConsumerOptsBuilder)(options)) {
108
- await this.jsm.consumers.add(streamName, { ...options.config, filter_subject: subject });
109
+ const isConsumerExist = await this.jsm.consumers.info(streamName, consumerName).catch(async (error) => {
110
+ if (error.message === this.CONSUMER_NOT_FOUND) {
111
+ return false;
112
+ }
113
+ throw error;
114
+ });
115
+ if (!isConsumerExist) {
116
+ await this.jsm.consumers.add(streamName, { ...options.config, filter_subject: subject });
117
+ }
109
118
  }
110
119
  return isPullConsumer
111
120
  ? new StreamFetcher_1.StreamFetcher(this.broker.jetstream(), streamName, consumerName, {
@@ -8,6 +8,7 @@ export declare class StreamManager extends Root {
8
8
  private readonly GREATER_WILDCARD;
9
9
  private readonly TWO_WEEKS_IN_SECOND;
10
10
  private readonly ONE_DAY_IN_SECOND;
11
+ private readonly CONSUMER_NOT_FOUND;
11
12
  private readonly defaultStreamOption;
12
13
  private jsm?;
13
14
  constructor(param: StreamManagerParam);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lad-tech/nsc-toolkit",
3
- "version": "1.22.4",
3
+ "version": "1.22.5",
4
4
  "description": "Toolkit for create microservices around NATS",
5
5
  "main": "dist/index.js",
6
6
  "types": "./dist/types/index.d.ts",