Schemaless JSON Source Connector

This connector is used to stream JSON files from a directory. It will not try to convert the JSON records to a schema. The recommended converter to use is the StringConverter.

value.converter=org.apache.kafka.connect.storage.StringConverter

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.SpoolDirSchemaLessJsonSourceConnector

The other connector-specific configuration properties are described below.

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.

Prerequisites
  1. Generate a JSON dataset using the command below:

    curl "https://api.mockaroo.com/api/17c84440?count=500&key=25fd9c80" > "json-spooldir-source.json"
    
  2. 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
    
  3. Load the SpoolDir Schemaless JSON Source Connector using the Confluent CLI confluent load command.

    confluent load spooldir​ -d spooldir.properties
    

    Important

    The Confluent CLI is meant for development purposes only and is not suitable for a production environment. The data that are produced are transient and are intended to be temporary.

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: 250
  • Validator: [1,…,9223372036854775807]

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

Sets how the connector should clean up files that are successfully processed. NONE leaves the files in place. Files left in place may be reprocessed if the connector is restarted. DELETE removes the file from the filesystem. MOVE (the default) moves the file to the finished.path directory.

  • Importance: MEDIUM
  • Type: STRING
  • Default Value: MOVE
  • Validator: Matches: NONE, DELETE, MOVE
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,…]
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( ^.*..+$ )

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 in timestamp.field. If set to FILE_TIME, the last time the file was modified is used. If set to PROCESS_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