Skip to content

Commit faad280

Browse files
authored
Merge pull request #5 from wingify/feat/ordering-key
Added support for ordering key while publishing message
2 parents dacfce1 + 304d3ee commit faad280

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [1.5] - 2023-11-13
8+
### Added
9+
- Added support for ordering key while publishing message
10+
711
## [1.4] - 2021-04-17
812
### Fixed
913
- Added exception handling in push_batch method for releasing lock

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Note that at least [ngx_lua 0.9.3](https://github.com/openresty/lua-nginx-module
103103
local ok, send_err = producer:send("Some Random Text", {
104104
attr1 = "Test1",
105105
attr2 = "Test2"
106-
})
106+
}, "optional_ordering_key")
107107

108108
-- Also check if there is any error while sending message
109109
if send_err ~= nil then
@@ -167,9 +167,9 @@ To load this module, just do this
167167
`syntax: local p, err = producer:new(pubsub_config)`
168168

169169
#### send
170-
`syntax: p:send(message, attributes)`
170+
`syntax: p:send(message, attributes[, ordering_key])`
171171

172-
* Requires a message of type string and attributes of type table
172+
* Requires a message of type string, attributes of type table and an optional ordering_key of type string
173173

174174
[Back to TOC](#table-of-contents)
175175

lib/resty/pubsub/producer.lua

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ _timer_flush = function (premature, self, time)
149149
end
150150
end
151151

152-
function _M.send(self, message, attributes)
152+
function _M.send(self, message, attributes, ordering_key)
153153

154154
if type(message) ~= "string" then
155155
return false, "Data expected in string, got " .. type(message)
@@ -165,6 +165,15 @@ function _M.send(self, message, attributes)
165165
attributes = attributes
166166
}
167167

168+
169+
if ordering_key ~= nil then
170+
if type(ordering_key) == "string" then
171+
body_message['ordering_key'] = ordering_key
172+
else
173+
ngx.log(ngx.DEBUG, "Ordering key must be String hence dropping it ", ordering_key)
174+
end
175+
end
176+
168177
if self.ring_buffer == nil then
169178
return false, "Buffer not initialized Properly"
170179
end

0 commit comments

Comments
 (0)