@jetit/publisher 4.1.0 → 5.0.0

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,24 @@
1
1
  import { Observable } from 'rxjs';
2
- import { EventData, PublishData } from './types';
2
+ import { IAggregatedMetrics, TQueryableMetrics } from '../monitoring/types';
3
+ import { CircuitState } from '../performance/circuit_breaker';
4
+ import { EventData, IListenOptions, IStreamsConfig, PublishData } from './types';
3
5
  export declare class Streams {
4
6
  private _redisPublisher?;
5
7
  private _redisGroups?;
8
+ private config;
9
+ private dlq;
10
+ private metricsCollector;
6
11
  private consumerGroupName;
7
12
  private instanceId;
8
13
  private instanceUniqueId;
9
14
  private cleanUpTimer;
10
15
  private eventsListened;
16
+ private subscriptions;
17
+ private duplicateChecker;
18
+ private circuitBreaker;
11
19
  private get redisPublisher();
12
20
  private get redisGroups();
21
+ private DEFAULT_STREAMS_CONFIG;
13
22
  /**
14
23
  * Creates a new Streams instance for a given service.
15
24
  *
@@ -24,7 +33,8 @@ export declare class Streams {
24
33
  * // Create a new Streams instance for the "POS" service
25
34
  * const streams = new Streams('POS');
26
35
  */
27
- constructor(serviceName: string);
36
+ constructor(serviceName: string, config?: Partial<IStreamsConfig>);
37
+ private setupCircuitBreakerListeners;
28
38
  private runClear;
29
39
  /**
30
40
  * Publishes an event with the given data to the Redis event stream.
@@ -96,7 +106,7 @@ export declare class Streams {
96
106
  * PUBLISHER_LOGGER.log('New order created:', event.data);
97
107
  * });
98
108
  */
99
- listen<T = unknown, const TName extends string = string>(eventName: TName, maxRetries?: number, initialDelay?: number): Observable<EventData<T, TName>>;
109
+ listen<T = unknown, const TName extends string = string>(eventName: TName, listenerOptions?: IListenOptions<T>): Observable<EventData<T, TName>>;
100
110
  private createConsumerAndRegister;
101
111
  private listenInternals;
102
112
  /**
@@ -142,4 +152,52 @@ export declare class Streams {
142
152
  }[];
143
153
  message: string;
144
154
  }>;
155
+ private logPerformance;
156
+ /**
157
+ * @description
158
+ * This method is use to retry an event that has ended in the dead letter queue,
159
+ * which happens after the first retry.
160
+ */
161
+ retryFromDLQ(eventId: string): Promise<boolean>;
162
+ /**
163
+ * @description
164
+ * This returns the number of items and the rate at which events are added
165
+ * to the queue. The queue is global and hence remains as is
166
+ */
167
+ getDLQStats(): Promise<{
168
+ size: number;
169
+ additionRate: number;
170
+ }>;
171
+ private removeSubscription;
172
+ /**
173
+ * @description
174
+ * This is a simple helper utility that can be used externally to create alerts based
175
+ * on thresholds that can be provided into the function. It returns true/false for each
176
+ * key that is provided. Not all keys are required
177
+ */
178
+ checkThresholds(thresholds: Partial<TQueryableMetrics>): Promise<Record<string, boolean>>;
179
+ /**
180
+ * @description
181
+ * This will return you the stats of the publisher for the last 6 hours after cleaning
182
+ */
183
+ getMetrics(startTime: number, endTime: number): Promise<IAggregatedMetrics[]>;
184
+ /**
185
+ * @description
186
+ * This will return you the latest stats of the publisher
187
+ */
188
+ getLatestMetrics(): Promise<IAggregatedMetrics | null>;
189
+ /**
190
+ * @description
191
+ * This returns the status of the performance control setup. This includes
192
+ * the circuit breaker
193
+ */
194
+ getPerformanceControlStatus(): Promise<{
195
+ circuitBreakerState: CircuitState;
196
+ }>;
197
+ /**
198
+ * @description
199
+ * This is a manual control to process stored events in case the
200
+ * circuit is OPEN
201
+ */
202
+ processStoredEvents(): Promise<void>;
145
203
  }