### Running HMQ MQTT Broker Source: https://github.com/fhmq/hmq/blob/master/README.md This snippet provides the commands to download, navigate to, and run the HMQ MQTT broker from its source code. It requires Go and Git to be installed and configured on the system. The `go get` command fetches the repository, `cd` changes the directory, and `go run` compiles and executes the `main.go` file to start the broker. ```bash $ go get github.com/fhmq/hmq $ cd $GOPATH/github.com/fhmq/hmq $ go run main.go ``` -------------------------------- ### Comprehensive ACL Configuration Example Source: https://github.com/fhmq/hmq/blob/master/plugins/auth/authfile/Readme.md This snippet provides a comprehensive example of ACL rules, demonstrating various types of access controls based on IP address, client ID, and username. It includes rules for allowing specific IPs to publish to system topics, granting full access to specific client IDs and usernames, allowing specific users access to particular topics, and defining rules for publishing to cloud topics based on client ID or username. It concludes with a general deny rule for all clients. ```ACL Configuration ## type clientid , username, ipaddr ##sub 1 , pub 2, pubsub 3 ## %c is clientid , %u is username allow ip 127.0.0.1 2 $SYS/# allow clientid 0001 3 # allow username admin 3 # allow username joy 3 /test,hello/world allow clientid * 1 toCloud/%c allow username * 1 toCloud/%u deny clientid * 3 # ``` -------------------------------- ### MQTT Shared Subscription Syntax Source: https://github.com/fhmq/hmq/blob/master/README.md This snippet demonstrates the syntax for MQTT shared subscriptions, allowing multiple clients to subscribe to the same topic and distribute messages among them. It shows the `$share//topic` prefix for subscribing and a standard `topic` for publishing, using `mosquitto_sub` and `mosquitto_pub` as examples. This feature enables load balancing of messages across a group of subscribers. ```markdown | Prefix | Examples | Publish | | ------------------- |-------------------------------------------|--------------------------- --| | $share//topic | mosquitto_sub -t ‘$share//topic’ | mosquitto_pub -t ‘topic’ | ``` -------------------------------- ### Setting Up HMQ Cluster Router Source: https://github.com/fhmq/hmq/blob/master/README.md This snippet provides instructions for setting up the router component required for HMQ clustering. It involves fetching and running the `fhmq/router` Go project, followed by configuring the `router` address in the main `hmq.config` file. This router is essential for maintaining cluster information and enabling distributed broker operations. ```bash 1, start router for hmq (https://github.com/fhmq/router.git) $ go get github.com/fhmq/router $ cd $GOPATH/github.com/fhmq/router $ go run main.go 2, config router in hmq.config ("router": "127.0.0.1:9888") ``` -------------------------------- ### HMQ Command-Line Options Source: https://github.com/fhmq/hmq/blob/master/README.md This snippet outlines the various command-line options available for configuring the HMQ MQTT broker. It details parameters for broker settings (worker number, ports, host), logging, cluster integration (router URL, cluster port), and common options like displaying help. These options allow for quick configuration without a separate file. ```bash Usage: hmq [options] Broker Options: -w, --worker Worker num to process message, perfer (client num)/10. (default 1024) -p, --port Use port for clients (default: 1883) --host Network host to listen on. (default "0.0.0.0") -ws, --wsport Use port for websocket monitoring -wsp,--wspath Use path for websocket monitoring -c, --config Configuration file Logging Options: -d, --debug Enable debugging output (default false) -D Debug enabled Cluster Options: -r, --router Router who maintenance cluster info -cp, --clusterport Cluster listen port for others Common Options: -h, --help Show this message ``` -------------------------------- ### Allow Specific User Access to Defined Topics Source: https://github.com/fhmq/hmq/blob/master/plugins/auth/authfile/Readme.md This rule allows the user 'joy' to both publish and subscribe ('3') to the specific topics '/test' and 'hello/world'. This demonstrates fine-grained topic-level access control for individual users, limiting their interaction to predefined topics. ```ACL Configuration #allow client with the username joy can pub sub topic '/test' and 'hello/world' allow username joy 3 /test,hello/world ``` -------------------------------- ### HMQ Broker Configuration File (JSON) Source: https://github.com/fhmq/hmq/blob/master/README.md This JSON snippet illustrates the structure of the `hmq.config` file used for persistent configuration of the HMQ MQTT broker. It allows setting worker numbers, network ports, host addresses, cluster details, WebSocket parameters, TLS/SSL settings (including certificate paths), and plugin configurations for authentication and bridging. This file provides a comprehensive way to manage broker behavior. ```json { "workerNum": 4096, "port": "1883", "host": "0.0.0.0", "cluster": { "host": "0.0.0.0", "port": "1993" }, "router": "127.0.0.1:9888", "wsPort": "1888", "wsPath": "/ws", "wsTLS": true, "tlsPort": "8883", "tlsHost": "0.0.0.0", "tlsInfo": { "verify": true, "caFile": "tls/ca/cacert.pem", "certFile": "tls/server/cert.pem", "keyFile": "tls/server/key.pem" }, "plugins": { "auth": "authhttp", "bridge": "kafka" } } ``` -------------------------------- ### Allow All Clients to Publish to Cloud Topics Source: https://github.com/fhmq/hmq/blob/master/plugins/auth/authfile/Readme.md These rules permit any client ('*') to publish ('2') to topics prefixed with 'toCloud/', dynamically replacing '%c' with the client ID or '%u' with the username. This enables personalized cloud topic publishing for all authenticated clients, allowing them to send data to unique cloud paths. ```ACL Configuration #allow all client pub the topic toCloud/{clientid/username} allow clientid * 2 toCloud/%c allow username * 2 toCloud/%u ``` -------------------------------- ### Defining CSVLog Configuration Structure in Go Source: https://github.com/fhmq/hmq/blob/master/plugins/bridge/CSVLog.md This Go struct, `csvBridgeConfig`, defines the configuration parameters for the CSVLog plugin. It specifies settings such as the output file name, log file rotation limits, write interval, command topic, and an array of message filters. Each field includes JSON tags for proper serialization and deserialization. ```Go type csvBridgeConfig struct { FileName string `json:"fileName"` LogFileMaxSizeMB int64 `json:"logFileMaxSizeMB"` LogFileMaxFiles int64 `json:"logFileMaxFiles"` WriteIntervalSecs int64 `json:"writeIntervalSecs"` CommandTopic string `json:"commandTopic"` Filters []string `json:"filters"` } ``` -------------------------------- ### Deny All Clients Full Access Source: https://github.com/fhmq/hmq/blob/master/plugins/auth/authfile/Readme.md This rule acts as a catch-all, denying all clients ('*') full publish and subscribe access ('3') to all topics ('#'). This is typically used as a default deny policy at the end of the ACL rule list, ensuring that any client not explicitly allowed by preceding rules is denied access. ```ACL Configuration #deny all client pub sub all topic deny clientid * 3 # ``` -------------------------------- ### Allow Local IP to Subscribe to System Topics Source: https://github.com/fhmq/hmq/blob/master/plugins/auth/authfile/Readme.md This ACL rule specifically allows the local IP address (127.0.0.1) to subscribe to system topics ($SYS/#), typically used for internal monitoring or management. The '1' indicates subscription access. ```ACL Configuration #allow local sub $SYS topic allow ip 127.0.0.1 1 $SYS/# ``` -------------------------------- ### HMQ Client Online/Offline Notification Format Source: https://github.com/fhmq/hmq/blob/master/README.md This snippet details the topic and payload format for HMQ's client online/offline notifications. The topic follows the `$SYS/broker/connection/clients/` convention, and the payload is a JSON object indicating the `clientID`, `online` status (true/false), and a `timestamp`. This allows external systems to monitor client connectivity status. ```json topic: $SYS/broker/connection/clients/ payload: {"clientID":"client001","online":true/false,"timestamp":"2018-10-25T09:32:32Z"} ``` -------------------------------- ### Grant Full Access to Specific Client ID and Username Source: https://github.com/fhmq/hmq/blob/master/plugins/auth/authfile/Readme.md These rules grant full publish and subscribe access ('3') to all topics ('#') for clients with the ID '0001' or the username 'admin'. This is useful for privileged clients or administrators who require broad access. ```ACL Configuration #allow client who's id with 0001 or username with admin pub sub all topic allow clientid 0001 3 # allow username admin 3 # ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.