Important
You are viewing documentation for an older version of Confluent Platform. For the latest, click here.
JSON Source Connector for Confluent Platform¶
This connector is used to stream JSON files from a directory while also converting the data based on the schema supplied in the configuration.
To use this connector, use a connector configuration that specifies the name of this connector class in the connector.class
configuration property:
connector.class=com.github.jcustenborder.kafka.connect.spooldir.SpoolDirJsonSourceConnector
The other connector-specific configuration properties are described below.
JSON Source Connector Example¶
This example follows the same steps as the Quick Start. Review the Quick Start for help running the Confluent Platform and installing the Spool Dir connectors.
Generate a JSON dataset using the command below:
curl "https://api.mockaroo.com/api/17c84440?count=500&key=25fd9c80" > "json-spooldir-source.json"
Create a
spooldir.properties
file with the following contents:name=JsonSpoolDir tasks.max=1 connector.class=com.github.jcustenborder.kafka.connect.spooldir.SpoolDirJsonSourceConnector input.path=/path/to/data input.file.pattern=json-spooldir-source.json error.path=/path/to/error finished.path=/path/to/finished halt.on.error=false topic=spooldir-json-topic
Load the SpoolDir JSON Source Connector using the Confluent CLI confluent local load command.
Caution
You must include a double dash (
--
) between the topic name and your flag. For more information, see this post.confluent local load spooldir -- -d spooldir.properties
Important
Don’t use the confluent local commands in production environments.
JSON Schemaless Source Connector Example¶
This example follows the same steps as the Quick Start. Review the Quick Start for help running the Confluent Platform and installing the Spool Dir connectors.
Generate a JSON dataset using the command below:
curl "https://api.mockaroo.com/api/17c84440?count=500&key=25fd9c80" > "json-spooldir-source.json"
Create a
spooldir.properties
file with the following contents:name=SchemaLessJsonSpoolDir tasks.max=1 connector.class=com.github.jcustenborder.kafka.connect.spooldir.SpoolDirSchemaLessJsonSourceConnector input.path=/path/to/data input.file.pattern=json-spooldir-source.json error.path=/path/to/error finished.path=/path/to/finished halt.on.error=false topic=spooldir-schemaless-json-topic value.converter=org.apache.kafka.connect.storage.StringConverter
Load the SpoolDir Schemaless JSON Source Connector.
Caution
You must include a double dash (
--
) between the topic name and your flag. For more information, see this post.confluent local load spooldir -- -d spooldir.properties
Important
Don’t use the Confluent CLI in production environments.
Configuration Properties¶
General¶
topic
The Kafka topic to write the data to.
- Importance: HIGH
- Type: STRING
batch.size
The number of records that should be returned with each batch.
- Importance: LOW
- Type: INT
- Default Value: 1000
empty.poll.wait.ms
The amount of time to wait if a poll returns an empty list of records.
- Importance: LOW
- Type: LONG
- Default Value: 500
- Validator: [1,…,9223372036854775807]
Metadata¶
metadata.field
The name of the field in the value where the metadata will be stored.
- Importance: LOW
- Type: STRING
- Default Value: metadata
metadata.location
Location that metadata about the input file will be stored. FIELD - Metadata about the file will be stored in a field in the value of the record. HEADERS - Metadata about the input file will be stored as headers on the record. NONE - no metadata about the input file will be stored.
- Importance: LOW
- Type: STRING
- Default Value: HEADERS
- Validator: Matches:
NONE
,HEADERS
,FIELD
File System¶
error.path
The directory to place files that have errors. This directory must exist and be writable by the user running Kafka Connect.
- Importance: HIGH
- Type: STRING
- Validator: Absolute path to a directory that exists and is writable.
input.file.pattern
Regular expression to check input file names against. This expression must match the entire filename. The equivalent of
Matcher.matches()
.- Importance: HIGH
- Type: STRING
input.path
The directory where Kafka Connect reads files that are processed. This directory must exist and be writable by the user running Connect.
- Importance: HIGH
- Type: STRING
- Validator: Absolute path to a directory that exists and is writable.
finished.path
The directory where Connect puts files that are successfully processed. This directory must exist and be writable by the user running Connect.
- Importance: HIGH
- Type: STRING
halt.on.error
Sets whether the task halts when it encounters an error or continues to the next file.
- Importance: HIGH
- Type: BOOLEAN
- Default Value: true
cleanup.policy
Determines how the connector should cleanup the files that have been successfully processed. NONE leaves the files in place which could cause them to be reprocessed if the connector is restarted. DELETE removes the file from the filesystem. MOVE will move the file to a finished directory. MOVEBYDATE will move the file to a finished directory with subdirectories by date.
- Importance: MEDIUM
- Type: STRING
- Default Value: MOVE
- Validator: Matches:
NONE
,DELETE
,MOVE
,MOVEBYDATE
task.partitioner
The task partitioner implementation is used when the connector is configured to use more than one task. This is used by each task to identify which files will be processed by that task. This ensures that each file is only assigned to one task.
- Importance: MEDIUM
- Type: STRING
- Default Value: ByName
- Validator: Matches:
ByName
file.buffer.size.bytes
The size of buffer for the BufferedInputStream that will be used to interact with the file system.
- Importance: LOW
- Type: INT
- Default Value: 131072
- Validator: [1,…]
file.minimum.age.ms
The amount of time in milliseconds after the file was last written to before the file can be processed.
- Importance: LOW
- Type: LONG
- Default Value: 0
- Validator: [0,…]
files.sort.attributes
The attributes each file will use to determine the sort order. Name is name of the file. Length is the length of the file preferring larger files first. LastModified is the LastModified attribute of the file preferring older files first.
- Importance: LOW
- Type: LIST
- Default Value: [NameAsc]
- Validator: Matches:
NameAsc
,NameDesc
,LengthAsc
,LengthDesc
,LastModifiedAsc
,LastModifiedDesc
processing.file.extension
Before a file is processed, it is renamed to indicate that it is currently being processed. This setting is appended to the end of the file.
- Importance: LOW
- Type: STRING
- Default Value: .PROCESSING
- Validator: Matches regex( ^.*..+$ )
Schema¶
key.schema
The schema for the key written to Kafka.
- Importance: HIGH
- Type: STRING
value.schema
The schema for the value written to Kafka.
- Importance: HIGH
- Type: STRING
Schema Generation¶
schema.generation.enabled
Flag to determine if schemas should be dynamically generated. If set to true,
key.schema
andvalue.schema
can be omitted, butschema.generation.key.name
andschema.generation.value.name
must be set.- Importance: MEDIUM
- Type: BOOLEAN
schema.generation.key.fields
The field(s) to use to build a key schema. This is only used during schema generation.
- Importance: MEDIUM
- Type: LIST
schema.generation.key.name
The name of the generated key schema.
- Importance: MEDIUM
- Type: STRING
- Default Value: com.github.jcustenborder.kafka.connect.model.Key
schema.generation.value.name
The name of the generated value schema.
- Importance: MEDIUM
- Type: STRING
- Default Value: com.github.jcustenborder.kafka.connect.model.Value
timestamp.field
The field in the value schema that contains the parsed timestamp for the record. This field cannot be marked as optional and must be a Timestamp.
- Importance: MEDIUM
- Type: STRING
Timestamps¶
timestamp.mode
Determines how the connector sets the timestamp for the ConnectRecord. If set to
Field
, the timestamp is read from a field in the value. This field cannot be optional and must be a Timestamp. Specify the field intimestamp.field
. If set toFILE_TIME
, the last time the file was modified is used. If set toPROCESS_TIME
(the default), the time the record is read is used.- Importance: MEDIUM
- Type: STRING
- Default Value: PROCESS_TIME
- Validator: Matches:
FIELD
,FILE_TIME
,PROCESS_TIME
timestamp.field
The field in the value schema that contains the parsed timestamp for the record. This field cannot be marked as optional and must be a Timestamp.
- Importance: MEDIUM
- Type: STRING
parser.timestamp.date.formats
The date formats that are expected in the file. This is a list of strings that are used to parse the date fields in order. The most accurate date format should be first in the list. See the Java documentation for more information.
- Importance: LOW
- Type: LIST
- Default Value: [yyyy-MM-dd’T’HH:mm:ss, yyyy-MM-dd’ ‘HH:mm:ss]
parser.timestamp.timezone
The time zone used for all parsed dates.
- Importance: LOW
- Type: STRING
- Default Value: UTC