Skip to content

Commit 0a2bf70

Browse files
committed
fix redis namespaces
1 parent 4578765 commit 0a2bf70

File tree

7 files changed

+48
-27
lines changed

7 files changed

+48
-27
lines changed

package-lock.json

Lines changed: 33 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cap-js-community/event-queue",
3-
"version": "2.0.0-beta.2",
3+
"version": "2.0.0-beta.3",
44
"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.",
55
"main": "src/index.js",
66
"types": "src/index.d.ts",

src/config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,8 +784,8 @@ class Config {
784784
};
785785
}
786786

787-
get redisNamespace() {
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;
789789
}
790790

791791
set insertEventsBeforeCommit(value) {

src/initialize.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ const initialize = async (options = {}) => {
115115
registerCdsShutdown();
116116
logger.info("event queue initialized", {
117117
registerAsEventProcessor: config.registerAsEventProcessor,
118+
namespace: config.namespace,
119+
processingNamespaces: config.processingNamespaces,
118120
processEventsAfterPublish: config.processEventsAfterPublish,
119121
multiTenancyEnabled: config.isMultiTenancy,
120122
redisEnabled: config.redisEnabled,

src/shared/distributedLock.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ const _acquireLockDB = async (
195195
};
196196

197197
const _generateKey = (context, tenantScoped, key) => {
198-
const keyParts = [config.redisNamespace];
198+
const keyParts = [config.redisNamespace()];
199199
tenantScoped && keyParts.push(context.tenant);
200200
keyParts.push(key);
201201
return `${keyParts.join("##")}`;

src/shared/redis/client.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ const createMainClientAndConnect = async () => {
1313

1414
const subscribeRedisChannel = async (channel, subscribeHandler) => {
1515
const redisClient = RedisClient.create(REDIS_CLIENT_NAME);
16-
const channelWithNamespace = [config.redisNamespace, channel].join("##");
16+
const channelWithNamespace = [config.redisNamespace(false), channel].join("##");
1717
return await redisClient.subscribeChannel(config.redisOptions, channelWithNamespace, subscribeHandler);
1818
};
1919

20-
const publishMessage = async (channel, message) => {
20+
const publishMessage = async (channel, message, { addNamespace = true } = {}) => {
2121
const redisClient = RedisClient.create(REDIS_CLIENT_NAME);
22-
const channelWithNamespace = [config.redisNamespace, channel].join("##");
22+
const channelWithNamespace = [config.redisNamespace(addNamespace), channel].join("##");
2323
return await redisClient.publishMessage(config.redisOptions, channelWithNamespace, message);
2424
};
2525

src/shared/redis/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const attachRedisUnsubscribeHandler = () => {
1515
try {
1616
const { tenantId } = JSON.parse(messageData);
1717
cds.log(COMPONENT_NAME).info("received unsubscribe broadcast event", { tenantId });
18-
this.executeUnsubscribeHandlers(tenantId);
18+
config.executeUnsubscribeHandlers(tenantId);
1919
} catch (err) {
2020
cds.log(COMPONENT_NAME).error("could not parse unsubscribe broadcast event", err, {
2121
messageData,
@@ -27,9 +27,11 @@ const attachRedisUnsubscribeHandler = () => {
2727

2828
const handleUnsubscribe = (tenantId) => {
2929
if (config.redisEnabled) {
30-
client.publishMessage(REDIS_OFFBOARD_TENANT_CHANNEL, JSON.stringify({ tenantId })).catch((error) => {
31-
cds.log(COMPONENT_NAME).error(`publishing tenant unsubscribe failed. tenantId: ${tenantId}`, error);
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+
});
3335
} else {
3436
config.executeUnsubscribeHandlers(tenantId);
3537
}

0 commit comments

Comments
 (0)