@cap-js-community/event-queue 2.0.0-beta.2 → 2.0.0-beta.3
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cap-js-community/event-queue",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.3",
|
|
4
4
|
"description": "An event queue that enables secure transactional processing of asynchronous and periodic events, featuring instant event processing with Redis Pub/Sub and load distribution across all application instances.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "src/index.d.ts",
|
package/src/config.js
CHANGED
|
@@ -784,8 +784,8 @@ class Config {
|
|
|
784
784
|
};
|
|
785
785
|
}
|
|
786
786
|
|
|
787
|
-
|
|
788
|
-
return `${[REDIS_PREFIX, this.#namespace].filter((a) => a).join("##")}
|
|
787
|
+
redisNamespace(addPublishNamespace = true) {
|
|
788
|
+
return addPublishNamespace ? `${[REDIS_PREFIX, this.#namespace].filter((a) => a).join("##")}` : REDIS_PREFIX;
|
|
789
789
|
}
|
|
790
790
|
|
|
791
791
|
set insertEventsBeforeCommit(value) {
|
package/src/initialize.js
CHANGED
|
@@ -115,6 +115,8 @@ const initialize = async (options = {}) => {
|
|
|
115
115
|
registerCdsShutdown();
|
|
116
116
|
logger.info("event queue initialized", {
|
|
117
117
|
registerAsEventProcessor: config.registerAsEventProcessor,
|
|
118
|
+
namespace: config.namespace,
|
|
119
|
+
processingNamespaces: config.processingNamespaces,
|
|
118
120
|
processEventsAfterPublish: config.processEventsAfterPublish,
|
|
119
121
|
multiTenancyEnabled: config.isMultiTenancy,
|
|
120
122
|
redisEnabled: config.redisEnabled,
|
|
@@ -195,7 +195,7 @@ const _acquireLockDB = async (
|
|
|
195
195
|
};
|
|
196
196
|
|
|
197
197
|
const _generateKey = (context, tenantScoped, key) => {
|
|
198
|
-
const keyParts = [config.redisNamespace];
|
|
198
|
+
const keyParts = [config.redisNamespace()];
|
|
199
199
|
tenantScoped && keyParts.push(context.tenant);
|
|
200
200
|
keyParts.push(key);
|
|
201
201
|
return `${keyParts.join("##")}`;
|
|
@@ -13,13 +13,13 @@ const createMainClientAndConnect = async () => {
|
|
|
13
13
|
|
|
14
14
|
const subscribeRedisChannel = async (channel, subscribeHandler) => {
|
|
15
15
|
const redisClient = RedisClient.create(REDIS_CLIENT_NAME);
|
|
16
|
-
const channelWithNamespace = [config.redisNamespace, channel].join("##");
|
|
16
|
+
const channelWithNamespace = [config.redisNamespace(false), channel].join("##");
|
|
17
17
|
return await redisClient.subscribeChannel(config.redisOptions, channelWithNamespace, subscribeHandler);
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
const publishMessage = async (channel, message) => {
|
|
20
|
+
const publishMessage = async (channel, message, { addNamespace = true } = {}) => {
|
|
21
21
|
const redisClient = RedisClient.create(REDIS_CLIENT_NAME);
|
|
22
|
-
const channelWithNamespace = [config.redisNamespace, channel].join("##");
|
|
22
|
+
const channelWithNamespace = [config.redisNamespace(addNamespace), channel].join("##");
|
|
23
23
|
return await redisClient.publishMessage(config.redisOptions, channelWithNamespace, message);
|
|
24
24
|
};
|
|
25
25
|
|
|
@@ -15,7 +15,7 @@ const attachRedisUnsubscribeHandler = () => {
|
|
|
15
15
|
try {
|
|
16
16
|
const { tenantId } = JSON.parse(messageData);
|
|
17
17
|
cds.log(COMPONENT_NAME).info("received unsubscribe broadcast event", { tenantId });
|
|
18
|
-
|
|
18
|
+
config.executeUnsubscribeHandlers(tenantId);
|
|
19
19
|
} catch (err) {
|
|
20
20
|
cds.log(COMPONENT_NAME).error("could not parse unsubscribe broadcast event", err, {
|
|
21
21
|
messageData,
|
|
@@ -27,9 +27,11 @@ const attachRedisUnsubscribeHandler = () => {
|
|
|
27
27
|
|
|
28
28
|
const handleUnsubscribe = (tenantId) => {
|
|
29
29
|
if (config.redisEnabled) {
|
|
30
|
-
client
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
client
|
|
31
|
+
.publishMessage(REDIS_OFFBOARD_TENANT_CHANNEL, JSON.stringify({ tenantId }), { addNamespace: false })
|
|
32
|
+
.catch((error) => {
|
|
33
|
+
cds.log(COMPONENT_NAME).error(`publishing tenant unsubscribe failed. tenantId: ${tenantId}`, error);
|
|
34
|
+
});
|
|
33
35
|
} else {
|
|
34
36
|
config.executeUnsubscribeHandlers(tenantId);
|
|
35
37
|
}
|