API Docs - v1.0.8¶
Sink¶
file (Sink)¶
File Sink can be used to publish (write) event data which is processed within siddhi to files.
Siddhi-io-file sink provides support to write both textual and binary data into files
Syntax
@sink(type="file", file.uri="<STRING>", append="<BOOL>", @map(...)))
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
file.uri | Used to specify the file for data to be written. | STRING | No | Yes | |
append | This parameter is used to specify whether the data should be append to the file or not. If append = 'true', data will be write at the end of the file without changing the existing content. If file does not exist, a new fill will be crated and then data will be written. If append append = 'false', If given file exists, existing content will be deleted and then data will be written back to the file. If given file does not exist, a new file will be created and then data will be written on it. |
true | BOOL | Yes | No |
Examples EXAMPLE 1
@sink(type='file', @map(type='json'), append='false', file.uri='/abc/{{symbol}}.txt') define stream BarStream (symbol string, price float, volume long);
Under above configuration, for each event, a file will be generated if there's no such a file,and then data will be written to that file as json messagesoutput will looks like below.
{
"event":{
"symbol":"WSO2",
"price":55.6,
"volume":100
}
}
Source¶
file (Source)¶
File Source provides the functionality for user to feed data to siddhi from files. Both text and binary files are supported by file source.
Syntax
@source(type="file", dir.uri="<STRING>", file.uri="<STRING>", mode="<STRING>", tailing="<BOOL>", action.after.process="<STRING>", action.after.failure="<STRING>", move.after.process="<STRING>", move.after.failure="<STRING>", begin.regex="<STRING>", end.regex="<STRING>", file.polling.interval="<STRING>", dir.polling.interval="<STRING>", timeout="<STRING>", @map(...)))
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
dir.uri | Used to specify a directory to be processed. All the files inside this directory will be processed. Only one of 'dir.uri' and 'file.uri' should be provided. This uri MUST have the respective protocol specified. |
STRING | No | No | |
file.uri | Used to specify a file to be processed. Only one of 'dir.uri' and 'file.uri' should be provided. This uri MUST have the respective protocol specified. |
STRING | No | No | |
mode | This parameter is used to specify how files in given directory should.Possible values for this parameter are, 1. TEXT.FULL : to read a text file completely at once. 2. BINARY.FULL : to read a binary file completely at once. 3. LINE : to read a text file line by line. 4. REGEX : to read a text file and extract data using a regex. |
line | STRING | Yes | No |
tailing | This can either have value true or false. By default it will be true. This attribute allows user to specify whether the file should be tailed or not. If tailing is enabled, the first file of the directory will be tailed. Also tailing should not be enabled in 'binary.full' or 'text.full' modes. |
true | BOOL | Yes | No |
action.after.process | This parameter is used to specify the action which should be carried out after processing a file in the given directory. It can be either DELETE or MOVE and default value will be 'DELETE'. If the action.after.process is MOVE, user must specify the location to move consumed files using 'move.after.process' parameter. |
delete | STRING | Yes | No |
action.after.failure | This parameter is used to specify the action which should be carried out if a failure occurred during the process. It can be either DELETE or MOVE and default value will be 'DELETE'. If the action.after.failure is MOVE, user must specify the location to move consumed files using 'move.after.failure' parameter. |
delete | STRING | Yes | No |
move.after.process | If action.after.process is MOVE, user must specify the location to move consumed files using 'move.after.process' parameter. This should be the absolute path of the file that going to be created after moving is done. This uri MUST have the respective protocol specified. |
STRING | No | No | |
move.after.failure | If action.after.failure is MOVE, user must specify the location to move consumed files using 'move.after.failure' parameter. This should be the absolute path of the file that going to be created after moving is done. This uri MUST have the respective protocol specified. |
STRING | No | No | |
begin.regex | This will define the regex to be matched at the beginning of the retrieved content. |
None | STRING | Yes | No |
end.regex | This will define the regex to be matched at the end of the retrieved content. |
None | STRING | Yes | No |
file.polling.interval | This parameter is used to specify the time period (in milliseconds) of a polling cycle for a file. |
1000 | STRING | Yes | No |
dir.polling.interval | This parameter is used to specify the time period (in milliseconds) of a polling cycle for a directory. |
1000 | STRING | Yes | No |
timeout | This parameter is used to specify the maximum time period (in milliseconds) for waiting until a file is processed. |
5000 | STRING | Yes | No |
Examples EXAMPLE 1
@source(type='file', mode='text.full', tailing='false' dir.uri='file://abc/xyz', action.after.process='delete', @map(type='json')) define stream FooStream (symbol string, price float, volume long);
Under above configuration, all the files in directory will be picked and read one by one.
In this case, it's assumed that all the files contains json valid json strings with keys 'symbol','price' and 'volume'.
Once a file is read, its content will be converted to an event using siddhi-map-json extension and then, that event will be received to the FooStream.
Finally, after reading is finished, the file will be deleted.
EXAMPLE 2
@source(type='file', mode='files.repo.line', tailing='true', dir.uri='file://abc/xyz', @map(type='json')) define stream FooStream (symbol string, price float, volume long);
Under above configuration, the first file in directory '/abc/xyz' will be picked and read line by line.
In this case, it is assumed that the file contains lines json strings.
For each line, line content will be converted to an event using siddhi-map-json extension and then, that event will be received to the FooStream.
Once file content is completely read, it will keep checking whether a new entry is added to the file or not.
If such entry is added, it will be immediately picked up and processed.