Access the MQTT message as a consumer, parse the json according to the configuration and write it into TDengine
English | 简体中文
- Install golang(1.14+) https://golang.google.cn/doc/install
- Set up golang proxy
go env -w GOPROXY=https://goproxy.cn,direct
- Install the TDengine client https://www.taosdata.com/en/getting-started/
- Configure C Compiler Environment(GCC)
- Execute in the project directory
go build
{
"address": "mqtt Address",
"clientID": "If the client ID is not set, use uuid",
"username": "Username",
"password": "Password",
"keepAlive": 30,
"caPath": "ca certification path",
"certPath": "Certificate Path",
"keyPath": "Certificate key path"
}
keepAlive
: Alive time (in seconds)
{
"host": "Address",
"port": 6030,
"user": "Username",
"password": "Password",
"db": "Database"
}
port
is the TDengine service port
[
{
"rule_name": "Rule Name",
"topic": "topic",
"rule": {
"s_table": "Corresponding to STable name",
"table": {
"default_value": "Default value",
"path": "json path"
},
"tags": [
{
"name": "corresponding to the tag name in TDengine",
"value_type": "Type of value",
"length": "Maximum length of the value (need to be set when the value type is string)",
"default_value": "Default value",
"path": "json path",
"time_layout": "Time formatted layout (need to be set when the value type is timeString)"
}
],
"columns": [
{
"name": "corresponding to the column name in TDengine",
"value_type": "Type of value",
"length": "Maximum length of the value (need to be set when the value type is string)",
"default_value": "Default value",
"path": "json path",
"time_layout": "Time formatted layout (need to be set when the value type is timeString)"
}
]
}
}
]
- Default value: Use the default value when the value corresponding to path is not found in json
- Type of value:
"int" "float" "bool" "string" "timeString" "timeSecond" "timeMillisecond" "timeMicrosecond" "timeNanosecond"
- json path see https://github.com/tidwall/gjson
- When the value type is
string
, thelength
parameter must be set tags
set at least onecolumns
set at least two, the first parameter name must bets
and the type must be one of"timeString" "timeSecond" "timeMillisecond" "timeMicrosecond" "timeNanosecond"
timeLayout
is golang time formatting template https://golang.google.cn/pkg/time/#pkg-constants
-c string
Configuration file path (default "./config/config.json")
-rc string
Rule configuration file path (default "./config/rule.json")
See example folder