zzq 0.1.1 → 0.2.0

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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -0
  3. data/LICENSE-APACHE +202 -0
  4. data/LICENSE-ISC +15 -0
  5. data/README.md +67 -122
  6. data/ext/zzq_native/Cargo.toml +35 -0
  7. data/ext/zzq_native/extconf.rb +8 -0
  8. data/ext/zzq_native/src/broker.rs +163 -0
  9. data/ext/zzq_native/src/client.rs +294 -0
  10. data/ext/zzq_native/src/context.rs +51 -0
  11. data/ext/zzq_native/src/error.rs +117 -0
  12. data/ext/zzq_native/src/lib.rs +52 -0
  13. data/ext/zzq_native/src/op.rs +140 -0
  14. data/ext/zzq_native/src/options.rs +168 -0
  15. data/ext/zzq_native/src/rb.rs +424 -0
  16. data/ext/zzq_native/src/wake.rs +155 -0
  17. data/lib/zzq/broker.rb +90 -21
  18. data/lib/zzq/client.rb +202 -35
  19. data/lib/zzq/errors.rb +37 -0
  20. data/lib/zzq/message.rb +16 -107
  21. data/lib/zzq/options.rb +27 -86
  22. data/lib/zzq/version.rb +2 -1
  23. data/lib/zzq/waiting.rb +65 -0
  24. data/lib/zzq.rb +22 -19
  25. metadata +33 -77
  26. data/LICENSE +0 -13
  27. data/lib/zzq/engine/connection_lifecycle.rb +0 -139
  28. data/lib/zzq/engine/keepalive.rb +0 -75
  29. data/lib/zzq/engine/socket_lifecycle.rb +0 -79
  30. data/lib/zzq/engine.rb +0 -169
  31. data/lib/zzq/error.rb +0 -42
  32. data/lib/zzq/monitor_event.rb +0 -14
  33. data/lib/zzq/persistence/interface.rb +0 -43
  34. data/lib/zzq/persistence/memory.rb +0 -37
  35. data/lib/zzq/persistence/pstore.rb +0 -66
  36. data/lib/zzq/routing/broker.rb +0 -380
  37. data/lib/zzq/routing/client.rb +0 -327
  38. data/lib/zzq/routing/packet_id_allocator.rb +0 -54
  39. data/lib/zzq/routing/qos_tracker.rb +0 -108
  40. data/lib/zzq/routing/retained_store.rb +0 -67
  41. data/lib/zzq/routing/topic_match.rb +0 -49
  42. data/lib/zzq/routing/topic_trie.rb +0 -232
  43. data/lib/zzq/socket.rb +0 -146
  44. data/lib/zzq/subscription.rb +0 -70
  45. data/lib/zzq/transport/ipc.rb +0 -92
  46. data/lib/zzq/transport/mqtt.rb +0 -83
  47. data/lib/zzq/transport/mqtts.rb +0 -173
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87925e5f4e25692989436ea262564b72a644c7a03973bd381424fcc7658e1434
4
- data.tar.gz: 2af870528ce076a739bd9095af5a628241c60aee97f4bf20037c7677b8c9e11c
3
+ metadata.gz: 4be497064f4ec7960826caa789a5fc3ab8cfc0123122b8a3a52d4ab74478a6d8
4
+ data.tar.gz: 463167e687bed7d514d987721aba27982e2f66371457b27848bb401a207df31c
5
5
  SHA512:
6
- metadata.gz: 69c572236412a029e78e65d792a0e489782b653fe52e36ab79d55efddf55aefe838689d7fd46428c00e43329c7b2c273e8626463306e330c9038cf4ba6aaa7a7
7
- data.tar.gz: 56f03ad05f16d98a753fcc6d83af72b45bf607c369eaff62189a09aba8099df44d532d1ec39025a1ebd9efcc73cd54433c68728891e4f45951f6f2a453dfdbcd
6
+ metadata.gz: 35ede1ed6a54c82572a49a2fa008d60c307ec3612e67d9e0fb9bd834e2056f5d503d362dcd461144f3a8393c7b23adf42ec5bcbbe141ab2950ceef8b9b916b12
7
+ data.tar.gz: 309c1c8350ed1b372ece13d2a8729fce44d06ab5405146e4072821cdd41b998d148c498261f400ba6d3f888c9f2470f2dbf9c5bb53e3c953edb9b9bb726a57c7
data/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # Changelog
2
2
 
3
+ ## [Unreleased]
4
+
5
+ ## v0.2.0 — 2026-10-26
6
+
7
+ - zzq is now a binding to the zzq Rust crates, built as a native
8
+ extension with rb-sys. It needs Rust 1.93 to install and Ruby 3.4.
9
+ - Calls no longer need an Async task: they wait under any fiber
10
+ scheduler, and release the GVL in plain threads.
11
+ - `Client#receive` and `Client#each` take messages from one inbox per
12
+ client. `#subscribe` returns the granted QoS; `Subscription`,
13
+ `Message#ack!`, message properties and `#monitor` are gone.
14
+ - New: reconnect with session resume, will delay, `#unsubscribe`,
15
+ `#disconnect(reason:)`, and `IO::TimeoutError` from `receive(timeout:)`.
16
+ - `session_expiry_interval:` is now `session_expiry:` and `recv_hwm:` is
17
+ `inbox:`. `linger:`, `send_hwm:`, `receive_maximum:`, `max_packet_size:`
18
+ and `topic_alias_maximum:` are gone from the client.
19
+ - `ZZQ::Broker` gets `#publish`, `#stats`, the limits of zzq-broker and
20
+ an MQTT-SN gateway on `udp://`. `persistence:` takes the path of a log
21
+ file instead of a store object. `#ingest`, `#<<` and `#session_count`
22
+ are gone.
23
+ - `ws://`, `wss://`, `quic://` and `inproc://` are built in; the
24
+ zzq-websocket gem is no longer needed.
25
+ - Dual-licensed under ISC or Apache-2.0, at your option.
26
+
3
27
  ## v0.1.1 — 2026-04-20
4
28
 
5
29
  - `Engine#handle_accepted` and `Engine#handle_connected` now return the
data/LICENSE-APACHE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/LICENSE-ISC ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2026 Patrik Wenger
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ PERFORMANCE OF THIS SOFTWARE.
data/README.md CHANGED
@@ -1,153 +1,98 @@
1
- # ZZQ — async-native MQTT for Ruby
1
+ # zzq for Ruby
2
2
 
3
- > Codename **Zanzara** — Italian for "mosquito", in the same spirit as
4
- > the Mosquitto broker that popularised MQTT. `zzq` keeps the
5
- > three-letter gem-name symmetry with its siblings `omq` and `nnq`.
3
+ MQTT 3.1.1 and 5.0 client and broker for Ruby, with an MQTT-SN gateway.
4
+ The `zzq` gem binds the [zzq](https://github.com/paddor/zzq) Rust crates:
5
+ connections run on Rust IO threads, and Ruby only hands messages in and
6
+ out.
6
7
 
7
- [![CI](https://github.com/paddor/zzq/actions/workflows/ci.yml/badge.svg)](https://github.com/paddor/zzq/actions/workflows/ci.yml)
8
- [![Gem Version](https://img.shields.io/gem/v/zzq?color=e9573f)](https://rubygems.org/gems/zzq)
9
- [![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg)](LICENSE)
10
- [![Ruby](https://img.shields.io/badge/Ruby-%3E%3D%204.0-CC342D?logo=ruby&logoColor=white)](https://www.ruby-lang.org)
8
+ Calls wait without blocking other fibers under a fiber scheduler such as
9
+ [Async](https://github.com/socketry/async), and release the GVL in plain
10
+ threads.
11
11
 
12
- ZZQ is a pure-Ruby MQTT 3.1.1 + 5.0 implementation — **client and
13
- broker in one gem** — built on [async](https://github.com/socketry/async),
14
- [io-stream](https://github.com/socketry/io-stream), and
15
- [protocol-mqtt](https://github.com/paddor/protocol-mqtt). It applies
16
- the [omq](https://github.com/paddor/omq) / [nnq](https://github.com/paddor/nnq)
17
- architecture to MQTT.
12
+ ## Install
18
13
 
19
- Status: pre-alpha. See [the design plan](../../.claude/plans/omq-and-nnq-s-design-robust-dolphin.md) for scope and roadmap.
14
+ ```sh
15
+ gem install zzq
16
+ ```
17
+
18
+ The gem builds its native extension on install, which needs Rust 1.93 or
19
+ newer.
20
20
 
21
- ## Quickstart
21
+ ## Client
22
22
 
23
23
  ```ruby
24
24
  require "zzq"
25
- require "async"
26
25
 
27
- # Client
28
- Async do
29
- client = ZZQ::Client.new(client_id: "sensor-42", version: 5, keepalive: 30)
30
- client.connect("mqtt://broker.example:1883") do |task|
31
- sub = client.subscribe("cmd/#", qos: 1)
32
- task.async do
33
- sub.each { |msg| puts "#{msg.topic}: #{msg.payload}" }
34
- end
35
- client.publish("status/sensor-42", "online", qos: 1, retain: true)
36
- end
37
- end
38
-
39
- # Broker
40
- Async do
41
- ctx = OpenSSL::SSL::SSLContext.new
42
- ctx.cert = OpenSSL::X509::Certificate.new(File.read("server.crt"))
43
- ctx.key = OpenSSL::PKey.read(File.read("server.key"))
44
- # Recommended: TLS 1.3 with DJB-family AEAD.
45
- ctx.min_version = OpenSSL::SSL::TLS1_3_VERSION
46
- ctx.max_version = OpenSSL::SSL::TLS1_3_VERSION
47
- ctx.ciphersuites = "TLS_CHACHA20_POLY1305_SHA256"
48
-
49
- broker = ZZQ::Broker.new
50
- broker.bind("mqtt://0.0.0.0:1883")
51
- broker.bind("mqtts://0.0.0.0:8883", tls_context: ctx)
52
- # ... bind more transports on the same broker
26
+ ZZQ::Client.connect("mqtt://localhost", client_id: "sensor-42") do |client|
27
+ client.subscribe("cmd/#", qos: 1)
28
+ client.publish("status/sensor-42", "online", qos: 1, retain: true)
29
+ client.each { |message| puts "#{message.topic}: #{message.payload}" }
53
30
  end
54
31
  ```
55
32
 
56
- ## Transports
57
-
58
- - `mqtt://` — plain MQTT over TCP (default port 1883).
59
- - `mqtts://` — MQTT over TLS (default port 8883). Takes any
60
- `OpenSSL::SSL::SSLContext` via `tls_context:`; the recommended
61
- configuration is TLS 1.3 pinned to `TLS_CHACHA20_POLY1305_SHA256`
62
- as shown above. The transport drops the connection at 128 GiB
63
- of application data — well below ChaCha20-Poly1305's ~256 GiB
64
- per-key integrity bound — so reconnects force fresh keys before
65
- AEAD nonce counters approach their unsafe range.
66
- - `ws://` / `wss://` — MQTT over WebSockets.
67
- - `ipc:///path` — Unix-domain socket, filesystem path.
68
- - `ipc://@abstract` — Linux abstract-namespace Unix socket.
69
-
70
- ## Persistence
71
-
72
- By default the broker keeps retained messages in process memory — fast,
73
- zero-config, and lost when the process exits. That's the right choice
74
- for tests and ephemeral workloads.
75
-
76
- For durability across restarts, pass a `PStore`-backed persistence
77
- object. It uses stdlib [`PStore`](https://docs.ruby-lang.org/en/master/PStore.html)
78
- with `ultra_safe = true` so every commit fsyncs the data file and its
79
- parent directory — retained state survives power loss, not just clean
80
- shutdowns.
33
+ - `publish(topic, payload, qos:, retain:)` returns once queued for QoS 0,
34
+ and once acked for QoS 1 and 2.
35
+ - `subscribe(filter, qos:)` returns the granted QoS. MQTT 5 options:
36
+ `no_local:`, `retain_as_published:`, `retain_handling:`,
37
+ `subscription_id:`.
38
+ - `receive(timeout:)` returns the next `ZZQ::Message`, or nil once the
39
+ client is closed. `each` yields messages until then.
40
+ - Publishing works from any fiber or thread; one fiber at a time
41
+ receives.
42
+
43
+ Options of `ZZQ::Client.new` and `.connect`: `client_id:`, `version:` (5 or
44
+ 3), `clean_start:`, `keep_alive:`, `session_expiry:`, `username:`,
45
+ `password:`, `will:` (`topic:`, `payload:`, `qos:`, `retain:`, `delay:`),
46
+ `inbox:`, `reconnect:` (true, or `min:`/`max:` seconds), `connect_timeout:`
47
+ and `tls:` (`ca:`, `cert:`, `key:` as PEM strings, `server_name:`,
48
+ `insecure:`).
49
+
50
+ ## Broker
81
51
 
82
52
  ```ruby
83
- # Default: in-memory, ephemeral
84
- broker = ZZQ::Broker.new
85
-
86
- # Explicit in-memory (same as default)
87
- broker = ZZQ::Broker.new persistence: ZZQ::Persistence::Memory.new
88
-
89
- # Durable: retained messages persist to ./zzq-data/
90
- persistence = ZZQ::Persistence::PStore.new data_dir: "./zzq-data"
91
- broker = ZZQ::Broker.new persistence: persistence
53
+ broker = ZZQ::Broker.new(persistence: "retained.log")
54
+ broker.bind("mqtt://0.0.0.0:1883")
55
+ broker.bind("ws://0.0.0.0:8080")
56
+ broker.publish("status/broker", "up", retain: true)
57
+ broker.stats # => {connections: 0, sessions: 0, ...}
58
+ broker.close
92
59
  ```
93
60
 
94
- PStore is single-process only — file locking doesn't coordinate across
95
- processes. For HA deployments, a future external adapter (Redis,
96
- SQLite) will ship as a separate gem.
97
-
98
- ## Bridging two brokers
61
+ Options take the limits of zzq-broker's `BrokerOptions`, such as
62
+ `max_connections:` or `max_queued:`, plus `sys_interval:`,
63
+ `connect_timeout:`, `persistence:` and `tls:` (`cert:`, `key:`,
64
+ `client_ca:`).
99
65
 
100
- ZZQ does not ship a `Bridge` class — broker-to-broker forwarding is a
101
- short composition of a `Client` and a local `Broker`. Subscribe on one
102
- side, publish to the other:
66
+ ## Async
103
67
 
104
68
  ```ruby
105
- require "zzq"
106
69
  require "async"
107
70
 
108
71
  Async do |task|
109
- upstream = ZZQ::Client.new(client_id: "site-42-bridge", version: 5)
110
- local = ZZQ::Broker.new
111
-
112
- upstream.connect("mqtts://cloud.example:8883")
113
- local.bind("mqtt://0.0.0.0:1883")
114
-
115
- # local → upstream: forward telemetry out.
116
- task.async do
117
- local.subscribe("telemetry/#", qos: 1).each do |m|
118
- upstream.publish(m.topic, m.payload, qos: m.qos, retain: m.retain)
119
- end
120
- end
121
-
122
- # upstream → local: pull commands in. `Broker#<<` fans the Message
123
- # straight into the local broker's delivery path — no need to pick
124
- # apart and re-pack fields (alias of `#ingest`).
125
- task.async do
126
- upstream.subscribe("cmd/#", qos: 1, no_local: true).each do |m|
127
- local << m
128
- end
129
- end
72
+ client = ZZQ::Client.connect("mqtt://localhost")
73
+ client.subscribe("jobs")
74
+ task.async { client.each { |message| handle(message) } }
75
+ 10.times { |i| task.async { client.publish("jobs", i.to_s, qos: 1) } }
130
76
  end
131
77
  ```
132
78
 
133
- Loop guard for two-way routes:
79
+ ## Transports
134
80
 
135
- * MQTT v5: pass `no_local: true` on the subscribe call — the spec
136
- forbids the broker from echoing back to the publisher of the
137
- subscription, so messages originating on one side don't bounce.
138
- * MQTT v3.1.1: no `no_local`. Use non-overlapping filters on each
139
- direction, or tag topics with a side-specific prefix.
81
+ `mqtt://` and `tcp://`, `mqtts://` and `tls://`, `ws://`, `wss://`,
82
+ `quic://`, `ipc://`, `inproc://`, and `udp://` for an MQTT-SN gateway on
83
+ the broker.
140
84
 
141
- ## When MQTT, when OMQ/NNQ
85
+ ## IO threads
142
86
 
143
- MQTT bridging makes sense only when the remote speaks MQTT and nothing
144
- else (AWS IoT Core, HiveMQ Cloud, partner Mosquitto). For inter-service
145
- comm where both ends are under your control, reach for
146
- [omq](https://github.com/paddor/omq) or [nnq](https://github.com/paddor/nnq)
147
- — cleaner wire format, no protocol overhead. ZZQ exposes
148
- `ZZQ::Message#to_wire` / `.from_wire` so you can ship MQTT messages
149
- across an OMQ/NNQ socket without re-encoding.
87
+ Clients and brokers of a process share its IO lanes, one by default. Set
88
+ `ZZQ.io_threads = n` before the first client or broker to use more.
150
89
 
151
90
  ## License
152
91
 
153
- ISC. See [LICENSE](LICENSE).
92
+ Licensed under either of [ISC](LICENSE-ISC) or
93
+ [Apache-2.0](LICENSE-APACHE), at your option.
94
+
95
+ Unless you explicitly state otherwise, any contribution intentionally
96
+ submitted for inclusion in the work by you, as defined in the Apache-2.0
97
+ license, shall be dual licensed as above, without any additional terms or
98
+ conditions.
@@ -0,0 +1,35 @@
1
+ [package]
2
+ name = "zzq_native"
3
+ version = "0.2.0"
4
+ edition = "2024"
5
+ rust-version = "1.93"
6
+ license = "ISC OR Apache-2.0"
7
+ authors = ["Patrik Wenger <paddor@gmail.com>"]
8
+ publish = false
9
+
10
+ [lib]
11
+ name = "zzq_native"
12
+ crate-type = ["cdylib"]
13
+
14
+ [dependencies]
15
+ zzq-broker = "0.1"
16
+ zzq-client = "0.1"
17
+ bytes = "1.12"
18
+ libc = "0.2"
19
+ rb-sys = "0.9"
20
+ tokio = { version = "1.53", default-features = false, features = ["sync"] }
21
+
22
+ [lints.rust]
23
+ missing_debug_implementations = "deny"
24
+ unsafe_op_in_unsafe_fn = "deny"
25
+ rust_2018_idioms = { level = "warn", priority = -1 }
26
+
27
+ [lints.clippy]
28
+ all = { level = "warn", priority = -1 }
29
+ pedantic = { level = "warn", priority = -1 }
30
+ module_name_repetitions = "allow"
31
+ missing_errors_doc = "allow"
32
+ missing_panics_doc = "allow"
33
+ must_use_candidate = "allow"
34
+ cast_possible_truncation = "allow"
35
+ cast_sign_loss = "allow"
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mkmf"
4
+ require "rb_sys/mkmf"
5
+
6
+ create_rust_makefile("zzq/zzq_native") do |r|
7
+ r.profile = ENV.fetch("RB_SYS_CARGO_PROFILE", :release).to_sym
8
+ end