@cap-js-community/event-queue 2.0.0-beta.1 → 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.1",
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
@@ -105,7 +105,6 @@ class Config {
105
105
  #unsubscribedTenants = {};
106
106
  #cronTimezone;
107
107
  #randomOffsetPeriodicEvents;
108
- #redisNamespace;
109
108
  #crashOnRedisUnavailable;
110
109
  #tenantIdFilterAuthContextCb;
111
110
  #tenantIdFilterEventProcessingCb;
@@ -785,12 +784,8 @@ class Config {
785
784
  };
786
785
  }
787
786
 
788
- set redisNamespace(value) {
789
- this.#redisNamespace = value;
790
- }
791
-
792
- get redisNamespace() {
793
- return `${[REDIS_PREFIX, this.#redisNamespace].filter((a) => a).join("##")}`;
787
+ redisNamespace(addPublishNamespace = true) {
788
+ return addPublishNamespace ? `${[REDIS_PREFIX, this.#namespace].filter((a) => a).join("##")}` : REDIS_PREFIX;
794
789
  }
795
790
 
796
791
  set insertEventsBeforeCommit(value) {
package/src/initialize.js CHANGED
@@ -42,7 +42,6 @@ const CONFIG_VARS = [
42
42
  ["enableTelemetry", true],
43
43
  ["cronTimezone", null],
44
44
  ["randomOffsetPeriodicEvents", null],
45
- ["redisNamespace", null],
46
45
  ["publishEventBlockList", true],
47
46
  ["crashOnRedisUnavailable", false],
48
47
  ["enableAdminService", false],
@@ -116,6 +115,8 @@ const initialize = async (options = {}) => {
116
115
  registerCdsShutdown();
117
116
  logger.info("event queue initialized", {
118
117
  registerAsEventProcessor: config.registerAsEventProcessor,
118
+ namespace: config.namespace,
119
+ processingNamespaces: config.processingNamespaces,
119
120
  processEventsAfterPublish: config.processEventsAfterPublish,
120
121
  multiTenancyEnabled: config.isMultiTenancy,
121
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
- this.executeUnsubscribeHandlers(tenantId);
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.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
+ });
33
35
  } else {
34
36
  config.executeUnsubscribeHandlers(tenantId);
35
37
  }