<!-- Kamailio Pull Request Template -->
<!-- IMPORTANT: - for detailed contributing guidelines, read: https://github.com/kamailio/kamailio/blob/master/.github/CONTRIBUTING.md - pull requests must be done to master branch, unless they are backports of fixes from master branch to a stable branch - backports to stable branches must be done with 'git cherry-pick -x ...' - code is contributed under BSD for core and main components (tm, sl, auth, tls) - code is contributed GPLv2 or a compatible license for the other components - GPL code is contributed with OpenSSL licensing exception -->
#### Pre-Submission Checklist <!-- Go over all points below, and after creating the PR, tick all the checkboxes that apply --> <!-- All points should be verified, otherwise, read the CONTRIBUTING guidelines from above--> <!-- If you're unsure about any of these, don't hesitate to ask on sr-dev mailing list --> - [x] Commit message has the format required by CONTRIBUTING guide - [x] Commits are split per component (core, individual modules, libs, utils, ...) - [x] Each component has a single commit (if not, squash them into one commit) - [ ] No commits to README files for modules (changes must be done to docbook files in `doc/` subfolder, the README file is autogenerated)
#### Type Of Change - [ ] Small bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds new functionality) - [ ] Breaking change (fix or feature that would change existing functionality)
#### Checklist: <!-- Go over all points below, and after creating the PR, tick the checkboxes that apply --> - [ ] PR should be backported to stable branches - [x] Tested changes locally - [ ] Related to issue #XXXX (replace XXXX with an open issue number)
#### Description <!-- Describe your changes in detail -->
New Module to participate in a MQTT pub/sub messaging system.
Initial Features:
- automatic reconnect with connected/disconnected event routes - support mqtt last will feature - subscribe and unsubscribe topics via script code - receive messages via event route - send messages from script code - full KEMI support
You can view, comment on, or merge this pull request online at:
https://github.com/kamailio/kamailio/pull/2187
-- Commit Summary --
* mqtt: module to support mqtt pubsub messaging
-- File Changes --
A src/modules/mqtt/Makefile (37) A src/modules/mqtt/README (349) A src/modules/mqtt/doc/Makefile (4) A src/modules/mqtt/doc/mqtt.xml (37) A src/modules/mqtt/doc/mqtt_admin.xml (399) A src/modules/mqtt/mqtt_dispatch.c (711) A src/modules/mqtt/mqtt_dispatch.h (71) A src/modules/mqtt/mqtt_mod.c (394)
-- Patch Links --
https://github.com/kamailio/kamailio/pull/2187.patch https://github.com/kamailio/kamailio/pull/2187.diff
I would love to see TLS support clearly implemented and documented. After all, it's 2020 :-)
oej commented on this pull request.
+ If defined, the module calls event_route[mqtt:message] when a message + is received from the broker. + + All incoming messages are handled in a single mqtt dispatcher process. +... +event_route[mqtt:message] { + xlog("mqtt message received: $mqtt(topic) -> $mqtt(msg) !\n"); +} +... + +6. Exported pseudo-variables + + * $mqtt(topic) - Received topic (only in mqtt:message) + * $mqtt(msg) - Received message (only in mqtt:message) +
How do I reach the QoS value for the message?
Thank you for this pull request. Generally, I miss these improvements to your code: - TLS - Failover (multiple MQTT servers)
Maybe one could want to set event_route per subscription too.
towe75 commented on this pull request.
+ If defined, the module calls event_route[mqtt:message] when a message + is received from the broker. + + All incoming messages are handled in a single mqtt dispatcher process. +... +event_route[mqtt:message] { + xlog("mqtt message received: $mqtt(topic) -> $mqtt(msg) !\n"); +} +... + +6. Exported pseudo-variables + + * $mqtt(topic) - Received topic (only in mqtt:message) + * $mqtt(msg) - Received message (only in mqtt:message) +
@oej it's not exposed ATM but it's simple to add it. I will enhance the module accordingly.
@oej thank you for the **really** quick review (only a couple of minutes after submission).
I will check the effort for TLS support. It should not be very high given the fact that libmosquitto exposes a highlevel API for it.
Regarding event_route per subscription: it's a nice idea and saves the script author a bit of boilerplate code. On the other hand: it would have to support pattern matching for wildcard topics to be really useful. I will not add it for now because of expected complexity.
Regarding event_route per subscription: I was toying with the idea to add a new parameter to the subscribe function. I think you consider something more automatic, but that would be more complex. Why not just add a third parameter?
@oej: it would IMHO only be simple for "static" subscriptions like "kamailio/foo" -> on_mqtt_foo().
But what about wildcard subscriptions like "kamailio/+/unregister" or "kamailio/#" ? I can, of course, forbit these mappings by some validation rule but a cleaner solution would be to pattern-match each incoming message against the wildcard subscription to find the correct route.
It's IMHO a somewhat sophisticated feature for a later version, if the need arises. For now the mapping for incoming messages can be done in script code. We can discuss about it in more detail on the mailing list or some other channel, if you want.
Ok, let's add new features later and polish this module. It's a very good start compared with my core-dumping first attempt :-)
Will try to test it soon.
@towe75 pushed 2 commits.
81852e5ba1fa6983df44f591c40154ea5fcef6b8 mqtt: add tls support ea699419df555b4453e1eb96659cfec8912ac3bc mqtt: expose received message qos level via pv
towe75 commented on this pull request.
+ If defined, the module calls event_route[mqtt:message] when a message + is received from the broker. + + All incoming messages are handled in a single mqtt dispatcher process. +... +event_route[mqtt:message] { + xlog("mqtt message received: $mqtt(topic) -> $mqtt(msg) !\n"); +} +... + +6. Exported pseudo-variables + + * $mqtt(topic) - Received topic (only in mqtt:message) + * $mqtt(msg) - Received message (only in mqtt:message) +
@oej, see commit ea69941
I added TLS support in commit 81852e5. The documentation is enhanced as well.
It's now possible to have a plain connection as well as TLS with configurable method, ciphers, client certificate and - if desired - disabled server cert checks.
Parameters are more or less directly forwarded to libmosquitto and subsequently into openssl. So the default optionset depends on the installed openssl version and the available libmosquitto version.
Going to merge it, is not a lot of code and further reviews and adjustments can be done directly in the repo afterwards. I will grant @towe75 git commit access so he can maintain the module. Thanks for the contribution!
Merged #2187 into master.