# Compile the plugins

In eKuiper source code root path, run the below command.

go build -trimpath --buildmode=plugin -o plugins/sinks/Tdengine@v1.0.0.so extensions/sinks/tdengine/tdengine.go
1

# Install plugin

Since the operation of the tdengine plug-in depends on the tdengine client, for the convenience of users, the tdengine client will be downloaded when the plug-in is installed. However, the tdengine client version corresponds to the server version one-to-one, which is not compatible with each other, so the user must inform the tdengine server version used.

# Rule Actions Description

As the tdengine database requires a timestamp field in the table, the user must inform the timestamp field name of the data table (required tsFieldName). The user can choose whether to provide timestamp data. If not (provideTs=false), the content of the timestamp field is automatically generated by the tdengine database.

NameTypeOptionalDescription
hoststringtrueDatabase host, it must be a host name aka. FQDN (opens new window). An IP address is invalid. The default value is localhost.
portintfalseDatabase port
userstringtrueUsername, default to root.
passwordstringtruePassword, default to taosdata.
databasestringfalseDatabase name.
tablestringfalseTable Name, could be a dynamic property.
fields[]stringtrueThe fields to be inserted to. The result map and the database should both have these fields. If not specified, all fields in the result map will be inserted.
provideTsBooltrueWhether the user provides a timestamp field, default to false.
tsFieldNameStringfalseTimestamp field name
tagFields[]StringtrueThe result fields to be used as the tag values in order. If sTable is specified, this is required.
sTableStringtrueThe super table to be use, could be a dynamic property.
tableDataFieldStringtrueWrite the nested values of the tableDataField into database.

Other common sink properties are supported. Please refer to the sink common properties for more information.

# Operation example

# To create a database or table, refer to the following documents

https://www.taosdata.com/cn/getting-started/
1

# Create a stream

curl --location --request POST 'http://127.0.0.1:9081/streams' --header 'Content-Type:application/json' --data '{"sql":"create stream demoStream(time string, age BIGINT) WITH ( DATASOURCE = \"device/+/message\", FORMAT = \"json\");"}'
1

# Create a rule

curl --location --request POST 'http://127.0.0.1:9081/rules' --header 'Content-Type:application/json' --data '{"id":"demoRule","sql":"SELECT * FROM demoStream;","actions":[{"tdengine":{"provideTs":true,"tsFieldName":"time","port":0,"ip":"127.0.0.1","user":"root","password":"taosdata","database":"dbName","table":"tableName","fields":["time","age"]}}]}'
1

Write into fixed table:

{
  "tdengine": {
    "host":        "hostname",
    "port":        6030,
    "user":        "root",
    "password":    "taosdata",
    "database":    "db",
    "table":       "tableName",
    "tsfieldname": "ts"
  }
}
1
2
3
4
5
6
7
8
9
10
11

Write into dynamic table:

{
  "tdengine": {
    "host":        "hostname",
    "port":        6030,
    "database":    "dab",
    "table":       "{{.table}}", // dynamic value, get from the table field of the result
    "tsfieldname": "ts",
    "fields":      ["f1", "f2"], // Write f1, f2 fields in result into f1, f2 columns in the db
    "sTable":      "myStable", // super table name, also allow dynamic
    "tagFields":   ["f3","f4"] // Write f3, f4 fields' values in the result as tags in order
  }
}
1
2
3
4
5
6
7
8
9
10
11
12

Write values of tableDataField into database:

The following configuration will write telemetry field's values into database

{
  "telemetry": [{
    "temperature": 32.32,
    "humidity": 80.8,
    "f3": "f3tagValue",
    "f4": "f4tagValue",
    "ts": 1388082430
  },{
    "temperature": 34.32,
    "humidity": 81.8,
    "f3": "f3tagValue",
    "f4": "f4tagValue",
    "ts": 1388082440
  }]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{
  "tdengine": {
    "host":        "hostname",
    "port":        6030,
    "database":    "dab",
    "table":       "tableName", // dynamic value, get from the table field of the result
    "tsfieldname": "ts",
    "fields":      ["temperature","humidity"], // Write f1, f2 fields in result into f1, f2 columns in the db
    "sTable":      "myStable", // super table name, also allow dynamic
    "tableDataField":      "telemetry", // write values of telemetry field into database
    "tagFields":   ["f3","f4"] // Write f3, f4 fields' values in the result as tags in order
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13