Skip to content

Commit 2fad5a9

Browse files
committed
Wildcard Support
1 parent a8e94a2 commit 2fad5a9

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

nmqtt.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ proc onPublish(ctx: MqttCtx, pkt: Pkt) {.async.} =
836836

837837
when not defined(broker):
838838
for top, cb in ctx.pubCallbacks:
839-
if top == topic or top == "#": cb.cb(topic, message)
839+
if top == topic or top.endsWith("#"): cb.cb(topic, message)
840840

841841
if qos == 1:
842842
ctx.workQueue[msgId] = Work(wk: PubWork, msgId: msgId, state: WorkNew, qos: 1, typ: PubAck)

tests/subscribe.nim

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,27 +170,26 @@ suite "test suite for subscribe":
170170
waitFor conn()
171171

172172

173-
test "subscribe to #":
174-
let (_, msg) = tdata("subscribe to #")
173+
test "subscribe to test/#":
174+
let (_, msg) = tdata("subscribe to test/#")
175175

176176
proc conn() {.async.} =
177177
var msgCount: int
178178
proc on_data_sub_all(topic: string, message: string) =
179179
msgCount += 1
180180

181-
await ctxListen.subscribe("#", 0, on_data_sub_all)
181+
await ctxListen.subscribe("test/#", 0, on_data_sub_all)
182182
await sleepAsync 500
183-
await ctxMain.publish("random1", msg, 0)
184-
await ctxMain.publish("random2", msg, 0)
185-
await ctxMain.publish("random3", msg, 0)
183+
await ctxMain.publish("test/random1", msg, 0)
184+
await ctxMain.publish("test/random2", msg, 0)
185+
await ctxMain.publish("test/random3", msg, 0)
186186
await sleepAsync 500
187-
await ctxListen.unsubscribe("#")
187+
await ctxListen.unsubscribe("test/#")
188188
await sleepAsync 500
189189
check(msgCount == 3)
190190

191191
waitFor conn()
192192

193-
194193
test "stay subscribed after disconnect with reconnect":
195194
let (tpc, msg) = tdata("stay subscribed after disconnect with reconnect")
196195

0 commit comments

Comments
 (0)