@jetit/publisher 1.1.1 → 1.1.2
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
CHANGED
|
@@ -51,7 +51,7 @@ class ScheduledProcessor {
|
|
|
51
51
|
* Instead of using the publish method directly, the entire logic is
|
|
52
52
|
* copy pasted to reduce the case of failure.
|
|
53
53
|
*/
|
|
54
|
-
const transaction = this.redisPublisher.multi();
|
|
54
|
+
const transaction = this.redisPublisher.multi({ pipeline: true });
|
|
55
55
|
eventData.eventId = (0, id_1.generateID)('HEX', 'FF');
|
|
56
56
|
transaction.zrem('se', eventString);
|
|
57
57
|
const consumerGroups = yield (0, groups_1.getAllConsumerGroups)(eventData.eventName, this.redisPublisher);
|
package/src/lib/redis/streams.js
CHANGED
|
@@ -110,7 +110,7 @@ class Streams {
|
|
|
110
110
|
data.eventId = (0, id_1.generateID)('HEX', 'FF');
|
|
111
111
|
if (!data.createdAt)
|
|
112
112
|
data.createdAt = Date.now();
|
|
113
|
-
const transaction = this.redisPublisher.multi();
|
|
113
|
+
const transaction = this.redisPublisher.multi({ pipeline: true });
|
|
114
114
|
const consumerGroups = yield (0, groups_1.getAllConsumerGroups)(data.eventName, this.redisPublisher);
|
|
115
115
|
if (consumerGroups.length > 0) {
|
|
116
116
|
console.log(`Publishing event ${data.eventName} to consumer groups: ${consumerGroups.join(', ')}`);
|
|
@@ -236,7 +236,7 @@ class Streams {
|
|
|
236
236
|
bs.next(eventData);
|
|
237
237
|
const pmKey = `pm:${this.consumerGroupName}:${streamName}`;
|
|
238
238
|
const currentTime = Date.now();
|
|
239
|
-
const transaction = this.redisGroups.multi();
|
|
239
|
+
const transaction = this.redisGroups.multi({ pipeline: true });
|
|
240
240
|
transaction.zadd(pmKey, currentTime, messageId);
|
|
241
241
|
transaction.xack(streamName, this.consumerGroupName, id);
|
|
242
242
|
transaction.zadd(`ack:${streamName}`, Date.now(), id);
|
|
@@ -275,8 +275,10 @@ class Streams {
|
|
|
275
275
|
const result = yield this.redisGroups.xreadgroup('GROUP', this.consumerGroupName, this.instanceId, 'STREAMS', streamName, '>');
|
|
276
276
|
if (result) {
|
|
277
277
|
const [, streamMessages] = result[0];
|
|
278
|
+
if (!streamMessages)
|
|
279
|
+
return;
|
|
278
280
|
console.log(`Unprocessed events: ${streamMessages.length}`);
|
|
279
|
-
const transaction = this.redisGroups.multi();
|
|
281
|
+
const transaction = this.redisGroups.multi({ pipeline: true });
|
|
280
282
|
for (const [id, data] of streamMessages) {
|
|
281
283
|
const eventData = JSON.parse(data[1]);
|
|
282
284
|
// Republishing the events
|
|
@@ -312,7 +314,7 @@ class Streams {
|
|
|
312
314
|
const [, minId, maxId, consumers] = pendingMessages;
|
|
313
315
|
if (!consumers || consumers.length === 0)
|
|
314
316
|
return;
|
|
315
|
-
const transaction = this.redisGroups.multi();
|
|
317
|
+
const transaction = this.redisGroups.multi({ pipeline: true });
|
|
316
318
|
for (const [consumer, pendingCount] of consumers) {
|
|
317
319
|
if (parseInt(pendingCount) > 0) {
|
|
318
320
|
const pending = (yield this.redisGroups.xpending(streamName, this.consumerGroupName, minId, maxId, Number(pendingCount), consumer));
|
|
@@ -387,7 +389,7 @@ class Streams {
|
|
|
387
389
|
const cleanupThreshold = Date.now() - interval;
|
|
388
390
|
const acknowledgedMessages = yield this.redisGroups.zrangebyscore(`ack:${streamName}`, '-inf', cleanupThreshold);
|
|
389
391
|
if (acknowledgedMessages && acknowledgedMessages.length > 0) {
|
|
390
|
-
const transaction = this.redisGroups.multi();
|
|
392
|
+
const transaction = this.redisGroups.multi({ pipeline: true });
|
|
391
393
|
// Remove acknowledged messages from the stream
|
|
392
394
|
for (const messageId of acknowledgedMessages) {
|
|
393
395
|
transaction.xdel(streamName, messageId);
|