redis-smq 8.3.0 → 8.3.1
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/CHANGELOG.md +6 -0
- package/dist/cjs/src/common/redis-client/scripts/lua/acknowledge-message.lua +19 -8
- package/dist/cjs/src/common/redis-client/scripts/lua/create-queue.lua +15 -10
- package/dist/cjs/src/common/redis-client/scripts/lua/delete-consumer-group.lua +20 -9
- package/dist/cjs/src/common/redis-client/scripts/lua/delete-message.lua +90 -147
- package/dist/cjs/src/common/redis-client/scripts/lua/fetch-message-for-processing.lua +11 -3
- package/dist/cjs/src/common/redis-client/scripts/lua/handle-processing-queue.lua +53 -82
- package/dist/cjs/src/common/redis-client/scripts/lua/has-queue-rate-exceeded.lua +15 -8
- package/dist/cjs/src/common/redis-client/scripts/lua/init-consumer-queue.lua +12 -8
- package/dist/cjs/src/common/redis-client/scripts/lua/publish-message.lua +19 -18
- package/dist/cjs/src/common/redis-client/scripts/lua/publish-scheduled-message.lua +89 -119
- package/dist/cjs/src/common/redis-client/scripts/lua/requeue-message.lua +54 -53
- package/dist/cjs/src/common/redis-client/scripts/lua/schedule-message.lua +47 -76
- package/dist/cjs/src/common/redis-client/scripts/lua/set-queue-rate-limit.lua +4 -5
- package/dist/cjs/src/common/redis-client/scripts/scripts.d.ts +0 -2
- package/dist/cjs/src/common/redis-client/scripts/scripts.d.ts.map +1 -1
- package/dist/cjs/src/common/redis-client/scripts/scripts.js +0 -2
- package/dist/cjs/src/common/redis-client/scripts/scripts.js.map +1 -1
- package/dist/esm/src/common/redis-client/scripts/lua/acknowledge-message.lua +19 -8
- package/dist/esm/src/common/redis-client/scripts/lua/create-queue.lua +15 -10
- package/dist/esm/src/common/redis-client/scripts/lua/delete-consumer-group.lua +20 -9
- package/dist/esm/src/common/redis-client/scripts/lua/delete-message.lua +90 -147
- package/dist/esm/src/common/redis-client/scripts/lua/fetch-message-for-processing.lua +11 -3
- package/dist/esm/src/common/redis-client/scripts/lua/handle-processing-queue.lua +53 -82
- package/dist/esm/src/common/redis-client/scripts/lua/has-queue-rate-exceeded.lua +15 -8
- package/dist/esm/src/common/redis-client/scripts/lua/init-consumer-queue.lua +12 -8
- package/dist/esm/src/common/redis-client/scripts/lua/publish-message.lua +19 -18
- package/dist/esm/src/common/redis-client/scripts/lua/publish-scheduled-message.lua +89 -119
- package/dist/esm/src/common/redis-client/scripts/lua/requeue-message.lua +54 -53
- package/dist/esm/src/common/redis-client/scripts/lua/schedule-message.lua +47 -76
- package/dist/esm/src/common/redis-client/scripts/lua/set-queue-rate-limit.lua +4 -5
- package/dist/esm/src/common/redis-client/scripts/scripts.d.ts +0 -2
- package/dist/esm/src/common/redis-client/scripts/scripts.d.ts.map +1 -1
- package/dist/esm/src/common/redis-client/scripts/scripts.js +0 -2
- package/dist/esm/src/common/redis-client/scripts/scripts.js.map +1 -1
- package/package.json +2 -2
- package/dist/cjs/src/common/redis-client/scripts/lua/cleanup-offline-consumer.lua +0 -33
- package/dist/cjs/src/common/redis-client/scripts/lua/delete-queue-messages.lua +0 -21
- package/dist/esm/src/common/redis-client/scripts/lua/cleanup-offline-consumer.lua +0 -33
- package/dist/esm/src/common/redis-client/scripts/lua/delete-queue-messages.lua +0 -21
|
@@ -4,8 +4,6 @@ local keyQueuePending = KEYS[3]
|
|
|
4
4
|
local keyQueueMessages = KEYS[4]
|
|
5
5
|
local keyMessage = KEYS[5]
|
|
6
6
|
|
|
7
|
-
---
|
|
8
|
-
|
|
9
7
|
local EQueuePropertyQueueType = ARGV[1]
|
|
10
8
|
local EQueuePropertyMessagesCount = ARGV[2]
|
|
11
9
|
local EQueuePropertyQueueTypePriorityQueue = ARGV[3]
|
|
@@ -20,33 +18,28 @@ local messageState = ARGV[11]
|
|
|
20
18
|
local EMessagePropertyMessage = ARGV[12]
|
|
21
19
|
local message = ARGV[13]
|
|
22
20
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
local function saveMessage()
|
|
26
|
-
redis.call("SADD", keyQueueMessages, messageId)
|
|
27
|
-
redis.call(
|
|
28
|
-
"HMSET", keyMessage,
|
|
29
|
-
EMessagePropertyStatus, messageStatus,
|
|
30
|
-
EMessagePropertyState, messageState,
|
|
31
|
-
EMessagePropertyMessage, message
|
|
32
|
-
)
|
|
33
|
-
redis.call("HINCRBY", keyQueueProperties, EQueuePropertyMessagesCount, 1)
|
|
34
|
-
end
|
|
21
|
+
-- Get queue type with a single field fetch
|
|
22
|
+
local queueType = redis.call("HGET", keyQueueProperties, EQueuePropertyQueueType)
|
|
35
23
|
|
|
36
|
-
|
|
24
|
+
-- Early return if queue doesn't exist
|
|
37
25
|
if queueType == false then
|
|
38
26
|
return 'QUEUE_NOT_FOUND'
|
|
39
27
|
end
|
|
40
28
|
|
|
29
|
+
-- Handle different queue types
|
|
41
30
|
if queueType == EQueuePropertyQueueTypePriorityQueue then
|
|
31
|
+
-- Check if priority is provided for priority queue
|
|
42
32
|
if messagePriority == nil or messagePriority == '' then
|
|
43
33
|
return 'MESSAGE_PRIORITY_REQUIRED'
|
|
44
34
|
end
|
|
45
35
|
redis.call("ZADD", keyPriorityQueue, messagePriority, messageId)
|
|
46
36
|
else
|
|
37
|
+
-- Check if priority is incorrectly provided for non-priority queue
|
|
47
38
|
if not (messagePriority == nil or messagePriority == '') then
|
|
48
39
|
return 'PRIORITY_QUEUING_NOT_ENABLED'
|
|
49
40
|
end
|
|
41
|
+
|
|
42
|
+
-- Handle LIFO and FIFO queues
|
|
50
43
|
if queueType == EQueuePropertyQueueTypeLIFOQueue then
|
|
51
44
|
redis.call("RPUSH", keyQueuePending, messageId)
|
|
52
45
|
elseif queueType == EQueuePropertyQueueTypeFIFOQueue then
|
|
@@ -56,6 +49,14 @@ else
|
|
|
56
49
|
end
|
|
57
50
|
end
|
|
58
51
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
52
|
+
-- Add message to queue and set its properties
|
|
53
|
+
redis.call("SADD", keyQueueMessages, messageId)
|
|
54
|
+
redis.call(
|
|
55
|
+
"HSET", keyMessage,
|
|
56
|
+
EMessagePropertyStatus, messageStatus,
|
|
57
|
+
EMessagePropertyState, messageState,
|
|
58
|
+
EMessagePropertyMessage, message
|
|
59
|
+
)
|
|
60
|
+
redis.call("HINCRBY", keyQueueProperties, EQueuePropertyMessagesCount, 1)
|
|
61
|
+
|
|
62
|
+
return 'OK'
|
|
@@ -8,136 +8,106 @@ local EQueuePropertyQueueTypeFIFOQueue = ARGV[7]
|
|
|
8
8
|
local EQueuePropertyMessagesCount = ARGV[8]
|
|
9
9
|
local EMessagePropertyMessage = ARGV[9]
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
local
|
|
14
|
-
local
|
|
15
|
-
local
|
|
16
|
-
local keyQueueProperties = ''
|
|
17
|
-
local keyQueuePriorityPending = ''
|
|
18
|
-
local keyQueueScheduled = ''
|
|
19
|
-
local keyScheduledMessage = ''
|
|
20
|
-
|
|
21
|
-
local messageId = ''
|
|
22
|
-
local message = ''
|
|
23
|
-
local messageState = ''
|
|
24
|
-
local messagePriority = ''
|
|
25
|
-
local scheduledMessageId = ''
|
|
26
|
-
local scheduledMessageNextScheduleTimestamp = ''
|
|
27
|
-
local scheduledMessageState = ''
|
|
28
|
-
|
|
29
|
-
---
|
|
30
|
-
|
|
31
|
-
local keyIndexOffset = 0
|
|
32
|
-
local argvIndexOffset = 9
|
|
33
|
-
|
|
34
|
-
---
|
|
35
|
-
|
|
36
|
-
local function addToQueueMessages()
|
|
37
|
-
redis.call("SADD", keyQueueMessages, messageId)
|
|
38
|
-
redis.call(
|
|
39
|
-
"HMSET", keyMessage,
|
|
40
|
-
EMessagePropertyStatus, EMessagePropertyStatusPending,
|
|
41
|
-
EMessagePropertyState, messageState,
|
|
42
|
-
EMessagePropertyMessage, message
|
|
43
|
-
)
|
|
44
|
-
redis.call("HINCRBY", keyQueueProperties, EQueuePropertyMessagesCount, 1)
|
|
45
|
-
end
|
|
11
|
+
--
|
|
12
|
+
local INITIAL_KEY_OFFSET = 0
|
|
13
|
+
local INITIAL_ARGV_OFFSET = 9
|
|
14
|
+
local PARAMS_PER_MESSAGE = 7
|
|
15
|
+
local KEYS_PER_MESSAGE = 7
|
|
46
16
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
elseif queueType == EQueuePropertyQueueTypeFIFOQueue then
|
|
51
|
-
redis.call("LPUSH", keyQueuePending, msgId)
|
|
52
|
-
else
|
|
53
|
-
redis.call("ZADD", keyQueuePriorityPending, messagePriority, msgId)
|
|
54
|
-
end
|
|
17
|
+
-- Validate parameters
|
|
18
|
+
if #ARGV <= INITIAL_ARGV_OFFSET then
|
|
19
|
+
return 'INVALID_PARAMETERS'
|
|
55
20
|
end
|
|
56
21
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if updateMessageCount == true then
|
|
60
|
-
redis.call("HINCRBY", keyQueueProperties, EQueuePropertyMessagesCount, -1)
|
|
61
|
-
end
|
|
62
|
-
end
|
|
22
|
+
--
|
|
23
|
+
local keyIndex = INITIAL_KEY_OFFSET + 1
|
|
63
24
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
25
|
+
for argvIndex = INITIAL_ARGV_OFFSET + 1, #ARGV, PARAMS_PER_MESSAGE do
|
|
26
|
+
-- Extract message parameters
|
|
27
|
+
local messageId = ARGV[argvIndex]
|
|
28
|
+
local message = ARGV[argvIndex + 1]
|
|
29
|
+
local messageState = ARGV[argvIndex + 2]
|
|
30
|
+
local messagePriority = ARGV[argvIndex + 3]
|
|
31
|
+
local scheduledMessageId = ARGV[argvIndex + 4]
|
|
32
|
+
local scheduledMessageNextScheduleTimestamp = ARGV[argvIndex + 5]
|
|
33
|
+
local scheduledMessageState = ARGV[argvIndex + 6]
|
|
67
34
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
)
|
|
77
|
-
end
|
|
78
|
-
end
|
|
35
|
+
-- Extract keys for current message
|
|
36
|
+
local keyMessage = KEYS[keyIndex]
|
|
37
|
+
local keyQueuePending = KEYS[keyIndex + 1]
|
|
38
|
+
local keyQueueMessages = KEYS[keyIndex + 2]
|
|
39
|
+
local keyQueueProperties = KEYS[keyIndex + 3]
|
|
40
|
+
local keyQueuePriorityPending = KEYS[keyIndex + 4]
|
|
41
|
+
local keyQueueScheduled = KEYS[keyIndex + 5]
|
|
42
|
+
local keyScheduledMessage = KEYS[keyIndex + 6]
|
|
79
43
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
end
|
|
44
|
+
-- Update keyIndex for next iteration
|
|
45
|
+
keyIndex = keyIndex + KEYS_PER_MESSAGE
|
|
83
46
|
|
|
84
|
-
|
|
85
|
-
local
|
|
86
|
-
|
|
87
|
-
if
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
publishMessage(queueType, scheduledMessageId)
|
|
95
|
-
removeFromScheduled()
|
|
96
|
-
updateScheduledMessageProperties(EMessagePropertyStatusPending)
|
|
97
|
-
else
|
|
98
|
-
publishMessage(queueType, messageId)
|
|
99
|
-
addToQueueMessages();
|
|
100
|
-
if scheduledMessageNextScheduleTimestamp == "0" then
|
|
101
|
-
removeFromScheduled()
|
|
102
|
-
deletedScheduledMessage(true)
|
|
103
|
-
else
|
|
104
|
-
scheduleMessage()
|
|
105
|
-
updateScheduledMessageProperties('')
|
|
47
|
+
-- Get queue type
|
|
48
|
+
local queueType = redis.call("HGET", keyQueueProperties, EQueuePropertyQueueType)
|
|
49
|
+
|
|
50
|
+
-- Skip processing if queue type is missing, assuming queue has been deleted
|
|
51
|
+
if queueType ~= false then
|
|
52
|
+
-- Check if queue type is valid
|
|
53
|
+
if queueType ~= EQueuePropertyQueueTypeLIFOQueue and
|
|
54
|
+
queueType ~= EQueuePropertyQueueTypeFIFOQueue and
|
|
55
|
+
queueType ~= EQueuePropertyQueueTypePriorityQueue then
|
|
56
|
+
return 'ERROR_INVALID_QUEUE_TYPE'
|
|
106
57
|
end
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
58
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
keyQueueProperties = KEYS[keyIndexOffset + 4]
|
|
120
|
-
keyQueuePriorityPending = KEYS[keyIndexOffset + 5]
|
|
121
|
-
keyQueueScheduled = KEYS[keyIndexOffset + 6]
|
|
122
|
-
keyScheduledMessage = KEYS[keyIndexOffset + 7]
|
|
123
|
-
keyIndexOffset = keyIndexOffset + 7
|
|
124
|
-
elseif idx == 4 then
|
|
125
|
-
message = ARGV[index]
|
|
126
|
-
elseif idx == 5 then
|
|
127
|
-
messageState = ARGV[index]
|
|
128
|
-
elseif idx == 6 then
|
|
129
|
-
messagePriority = ARGV[index]
|
|
130
|
-
elseif idx == 0 then
|
|
131
|
-
scheduledMessageId = ARGV[index]
|
|
132
|
-
elseif idx == 1 then
|
|
133
|
-
scheduledMessageNextScheduleTimestamp = ARGV[index]
|
|
134
|
-
elseif idx == 2 then
|
|
135
|
-
scheduledMessageState = ARGV[index]
|
|
136
|
-
handleMessage()
|
|
59
|
+
-- Case 1: No message ID provided, use scheduled message directly
|
|
60
|
+
if messageId == '' then
|
|
61
|
+
-- Publish the scheduled message
|
|
62
|
+
if queueType == EQueuePropertyQueueTypeFIFOQueue then
|
|
63
|
+
redis.call("LPUSH", keyQueuePending, scheduledMessageId)
|
|
64
|
+
elseif queueType == EQueuePropertyQueueTypeLIFOQueue then
|
|
65
|
+
redis.call("RPUSH", keyQueuePending, scheduledMessageId)
|
|
66
|
+
else -- Priority queue
|
|
67
|
+
redis.call("ZADD", keyQueuePriorityPending, messagePriority, scheduledMessageId)
|
|
137
68
|
end
|
|
69
|
+
|
|
70
|
+
-- Remove from scheduled
|
|
71
|
+
redis.call("ZREM", keyQueueScheduled, scheduledMessageId)
|
|
72
|
+
|
|
73
|
+
-- Update scheduled message properties
|
|
74
|
+
redis.call(
|
|
75
|
+
"HSET", keyScheduledMessage,
|
|
76
|
+
EMessagePropertyState, scheduledMessageState,
|
|
77
|
+
EMessagePropertyStatus, EMessagePropertyStatusPending
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
else
|
|
81
|
+
-- Case 2: Message ID provided, publish new message and reschedule the message
|
|
82
|
+
-- Check if we have the next schedule timestamp
|
|
83
|
+
if scheduledMessageNextScheduleTimestamp == "0" then
|
|
84
|
+
return 'ERROR_NEXT_SCHEDULE_TIMESTAMP_REQUIRED'
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
-- Publish the message
|
|
88
|
+
if queueType == EQueuePropertyQueueTypeFIFOQueue then
|
|
89
|
+
redis.call("LPUSH", keyQueuePending, messageId)
|
|
90
|
+
elseif queueType == EQueuePropertyQueueTypeLIFOQueue then
|
|
91
|
+
redis.call("RPUSH", keyQueuePending, messageId)
|
|
92
|
+
else -- Priority queue
|
|
93
|
+
redis.call("ZADD", keyQueuePriorityPending, messagePriority, messageId)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
-- Add to queue messages
|
|
97
|
+
redis.call("SADD", keyQueueMessages, messageId)
|
|
98
|
+
redis.call(
|
|
99
|
+
"HSET", keyMessage,
|
|
100
|
+
EMessagePropertyStatus, EMessagePropertyStatusPending,
|
|
101
|
+
EMessagePropertyState, messageState,
|
|
102
|
+
EMessagePropertyMessage, message
|
|
103
|
+
)
|
|
104
|
+
redis.call("HINCRBY", keyQueueProperties, EQueuePropertyMessagesCount, 1)
|
|
105
|
+
|
|
106
|
+
-- Reschedule message
|
|
107
|
+
redis.call("ZADD", keyQueueScheduled, scheduledMessageNextScheduleTimestamp, scheduledMessageId)
|
|
108
|
+
redis.call("HSET", keyScheduledMessage, EMessagePropertyState, scheduledMessageState)
|
|
138
109
|
end
|
|
139
110
|
end
|
|
140
|
-
return 'OK'
|
|
141
111
|
end
|
|
142
112
|
|
|
143
|
-
return '
|
|
113
|
+
return 'OK'
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
local keyFromQueue = KEYS[1]
|
|
2
2
|
local keyQueueProperties = KEYS[2]
|
|
3
3
|
|
|
4
|
-
---
|
|
5
|
-
|
|
6
4
|
local keyQueuePropertyQueueType = ARGV[1]
|
|
7
5
|
local typePriorityQueue = ARGV[2]
|
|
8
6
|
local typeLIFOQueue = ARGV[3]
|
|
@@ -11,74 +9,77 @@ local EMessagePropertyStatus = ARGV[5]
|
|
|
11
9
|
local messageStatus = ARGV[6]
|
|
12
10
|
local EMessagePropertyState = ARGV[7]
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
local
|
|
17
|
-
local
|
|
18
|
-
local
|
|
12
|
+
-- Constants for parameter counts
|
|
13
|
+
local INITIAL_KEY_OFFSET = 2
|
|
14
|
+
local INITIAL_ARGV_OFFSET = 7
|
|
15
|
+
local PARAMS_PER_MESSAGE = 3
|
|
16
|
+
local KEYS_PER_MESSAGE = 3
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
-- Validate parameters
|
|
19
|
+
if #ARGV <= INITIAL_ARGV_OFFSET then
|
|
20
|
+
return 'INVALID_PARAMETERS'
|
|
21
|
+
end
|
|
23
22
|
|
|
24
|
-
|
|
23
|
+
--
|
|
24
|
+
local keyIndex = INITIAL_KEY_OFFSET + 1
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
-- Process each message batch
|
|
27
|
+
for argvIndex = INITIAL_ARGV_OFFSET + 1, #ARGV, PARAMS_PER_MESSAGE do
|
|
28
|
+
-- Extract message parameters in sequence
|
|
29
|
+
local messageId = ARGV[argvIndex]
|
|
30
|
+
local messagePriority = ARGV[argvIndex + 1]
|
|
31
|
+
local messageState = ARGV[argvIndex + 2]
|
|
28
32
|
|
|
29
|
-
|
|
33
|
+
-- Extract keys for current message
|
|
34
|
+
local keyQueuePriority = KEYS[keyIndex]
|
|
35
|
+
local keyQueuePending = KEYS[keyIndex + 1]
|
|
36
|
+
local keyMessage = KEYS[keyIndex + 2]
|
|
30
37
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"HMSET", keyMessage,
|
|
34
|
-
EMessagePropertyStatus, messageStatus,
|
|
35
|
-
EMessagePropertyState, messageState
|
|
36
|
-
)
|
|
37
|
-
end
|
|
38
|
+
-- Update keyIndex for next iteration
|
|
39
|
+
keyIndex = keyIndex + KEYS_PER_MESSAGE
|
|
38
40
|
|
|
39
|
-
|
|
41
|
+
-- Try to remove the message from the source queue
|
|
40
42
|
local result = redis.call("LREM", keyFromQueue, 1, messageId)
|
|
43
|
+
|
|
44
|
+
-- Only proceed if message was found and removed
|
|
41
45
|
if result then
|
|
46
|
+
-- Get queue type
|
|
42
47
|
local queueType = redis.call("HGET", keyQueueProperties, keyQueuePropertyQueueType)
|
|
43
|
-
|
|
48
|
+
|
|
49
|
+
-- Handle priority queue
|
|
50
|
+
if queueType == typePriorityQueue and messagePriority ~= nil and messagePriority ~= '' then
|
|
44
51
|
redis.call("ZADD", keyQueuePriority, messagePriority, messageId)
|
|
45
|
-
|
|
46
|
-
|
|
52
|
+
|
|
53
|
+
-- Update message properties
|
|
54
|
+
redis.call(
|
|
55
|
+
"HSET", keyMessage,
|
|
56
|
+
EMessagePropertyStatus, messageStatus,
|
|
57
|
+
EMessagePropertyState, messageState
|
|
58
|
+
)
|
|
59
|
+
-- Handle LIFO/FIFO queues
|
|
60
|
+
elseif (queueType == typeLIFOQueue or queueType == typeFIFOQueue) and
|
|
61
|
+
(messagePriority == nil or messagePriority == '') then
|
|
62
|
+
-- Use direct conditional for better performance
|
|
47
63
|
if queueType == typeLIFOQueue then
|
|
48
64
|
redis.call("RPUSH", keyQueuePending, messageId)
|
|
49
65
|
else
|
|
50
66
|
redis.call("LPUSH", keyQueuePending, messageId)
|
|
51
67
|
end
|
|
52
|
-
return 'OK'
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
return 'MESSAGE_NOT_FOUND'
|
|
56
|
-
end
|
|
57
68
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
keyMessage = KEYS[keyIndexOffset + 3]
|
|
68
|
-
keyIndexOffset = keyIndexOffset + 3;
|
|
69
|
-
elseif idx == 0 then
|
|
70
|
-
messagePriority = ARGV[index]
|
|
71
|
-
elseif idx == 1 then
|
|
72
|
-
messageState = ARGV[index]
|
|
73
|
-
result = requeue()
|
|
74
|
-
if result == 'OK' then
|
|
75
|
-
updateMessage()
|
|
76
|
-
else
|
|
77
|
-
break
|
|
78
|
-
end
|
|
79
|
-
end
|
|
69
|
+
-- Update message properties
|
|
70
|
+
redis.call(
|
|
71
|
+
"HSET", keyMessage,
|
|
72
|
+
EMessagePropertyStatus, messageStatus,
|
|
73
|
+
EMessagePropertyState, messageState
|
|
74
|
+
)
|
|
75
|
+
else
|
|
76
|
+
-- If we get here, the queue type doesn't match the message priority configuration
|
|
77
|
+
return 'QUEUE_TYPE_MISMATCH'
|
|
80
78
|
end
|
|
79
|
+
else
|
|
80
|
+
-- Message not found in the source queue
|
|
81
|
+
return 'MESSAGE_NOT_FOUND'
|
|
81
82
|
end
|
|
82
83
|
end
|
|
83
84
|
|
|
84
|
-
return
|
|
85
|
+
return 'OK'
|
|
@@ -6,92 +6,63 @@ local EMessagePropertyStatusScheduled = ARGV[5]
|
|
|
6
6
|
local EMessagePropertyState = ARGV[6]
|
|
7
7
|
local scheduleFromDelayed = ARGV[7]
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
-- Constants for parameter counts
|
|
10
|
+
local INITIAL_KEY_OFFSET = 0
|
|
11
|
+
local INITIAL_ARGV_OFFSET = 7
|
|
12
|
+
local PARAMS_PER_MESSAGE = 4
|
|
13
|
+
local KEYS_PER_MESSAGE = 5
|
|
10
14
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
local keyQueueDelayed = ''
|
|
16
|
-
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
local messageId = ''
|
|
20
|
-
local message = ''
|
|
21
|
-
local scheduleTimestamp = ''
|
|
22
|
-
local messageState = ''
|
|
15
|
+
--
|
|
16
|
+
if (#ARGV <= INITIAL_ARGV_OFFSET) then
|
|
17
|
+
return 'INVALID_PARAMETERS'
|
|
18
|
+
end
|
|
23
19
|
|
|
24
|
-
|
|
20
|
+
--
|
|
21
|
+
local keyIndex = INITIAL_KEY_OFFSET + 1
|
|
25
22
|
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
-- Process messages in batches
|
|
24
|
+
for argvIndex = INITIAL_ARGV_OFFSET + 1, #ARGV, PARAMS_PER_MESSAGE do
|
|
25
|
+
-- Extract message parameters
|
|
26
|
+
local messageId = ARGV[argvIndex]
|
|
27
|
+
local message = ARGV[argvIndex + 1]
|
|
28
|
+
local scheduleTimestamp = ARGV[argvIndex + 2]
|
|
29
|
+
local messageState = ARGV[argvIndex + 3]
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
-- Set keys for this message
|
|
32
|
+
local keyQueueMessages = KEYS[keyIndex]
|
|
33
|
+
local keyQueueProperties = KEYS[keyIndex + 1]
|
|
34
|
+
local keyMessage = KEYS[keyIndex + 2]
|
|
35
|
+
local keyQueueScheduled = KEYS[keyIndex + 3]
|
|
36
|
+
local keyQueueDelayed = KEYS[keyIndex + 4]
|
|
30
37
|
|
|
31
|
-
|
|
38
|
+
-- Update keyIndex for next iteration
|
|
39
|
+
keyIndex = keyIndex + KEYS_PER_MESSAGE
|
|
32
40
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
local queueType = queueProperties[1]
|
|
41
|
+
-- Check if queue exists
|
|
42
|
+
local queueType = redis.call("HGET", keyQueueProperties, EQueuePropertyQueueType)
|
|
36
43
|
if queueType == false then
|
|
37
44
|
return 'QUEUE_NOT_FOUND'
|
|
38
45
|
end
|
|
39
|
-
return 'OK'
|
|
40
|
-
end
|
|
41
46
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
)
|
|
58
|
-
redis.call("HINCRBY", keyQueueProperties, EQueuePropertyMessagesCount, 1)
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
if #ARGV > argvIndexOffset then
|
|
62
|
-
for index in pairs(ARGV) do
|
|
63
|
-
if (index > argvIndexOffset) then
|
|
64
|
-
local idx = index % 4
|
|
65
|
-
if idx == 0 then
|
|
66
|
-
messageId = ARGV[index]
|
|
67
|
-
keyQueueMessages = KEYS[keyIndexOffset + 1]
|
|
68
|
-
keyQueueProperties = KEYS[keyIndexOffset + 2]
|
|
69
|
-
keyMessage = KEYS[keyIndexOffset + 3]
|
|
70
|
-
keyQueueScheduled = KEYS[keyIndexOffset + 4]
|
|
71
|
-
keyQueueDelayed = KEYS[keyIndexOffset + 5]
|
|
72
|
-
keyIndexOffset = keyIndexOffset + 5
|
|
73
|
-
elseif idx == 1 then
|
|
74
|
-
message = ARGV[index]
|
|
75
|
-
elseif idx == 2 then
|
|
76
|
-
scheduleTimestamp = ARGV[index]
|
|
77
|
-
elseif idx == 3 then
|
|
78
|
-
messageState = ARGV[index]
|
|
79
|
-
local found = checkQueue()
|
|
80
|
-
if found == 'OK' then
|
|
81
|
-
if scheduleFromDelayed == '1' then
|
|
82
|
-
redis.call("LREM", keyQueueDelayed, 1, messageId)
|
|
83
|
-
updateMessageState()
|
|
84
|
-
else
|
|
85
|
-
saveMessage()
|
|
86
|
-
end
|
|
87
|
-
redis.call("ZADD", keyQueueScheduled, scheduleTimestamp, messageId)
|
|
88
|
-
else
|
|
89
|
-
return found
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
end
|
|
47
|
+
-- Process the message based on its source
|
|
48
|
+
if scheduleFromDelayed == '1' then
|
|
49
|
+
-- Update existing message from delayed queue
|
|
50
|
+
redis.call("LREM", keyQueueDelayed, 1, messageId)
|
|
51
|
+
redis.call("HSET", keyMessage,
|
|
52
|
+
EMessagePropertyStatus, EMessagePropertyStatusScheduled,
|
|
53
|
+
EMessagePropertyState, messageState)
|
|
54
|
+
else
|
|
55
|
+
-- Save new message
|
|
56
|
+
redis.call("SADD", keyQueueMessages, messageId)
|
|
57
|
+
redis.call("HSET", keyMessage,
|
|
58
|
+
EMessagePropertyMessage, message,
|
|
59
|
+
EMessagePropertyStatus, EMessagePropertyStatusScheduled,
|
|
60
|
+
EMessagePropertyState, messageState)
|
|
61
|
+
redis.call("HINCRBY", keyQueueProperties, EQueuePropertyMessagesCount, 1)
|
|
93
62
|
end
|
|
94
|
-
|
|
63
|
+
|
|
64
|
+
-- Add to scheduled queue
|
|
65
|
+
redis.call("ZADD", keyQueueScheduled, scheduleTimestamp, messageId)
|
|
95
66
|
end
|
|
96
67
|
|
|
97
|
-
return '
|
|
68
|
+
return 'OK'
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
local keyQueueProperties = KEYS[1]
|
|
2
2
|
|
|
3
|
-
---
|
|
4
|
-
|
|
5
3
|
local EQueuePropertyRateLimit = ARGV[1]
|
|
6
4
|
local rateLimit = ARGV[2]
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
if
|
|
10
|
-
return 'QUEUE_NOT_FOUND'
|
|
6
|
+
-- Early return if queue doesn't exist
|
|
7
|
+
if redis.call("EXISTS", keyQueueProperties) == 0 then
|
|
8
|
+
return 'QUEUE_NOT_FOUND'
|
|
11
9
|
end
|
|
12
10
|
|
|
11
|
+
-- Set the rate limit property
|
|
13
12
|
redis.call("HSET", keyQueueProperties, EQueuePropertyRateLimit, rateLimit)
|
|
14
13
|
return 'OK'
|
|
@@ -11,7 +11,6 @@ export declare enum ELuaScriptName {
|
|
|
11
11
|
DELETE_MESSAGE = "DELETE_MESSAGE",
|
|
12
12
|
FETCH_MESSAGE_FOR_PROCESSING = "FETCH_MESSAGE_FOR_PROCESSING",
|
|
13
13
|
DELETE_CONSUMER_GROUP = "DELETE_CONSUMER_GROUP",
|
|
14
|
-
CLEANUP_OFFLINE_CONSUMER = "CLEANUP_OFFLINE_CONSUMER",
|
|
15
14
|
SET_QUEUE_RATE_LIMIT = "SET_QUEUE_RATE_LIMIT"
|
|
16
15
|
}
|
|
17
16
|
export declare const scriptFileMap: {
|
|
@@ -27,7 +26,6 @@ export declare const scriptFileMap: {
|
|
|
27
26
|
DELETE_MESSAGE: string;
|
|
28
27
|
FETCH_MESSAGE_FOR_PROCESSING: string;
|
|
29
28
|
DELETE_CONSUMER_GROUP: string;
|
|
30
|
-
CLEANUP_OFFLINE_CONSUMER: string;
|
|
31
29
|
SET_QUEUE_RATE_LIMIT: string;
|
|
32
30
|
};
|
|
33
31
|
//# sourceMappingURL=scripts.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scripts.d.ts","sourceRoot":"","sources":["../../../../../../src/common/redis-client/scripts/scripts.ts"],"names":[],"mappings":"AAYA,oBAAY,cAAc;IACxB,yBAAyB,8BAA8B;IACvD,eAAe,oBAAoB;IACnC,eAAe,oBAAoB;IACnC,gBAAgB,qBAAqB;IACrC,uBAAuB,4BAA4B;IACnD,YAAY,iBAAiB;IAC7B,mBAAmB,wBAAwB;IAC3C,uBAAuB,4BAA4B;IACnD,mBAAmB,wBAAwB;IAC3C,cAAc,mBAAmB;IACjC,4BAA4B,iCAAiC;IAC7D,qBAAqB,0BAA0B;IAC/C,
|
|
1
|
+
{"version":3,"file":"scripts.d.ts","sourceRoot":"","sources":["../../../../../../src/common/redis-client/scripts/scripts.ts"],"names":[],"mappings":"AAYA,oBAAY,cAAc;IACxB,yBAAyB,8BAA8B;IACvD,eAAe,oBAAoB;IACnC,eAAe,oBAAoB;IACnC,gBAAgB,qBAAqB;IACrC,uBAAuB,4BAA4B;IACnD,YAAY,iBAAiB;IAC7B,mBAAmB,wBAAwB;IAC3C,uBAAuB,4BAA4B;IACnD,mBAAmB,wBAAwB;IAC3C,cAAc,mBAAmB;IACjC,4BAA4B,iCAAiC;IAC7D,qBAAqB,0BAA0B;IAC/C,oBAAoB,yBAAyB;CAC9C;AAID,eAAO,MAAM,aAAa;;;;;;;;;;;;;;CA+CzB,CAAC"}
|
|
@@ -17,7 +17,6 @@ var ELuaScriptName;
|
|
|
17
17
|
ELuaScriptName["DELETE_MESSAGE"] = "DELETE_MESSAGE";
|
|
18
18
|
ELuaScriptName["FETCH_MESSAGE_FOR_PROCESSING"] = "FETCH_MESSAGE_FOR_PROCESSING";
|
|
19
19
|
ELuaScriptName["DELETE_CONSUMER_GROUP"] = "DELETE_CONSUMER_GROUP";
|
|
20
|
-
ELuaScriptName["CLEANUP_OFFLINE_CONSUMER"] = "CLEANUP_OFFLINE_CONSUMER";
|
|
21
20
|
ELuaScriptName["SET_QUEUE_RATE_LIMIT"] = "SET_QUEUE_RATE_LIMIT";
|
|
22
21
|
})(ELuaScriptName || (exports.ELuaScriptName = ELuaScriptName = {}));
|
|
23
22
|
const dirname = redis_smq_common_1.env.getCurrentDir();
|
|
@@ -34,7 +33,6 @@ exports.scriptFileMap = {
|
|
|
34
33
|
[ELuaScriptName.DELETE_MESSAGE]: (0, path_1.resolve)(dirname, './lua/delete-message.lua'),
|
|
35
34
|
[ELuaScriptName.FETCH_MESSAGE_FOR_PROCESSING]: (0, path_1.resolve)(dirname, './lua/fetch-message-for-processing.lua'),
|
|
36
35
|
[ELuaScriptName.DELETE_CONSUMER_GROUP]: (0, path_1.resolve)(dirname, './lua/delete-consumer-group.lua'),
|
|
37
|
-
[ELuaScriptName.CLEANUP_OFFLINE_CONSUMER]: (0, path_1.resolve)(dirname, './lua/cleanup-offline-consumer.lua'),
|
|
38
36
|
[ELuaScriptName.SET_QUEUE_RATE_LIMIT]: (0, path_1.resolve)(dirname, './lua/set-queue-rate-limit.lua'),
|
|
39
37
|
};
|
|
40
38
|
//# sourceMappingURL=scripts.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scripts.js","sourceRoot":"","sources":["../../../../../../src/common/redis-client/scripts/scripts.ts"],"names":[],"mappings":";;;AASA,+BAA+B;AAC/B,uDAAuC;AAEvC,IAAY,
|
|
1
|
+
{"version":3,"file":"scripts.js","sourceRoot":"","sources":["../../../../../../src/common/redis-client/scripts/scripts.ts"],"names":[],"mappings":";;;AASA,+BAA+B;AAC/B,uDAAuC;AAEvC,IAAY,cAcX;AAdD,WAAY,cAAc;IACxB,yEAAuD,CAAA;IACvD,qDAAmC,CAAA;IACnC,qDAAmC,CAAA;IACnC,uDAAqC,CAAA;IACrC,qEAAmD,CAAA;IACnD,+CAA6B,CAAA;IAC7B,6DAA2C,CAAA;IAC3C,qEAAmD,CAAA;IACnD,6DAA2C,CAAA;IAC3C,mDAAiC,CAAA;IACjC,+EAA6D,CAAA;IAC7D,iEAA+C,CAAA;IAC/C,+DAA6C,CAAA;AAC/C,CAAC,EAdW,cAAc,8BAAd,cAAc,QAczB;AAED,MAAM,OAAO,GAAG,sBAAG,CAAC,aAAa,EAAE,CAAC;AAEvB,QAAA,aAAa,GAAG;IAC3B,CAAC,cAAc,CAAC,yBAAyB,CAAC,EAAE,IAAA,cAAO,EACjD,OAAO,EACP,qCAAqC,CACtC;IACD,CAAC,cAAc,CAAC,eAAe,CAAC,EAAE,IAAA,cAAO,EACvC,OAAO,EACP,2BAA2B,CAC5B;IACD,CAAC,cAAc,CAAC,eAAe,CAAC,EAAE,IAAA,cAAO,EACvC,OAAO,EACP,2BAA2B,CAC5B;IACD,CAAC,cAAc,CAAC,gBAAgB,CAAC,EAAE,IAAA,cAAO,EACxC,OAAO,EACP,4BAA4B,CAC7B;IACD,CAAC,cAAc,CAAC,uBAAuB,CAAC,EAAE,IAAA,cAAO,EAC/C,OAAO,EACP,mCAAmC,CACpC;IACD,CAAC,cAAc,CAAC,YAAY,CAAC,EAAE,IAAA,cAAO,EAAC,OAAO,EAAE,wBAAwB,CAAC;IACzE,CAAC,cAAc,CAAC,mBAAmB,CAAC,EAAE,IAAA,cAAO,EAC3C,OAAO,EACP,+BAA+B,CAChC;IACD,CAAC,cAAc,CAAC,uBAAuB,CAAC,EAAE,IAAA,cAAO,EAC/C,OAAO,EACP,mCAAmC,CACpC;IACD,CAAC,cAAc,CAAC,mBAAmB,CAAC,EAAE,IAAA,cAAO,EAC3C,OAAO,EACP,+BAA+B,CAChC;IACD,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,IAAA,cAAO,EAAC,OAAO,EAAE,0BAA0B,CAAC;IAC7E,CAAC,cAAc,CAAC,4BAA4B,CAAC,EAAE,IAAA,cAAO,EACpD,OAAO,EACP,wCAAwC,CACzC;IACD,CAAC,cAAc,CAAC,qBAAqB,CAAC,EAAE,IAAA,cAAO,EAC7C,OAAO,EACP,iCAAiC,CAClC;IACD,CAAC,cAAc,CAAC,oBAAoB,CAAC,EAAE,IAAA,cAAO,EAC5C,OAAO,EACP,gCAAgC,CACjC;CACF,CAAC"}
|