You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Addition of subx to allow user to choose quality of service level
Docs on quality of service levels (for publishing and subscribing) - affects performance/quality/throughput
Prev sub method hardcoded with a QoS level.
Existing sub functionality not changed (calls subx).
Copy file name to clipboardExpand all lines: docs/reference.md
+48-3Lines changed: 48 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,7 @@ They allow you to interact with MQTT brokers and send and receive messages.
13
13
[`pub`](#mqttpub) publish a message to a topic<br>
14
14
[`pubx`](#mqttpubx) publish a message to a topic controlling qos and ret<br>
15
15
[`sub`](#mqttsub) subscribe to a topic<br>
16
+
[`subx`](#mqttsubx) subscribe to a topic<br>
16
17
[`unsub`](#mqttunsub) unsubscribe from a topic
17
18
18
19
**Callback functions**<br>
@@ -209,7 +210,7 @@ q).mqtt.pub[`topic1;"This is a test message"];
209
210
>
210
211
> Where
211
212
>
212
-
> 1.`kqos` is set to 1. The broker/client will deliver the message at least once, with confirmation required.
213
+
> 1.`kqos` is set to 1. The broker/client will deliver the message at least once, with ack messages required.
213
214
> 2.`kret` is set to `0b`. Messages are not retained after sending.
214
215
215
216
@@ -225,7 +226,10 @@ Where
225
226
226
227
-`topic` is a symbol denoting the topic that the message is to be sent to
227
228
-`msg` is a string of the message being sent to the broker
228
-
-`kqos` is an long denoting the quality of service to be used
229
+
-`kqos` is an long denoting the quality of service to be used. The higher the quality of service, the lower the throughput/performance. Possible values are:
230
+
- 0 (QoS 0 - at most once) comparable to TCP
231
+
- 1 (Qos 1 - at least once) as with QoS 0 but with use of ack message for each message sent
232
+
- 2 (QoS 2 - only once) as with QoS 1 but with use of multiple request/response flows for each message
229
233
-`kret` is a boolean denoting if published messages are to be retained
230
234
231
235
returns a callback to the process stating that the message has been sent to the broker.
@@ -248,7 +252,7 @@ _Subscribe to a topic on a Mosquitto broker process_
248
252
.mqtt.sub topic
249
253
```
250
254
251
-
Where `topic` is a symbol denoting the topic that the process should listen to, returns a callback to the process when a message is received on topic stating that the message was received and what that message is.
255
+
Where `topic` is a symbol denoting the topic that the process should listen to. Received msgs on that topic can then be processed via the callback [.mqtt.msgrcvd](mqttmsgrecv)
252
256
253
257
```q
254
258
// Connect to the host broker and publish a message
@@ -259,6 +263,47 @@ q).mqtt.sub[`topic1]
259
263
(`msgrcvd;"topic1";"This is a test message")
260
264
```
261
265
266
+
> This function is a projection of the function `.mqtt.pubx` defined below.
267
+
>
268
+
> Where
269
+
>
270
+
> 1.`kqos` is set to 1. The broker/client will deliver the message at least once, with confirmation messages sent to the broker from the subscriber for each message received.
271
+
272
+
## `.mqtt.subx`
273
+
274
+
_Subscribe to a topic on a Mosquitto broker process, controlling quality of service_
275
+
276
+
```txt
277
+
.mqtt.subx[topic;kqos]
278
+
```
279
+
280
+
Where `
281
+
282
+
-`topic` is a symbol denoting the topic that the process should listen to. Received msgs on that topic can then be processed via the callback [.mqtt.msgrcvd](mqttmsgrecv)
283
+
-`kqos` is an long denoting the quality of service to be used. The higher the quality of service, the lower the throughput/performance. Possible values are:
284
+
- 0 (QoS 0 - at most once) comparable to TCP
285
+
- 1 (Qos 1 - at least once) as with QoS 0 but with use of ack message for each message sent
286
+
- 2 (QoS 2 - only once) as with QoS 1 but with use of multiple request/response flows for each message
287
+
288
+
> Note that the subscriber QoS can downgrade the intended Qos from the publisher, but not upgrade it. For example, when publisher subscriber using QoS 0 or 1 with a Mosquitto broker:
289
+
>
290
+
> | Pub QoS | Sub QoS | Acks From Broker to Pub | Acks from Sub to Broker |
291
+
> | --- | --- | --- | --- |
292
+
> |0|0|No|No|
293
+
> |1|0|Yes|No|
294
+
> |0|1|No|No|
295
+
> |1|1|Yes|Yes|
296
+
>
297
+
> In this scenario, when the publisher uses QoS 1 and the subscriber has less requirements for QoS (ie. can set to 0), the subscriber will gain better performance.
298
+
299
+
```q
300
+
// Connect to the host broker and publish a message
301
+
q).mqtt.conn[`$"tcp://localhost:1883";`rcv]
302
+
303
+
// Subscribe to topic1 and recieve a message sent to that topic
0 commit comments