@cap-js-community/event-queue
Advanced tools
Comparing version 0.2.0 to 0.2.1
{ | ||
"name": "@cap-js-community/event-queue", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "An event queue that enables secure transactional processing of asynchronous events, featuring instant event processing with Redis Pub/Sub and load distribution across all application instances.", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -6,3 +6,3 @@ # @cap-js-community/event-queue | ||
[![REUSE status](https://api.reuse.software/badge/github.com/cap-js-community/event-queue)](https://api.reuse.software/info/github.com/cap-js-community/event-queue) | ||
[![CI Main](https://github.com/cap-js-community/event-queue/actions/workflows/ci-main.yml/badge.svg)](https://github.com/cap-js-community/event-queue/commits/main) | ||
[![CI Main](https://github.com/cap-js-community/event-queue/actions/workflows/main-ci.yml/badge.svg)](https://github.com/cap-js-community/event-queue/commits/main) | ||
@@ -9,0 +9,0 @@ The Event-Queue is a framework built on top of CAP Node.js, specifically designed to enable efficient and streamlined |
@@ -15,3 +15,4 @@ "use strict"; | ||
const { getConfigInstance } = require("./config"); | ||
const { initEventQueueRedisSubscribe } = require("./redisPubSub"); | ||
const { initEventQueueRedisSubscribe, closeSubscribeClient } = require("./redisPubSub"); | ||
const { closeMainClient } = require("./shared/redis"); | ||
@@ -86,2 +87,3 @@ const readFileAsync = promisify(fs.readFile); | ||
registerEventProcessors(); | ||
registerCdsShutdown(); | ||
logger.info("event queue initialized", { | ||
@@ -186,4 +188,10 @@ registerAsEventProcessor: configInstance.registerAsEventProcessor, | ||
const registerCdsShutdown = () => { | ||
cds.on("shutdown", async () => { | ||
await Promise.allSettled([closeMainClient(), closeSubscribeClient()]); | ||
}); | ||
}; | ||
module.exports = { | ||
initialize, | ||
}; |
@@ -70,5 +70,17 @@ "use strict"; | ||
const closeSubscribeClient = async () => { | ||
try { | ||
const client = await subscriberClientPromise; | ||
if (client?.quit) { | ||
await client.quit(); | ||
} | ||
} catch (err) { | ||
// ignore errors during shutdown | ||
} | ||
}; | ||
module.exports = { | ||
initEventQueueRedisSubscribe, | ||
broadcastEvent, | ||
closeSubscribeClient, | ||
}; |
@@ -32,5 +32,14 @@ "use strict"; | ||
const credentials = env.getRedisCredentialsFromEnv(); | ||
// NOTE: settings the user explicitly to empty resolves auth problems, see | ||
// https://github.com/go-redis/redis/issues/1343 | ||
const redisIsCluster = credentials.cluster_mode; | ||
const url = credentials.uri.replace(/(?<=rediss:\/\/)[\w-]+?(?=:)/, ""); | ||
if (redisIsCluster) { | ||
return redis.createCluster({ | ||
rootNodes: [{ url }], | ||
// https://github.com/redis/node-redis/issues/1782 | ||
defaults: { | ||
password: credentials.password, | ||
socket: { tls: credentials.tls }, | ||
}, | ||
}); | ||
} | ||
return redis.createClient({ url }); | ||
@@ -91,2 +100,13 @@ } catch (err) { | ||
const closeMainClient = async () => { | ||
try { | ||
const client = await mainClientPromise; | ||
if (client?.quit) { | ||
await client.quit(); | ||
} | ||
} catch (err) { | ||
// ignore errors during shutdown | ||
} | ||
}; | ||
module.exports = { | ||
@@ -97,2 +117,3 @@ createClientAndConnect, | ||
publishMessage, | ||
closeMainClient, | ||
}; |
113728
2651