# Compile the plugins

# plugins/go.mod

module plugins

go 1.13

replace github.com/lf-edge/ekuiper => /$eKuiper

require (
    github.com/lf-edge/ekuiper v0.0.0-00010101000000-000000000000 // indirect
    github.com/taosdata/driver-go v0.0.0-20200723061832-5be6460b0c20
)
1
2
3
4
5
6
7
8
9
10
go mod edit -replace github.com/lf-edge/ekuiper=/$eKuiper
go build -trimpath -modfile extensions.mod --buildmode=plugin -o /$ekuiper/plugins/sinks/Tdengine@v1.0.0.so /$ekuiper/extensions/sinks/tdengine/tdengine.go
1
2

# 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 time stamp field in the table, the user must inform the time stamp field name of the data table (required tsFieldName). The user can choose whether to provide time stamp data. If not (provideTs=false), the content of the time stamp field is automatically generated by the tdengine database.

NameTypeOptionalDescription
ipstringfalseDatabase ip
portintfalseDatabase port
userstringfalseUsername
passwordstringfalsePassword
databasestringfalseDatabase name
tablestringfalseTable Name
fields[]stringtrue(Replace with data key when not filling in)Table field collection
provideTsBoolfalseWhether the user provides a timestamp field
tsFieldNameStringfalseTimestamp field name

# 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

# Send data

mosquitto_pub -h broker.emqx.io -m '{"time":"2020-01-11 18:18:18", "age" : 18}' -t device/device_001/message
1