{"id":15372958,"url":"https://github.com/rs/moquette","last_synced_at":"2025-04-15T12:31:34.480Z","repository":{"id":66040891,"uuid":"143843479","full_name":"rs/moquette","owner":"rs","description":"MQTT service dispatcher","archived":false,"fork":false,"pushed_at":"2019-01-10T01:10:32.000Z","size":14,"stargazers_count":38,"open_issues_count":2,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T21:11:35.370Z","etag":null,"topics":["golang","iot","iot-gateway","mqtt","mqtt-service"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-07T08:30:18.000Z","updated_at":"2024-02-14T09:34:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"313002c4-c763-43fa-8aeb-9642e9aa2751","html_url":"https://github.com/rs/moquette","commit_stats":{"total_commits":5,"total_committers":1,"mean_commits":5.0,"dds":0.0,"last_synced_commit":"93634729c55a45b35ec6512400c0db90f2449009"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rs%2Fmoquette","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rs%2Fmoquette/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rs%2Fmoquette/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rs%2Fmoquette/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rs","download_url":"https://codeload.github.com/rs/moquette/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249072238,"owners_count":21208142,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","iot","iot-gateway","mqtt","mqtt-service"],"created_at":"2024-10-01T13:53:50.176Z","updated_at":"2025-04-15T12:31:34.234Z","avatar_url":"https://github.com/rs.png","language":"Go","readme":"# Moquette — MQTT Service Dispatcher\n\nMoquette is to MQTT what inetd is to IP. Moquette listens for events from an MQTT broker and executes a process (event handler) found in its configuration directory if its name matches the event's topic. The matching obeys to the MQTT topic rules. Slashes in the topic are replaced by colon (:).\n\nFor instance, the following file names will all match the topic `home/office/lamp/setOn`:\n\n  * `home:office:lamp:setOn`\n  * `home:office:+:setOn`\n  * `home:office:#`\n  * `#`\n\nEvent handler files must be at the root of the Moquette configuration directory and have their executable flag set. The default directory is `/etc/moquette.d` and can be changed using the `--conf` option. New files can be added/removed while Moquette is running, without the need to restart it.\n\nWhen an event handler is executed, Moquette sends the event payload as first argument to the command and the event topic is set as the `$MQTT_TOPIC` environment variable. The message ID is also transmitted using the `$MQTT_MSGID` environment variable.\n\nA command can send events back by writing to the file descriptor number 3. The Format is as follow:\n\n    PUB \u003ctopic\u003e \u003cqos\u003e \u003cpayload length\u003e\\n\n    \u003cpayload\u003e\n\nFor instance, to send \"hello world\" on the `example/somewhere` topic using bash:\n\n```bash\nmsg=\"hello world\"\necho -e \"PUB example/somewhere 0 ${#msg}\\n$msg\" \u003e\u00263\n```\n\nMoquette will wait as long as necessary for the process to finish its execution. This way it is possible to delay the response to an event, or send multiple events spread in time to implement a timer for instance.\n\n## Handler Examples\n\nThe examples below are written in bash, but handlers can be written in any language. You can find more examples in the [conf](conf/) directory.\n\n### example:echo:+:in\n\n```bash\n#!/bin/bash\n\necho -e \"PUB ${MQTT_TOPIC%*in}out 0 ${#1}\\n$1\" \u003e\u00263\n```\n\nThis handler responds to any event written on a matching topic, and sends back an event on the same topic by replacing `in` by `out`.\n\nFor instance, sending \"hello world\" to `example/echo/test/in` will send back \"hello world\" to the topic `example/echo/test/out`.\n\n### example:timer:+:set\n\n```bash\n#!/bin/bash\n\n# Kill concurrent run of ourselves\necho \"KILL $MQTT_TOPIC\" \u003e\u00263\n\nn=$1\nwhile [ $n -ge 0 ]; do\n    sleep 1\n    echo -e \"PUB ${MQTT_TOPIC%*set}tick 0 ${#n}\\n$n\" \u003e\u00263\n    ((n--))\ndone\n```\n\nThis handler sends a tick every second for `n` seconds when `n` is sent to a matching topic. Ticks are sent on the same topic with the last `set` component replaced by `tick`.\n\nNote that we introduced the `KILL` command here. A `KILL` followed by a topic, will kill all existing running commands that match the provided topic. The current process is never killed, even if the topic matches.\n\n## Install\n\nFrom source:\n\n    go get -u github.com/rs/moquette\n\nUsing docker (assuming the `conf/` directory contains your handlers):\n\n    docker run -it --rm -v $(pwd)/conf:/etc/moquette.d poitrus/moquette -broker tcp://\u003cbroker_ip\u003e:1883\n\n## License\n\nAll source code is licensed under the [MIT License](https://raw.github.com/rs/moquette/master/LICENSE).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frs%2Fmoquette","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frs%2Fmoquette","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frs%2Fmoquette/lists"}