Sink Extension
To develop a sink for eKuiper is to implement api.Sink interface and export it as a golang plugin.
Before starting the development, you must .
To develop a sink, the Configure method must be implemented. This method will be called once the sink is initialized. In this method, a map that contains the configuration in the rule actions definition is passed in. Typically, there will be information such as host, port, user and password of the external system. You can use this map to initialize this sink.
The main task for a Sink is to implement collect method. The function will be invoked when eKuiper feed any data into the sink. As an infinite stream, this function will be invoked continuously. The task of this function is to publish data to the external system. The first parameter is the context, and the second parameter is the data received from eKuiper.
The last method to implement is Close which literally close the connection. It is called when the stream is about to terminate. You could also do any clean up work in this function.
As the sink itself is a plugin, it must be in the main package. Given the sink struct name is mySink. At last of the file, the sink must be exported as a symbol as below. There are . For sink extension, states are usually needed, so it is recommended to export a constructor function.
Build the implemented sink as a go plugin and make sure the output so file resides in the plugins/sinks folder.
The customized sink is specified in a actions definition. Its name is used as the key of the action. The configuration is the value.
If you have developed a sink implementation MySink, you should have:
- The compiled MySink.so file is located inside plugins/sinks
Whereas, mySink is a key of the actions. The value of mySink is the properties for that sink.