@jetit/publisher 4.0.0 → 4.1.1
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/package.json +1 -1
- package/src/lib/redis/streams.d.ts +20 -9
- package/src/lib/redis/streams.js +28 -12
- package/src/lib/redis/utils.d.ts +7 -0
- package/src/lib/redis/utils.js +16 -1
package/package.json
CHANGED
|
@@ -121,14 +121,25 @@ export declare class Streams {
|
|
|
121
121
|
*/
|
|
122
122
|
close(): Promise<void>;
|
|
123
123
|
private cleanupAcknowledgedMessages;
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
124
|
+
getDiagnosticData(events: string[]): Promise<{
|
|
125
|
+
status: string;
|
|
126
|
+
message: string;
|
|
127
|
+
data?: undefined;
|
|
128
|
+
} | {
|
|
129
|
+
status: string;
|
|
130
|
+
data: {
|
|
131
|
+
eventName: string;
|
|
132
|
+
consumerGroupMap: {
|
|
133
|
+
consumerGroup: string;
|
|
134
|
+
diagnostics: Generator<Promise<unknown[]> | {
|
|
135
|
+
count: number;
|
|
136
|
+
consumers: {
|
|
137
|
+
consumerName: string;
|
|
138
|
+
pendingCount: string;
|
|
139
|
+
}[];
|
|
140
|
+
}, void, [number, string, string, string[][]]>;
|
|
141
|
+
}[];
|
|
142
|
+
}[];
|
|
143
|
+
message: string;
|
|
133
144
|
}>;
|
|
134
145
|
}
|
package/src/lib/redis/streams.js
CHANGED
|
@@ -257,12 +257,21 @@ class Streams {
|
|
|
257
257
|
});
|
|
258
258
|
eventStreamClient.on('message', async (channel, data) => {
|
|
259
259
|
const subscribeStartTime = process.hrtime();
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
260
|
+
let messageIdRead, multicastRead;
|
|
261
|
+
try {
|
|
262
|
+
const { messageId, multicast } = JSON.parse(data);
|
|
263
|
+
messageIdRead = messageId;
|
|
264
|
+
multicastRead = multicast;
|
|
265
|
+
}
|
|
266
|
+
catch (e) {
|
|
267
|
+
messageIdRead = data;
|
|
268
|
+
multicastRead = false;
|
|
269
|
+
}
|
|
270
|
+
logger_1.PUBLISHER_LOGGER.log(`PUBLISHER: Stream Notification Received for event ${eventName} with message ID ${messageIdRead}`);
|
|
271
|
+
await processMessage(this.redisGroups, messageIdRead, multicastRead);
|
|
263
272
|
const subscribendTime = process.hrtime(subscribeStartTime);
|
|
264
273
|
const elapsedTime = subscribendTime[0] * 1000 + subscribendTime[1] / 1000000;
|
|
265
|
-
logger_1.PERFORMANCE_LOGGER.log(`STIME;${
|
|
274
|
+
logger_1.PERFORMANCE_LOGGER.log(`STIME;${messageIdRead};${data.eventName};${Date.now()};${elapsedTime}`);
|
|
266
275
|
});
|
|
267
276
|
})
|
|
268
277
|
.catch((e) => {
|
|
@@ -317,14 +326,21 @@ class Streams {
|
|
|
317
326
|
await this.redisGroups.zremrangebyscore(`ack:${streamName}`, '-inf', cleanupThreshold);
|
|
318
327
|
}
|
|
319
328
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
329
|
+
async getDiagnosticData(events) {
|
|
330
|
+
if (events.length > 100) {
|
|
331
|
+
return { status: 'ERROR', message: 'Please pass in a maximum of 100 elements to fetch diagnostics' };
|
|
332
|
+
}
|
|
333
|
+
const tempPromises = events.map(async (eventName) => {
|
|
334
|
+
const consumerGroups = await (0, utils_1.getAllConsumerGroups)(eventName, this.redisPublisher);
|
|
335
|
+
const consumerGroupMap = await Promise.all(consumerGroups.map(async (consumerGroup) => {
|
|
336
|
+
const streamName = `${eventName}:${consumerGroup}`;
|
|
337
|
+
const diagnostics = await (0, utils_1.getSummaryOnStreamConsumerGroup)(this.redisGroups, consumerGroup, streamName);
|
|
338
|
+
return { consumerGroup, diagnostics };
|
|
339
|
+
}));
|
|
340
|
+
return { eventName, consumerGroupMap };
|
|
341
|
+
});
|
|
342
|
+
const returnData = await await Promise.all(tempPromises);
|
|
343
|
+
return { status: 'SUCCESS', data: returnData, message: 'We recommend not running this in times of heavy load' };
|
|
328
344
|
}
|
|
329
345
|
}
|
|
330
346
|
exports.Streams = Streams;
|
package/src/lib/redis/utils.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { RedisType } from './registry';
|
|
2
2
|
import { EventData } from './types';
|
|
3
3
|
export declare function getAllConsumerGroups(eventName: string, redisConnection: RedisType): Promise<string[]>;
|
|
4
|
+
export declare function getSummaryOnStreamConsumerGroup(redisClient: RedisType, consumerGroupName: string, streamName: string): Generator<Promise<unknown[]> | {
|
|
5
|
+
count: number;
|
|
6
|
+
consumers: {
|
|
7
|
+
consumerName: string;
|
|
8
|
+
pendingCount: string;
|
|
9
|
+
}[];
|
|
10
|
+
}, void, [number, string, string, string[][]]>;
|
|
4
11
|
export declare function getUnacknowledgedMessages(redisClient: RedisType, consumerGroupName: string, streamName: string, consumerName: string, count?: number): Promise<{
|
|
5
12
|
count: number;
|
|
6
13
|
countOnThisConsumer?: number;
|
package/src/lib/redis/utils.js
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UTILS = exports.decodeScheduledMessage = exports.encodeScheduledMessage = exports.removedScheduledJob = exports.notifySubscribers = exports.getMessageStatesCount = exports.getUnacknowledgedMessages = exports.getAllConsumerGroups = void 0;
|
|
3
|
+
exports.UTILS = exports.decodeScheduledMessage = exports.encodeScheduledMessage = exports.removedScheduledJob = exports.notifySubscribers = exports.getMessageStatesCount = exports.getUnacknowledgedMessages = exports.getSummaryOnStreamConsumerGroup = exports.getAllConsumerGroups = void 0;
|
|
4
4
|
const logger_1 = require("./logger");
|
|
5
5
|
async function getAllConsumerGroups(eventName, redisConnection) {
|
|
6
6
|
const consumerGroups = await redisConnection.smembers(`${eventName}`);
|
|
7
7
|
return consumerGroups;
|
|
8
8
|
}
|
|
9
9
|
exports.getAllConsumerGroups = getAllConsumerGroups;
|
|
10
|
+
function* getSummaryOnStreamConsumerGroup(redisClient, consumerGroupName, streamName) {
|
|
11
|
+
const [count, , , consumers] = (yield redisClient.xpending(streamName, consumerGroupName));
|
|
12
|
+
yield {
|
|
13
|
+
count,
|
|
14
|
+
consumers: consumers
|
|
15
|
+
? consumers.map((x) => {
|
|
16
|
+
return {
|
|
17
|
+
consumerName: x[0],
|
|
18
|
+
pendingCount: x[1],
|
|
19
|
+
};
|
|
20
|
+
})
|
|
21
|
+
: [],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
exports.getSummaryOnStreamConsumerGroup = getSummaryOnStreamConsumerGroup;
|
|
10
25
|
async function getUnacknowledgedMessages(redisClient, consumerGroupName, streamName, consumerName, count = 500) {
|
|
11
26
|
try {
|
|
12
27
|
// Get pending messages summary
|