JSON Source Connector for Confluent Platform

The Kafka Connect JSON Source connector is used to stream JSON files from an SFTP directory while also converting the data based on the schema supplied in the configuration. If the schema is not supplied in the configuration then the connector can also auto generate the key.schema and value.schema at run time when schema.generation.enabled is true.

To use this connector, use a connector configuration that specifies the name of this connector class in the connector.class configuration property, as shown below:

connector.class=io.confluent.connect.sftp.SftpJsonSourceConnector

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 SFTP connector package.

  1. Generate a JSON dataset using the command below and push it to SFTP server:

    echo $'{"id":1,"first_name":"Roscoe","last_name":"Brentnall","email":"rbrentnall0@mediafire.com","gender":"Male","ip_address":"202.84.142.254","last_login":"2018-02-12T06:26:23Z","account_balance":1450.68,"country":"CZ","favorite_color":"#4eaefa"}\n{"id":2,"first_name":"Gregoire","last_name":"Fentem","email":"gfentem1@nsw.gov.au","gender":"Male","ip_address":"221.159.106.63","last_login":"2015-03-27T00:29:56Z","account_balance":1392.37,"country":"ID","favorite_color":"#e8f686"}' > "json-sftp-source.json"
    
  2. Create an sftp.properties file with the following contents:

    name=JsonSftp
    tasks.max=1
    connector.class=io.confluent.connect.sftp.SftpJsonSourceConnector
    input.path=/path/to/data
    error.path=/path/to/error
    finished.path=/path/to/finished
    cleanup.policy=NONE
    input.file.pattern=json-sftp-source.json
    behavior.on.error=IGNORE
    sftp.username=username
    sftp.password=password
    sftp.host=localhost
    sftp.port=22
    kafka.topic=sftp-json-topic
    key.schema={\"name\" : \"com.example.users.UserKey\",\"type\" : \"STRUCT\",\"isOptional\" : false,\"fieldSchemas\" : {\"id\" : {\"type\" : \"INT64\",\"isOptional\" : false}}}
    value.schema={\"name\" : \"com.example.users.User\",\"type\" : \"STRUCT\",\"isOptional\" : false,\"fieldSchemas\" : {\"id\" : {\"type\" : \"INT64\",\"isOptional\" : false},\"first_name\" : {\"type\" : \"STRING\",\"isOptional\" : true},\"last_name\" : {\"type\" : \"STRING\",\"isOptional\" : true},\"email\" : {\"type\" : \"STRING\",\"isOptional\" : true},\"gender\" : {\"type\" : \"STRING\",\"isOptional\" : true},\"ip_address\" : {\"type\" : \"STRING\",\"isOptional\" : true},\"last_login\" : {\"type\" : \"STRING\",\"isOptional\" : true},\"account_balance\" : {\"name\" : \"org.apache.kafka.connect.data.Decimal\",\"type\" : \"BYTES\",\"version\" : 1,\"parameters\" : {\"scale\" : \"2\"},\"isOptional\" : true},\"country\" : {\"type\" : \"STRING\",\"isOptional\" : true},\"favorite_color\" : {\"type\" : \"STRING\",\"isOptional\" : true}}}
    
  3. Load the SFTP JSON Source connector.

    Caution

    You must include a double dash (--) between the connector name and your flag. For more information, see this post.

    confluent local services connect connector load JsonSftp --config sftp.properties
    

    Important

    Don’t use the Confluent CLI in production environments.

Configuration Properties

Connector-specific configuration properties are described below.

General

kafka.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
  • Valid values: [1,…,9223372036854775807]

Connection

sftp.host

Sftp host to connect with.

  • Type: string
  • Default: localhost
  • Importance: high
sftp.port

Port number of SFTP server.

  • Type: int
  • Default: 22
  • Importance: medium
sftp.username

Username for sftp server.

  • Type: string
  • Default: foo
  • Importance: high
sftp.password

Password for sftp server.

  • Type: string
  • Default: pass
  • Importance: high

Security

tls.private.key

Private key that will be used for public-key authentication.

  • Type: password
  • Default: [hidden]
  • Importance: low
tls.public.key

Public key that will be used to decrypt the private key if the given private key is encrypted.

  • Type: password
  • Default: [hidden]
  • Importance: low
tls.passphrase

Passphrase that will be used to decrypt the private key if the given private key is encrypted.

  • Type: password
  • Default: [hidden]
  • Importance: low
tls.pemfile

Path to pemfile.

  • Type: string
  • Default: “”
  • Importance: low

Kerberos

If Kerberos is enabled, the Connector assumes the /etc/krb5.conf file has been correctly configured and points to a KDC which can issue tickets for SFTP. The connector will refresh its TGT when it expires.

To test if the configuration of the krb5.conf file and the keytab was successful, the command kinit -k -t /path/to/user.keytab username may be used. The connector first looks for a cached ticket on the system, if it does not exist it uses the configured keytab and principal. Note that if there is ticket cached on the system that is for a different application, the cache may need to be cleared temporarily when starting the connector.

kerberos.user.principal

The principal to use when connecting to SFTP with Kerberos. The sftp.username is still required. Format: username@REALM.

  • Type: string
  • Default: “”
  • Importance: low
kerberos.keytab.path

The path to the keytab file for the SFTP connector principal. This keytab file should only be readable by the connector.

  • Type: string
  • Default: “”
  • Importance: low

Proxy

sftp.proxy.url

Proxy url for sftp connection.

  • Type: string
  • Default: “”
  • Importance: low
proxy.username

Proxy username for sftp server if proxy is being used.

  • Type: string
  • Default: null
  • Importance: low
proxy.password

Proxy password for sftp server if proxy is being used.

  • Type: string
  • Default: null
  • Importance: low

Auto topic creation

For more information about Auto topic creation, see Configuring Auto Topic Creation for Source Connectors.

Note

Configuration properties accept regular expressions (regex) that are defined as Java regex.

topic.creation.groups

A list of group aliases that are used to define per-group topic configurations for matching topics. A default group always exists and matches all topics.

  • Type: List of String types
  • Default: empty
  • Possible Values: The values of this property refer to any additional groups. A default group is always defined for topic configurations.
topic.creation.$alias.replication.factor

The replication factor for new topics created by the connector. This value must not be larger than the number of brokers in the Kafka cluster. If this value is larger than the number of Kafka brokers, an error occurs when the connector attempts to create a topic. This is a required property for the default group. This property is optional for any other group defined in topic.creation.groups. Other groups use the Kafka broker default value.

  • Type: int
  • Default: n/a
  • Possible Values: >= 1 for a specific valid value or -1 to use the Kafka broker’s default value.
topic.creation.$alias.partitions

The number of topic partitions created by this connector. This is a required property for the default group. This property is optional for any other group defined in topic.creation.groups. Other groups use the Kafka broker default value.

  • Type: int
  • Default: n/a
  • Possible Values: >= 1 for a specific valid value or -1 to use the Kafka broker’s default value.
topic.creation.$alias.include

A list of strings that represent regular expressions that match topic names. This list is used to include topics with matching values, and apply this group’s specific configuration to the matching topics. $alias applies to any group defined in topic.creation.groups. This property does not apply to the default group.

  • Type: List of String types
  • Default: empty
  • Possible Values: Comma-separated list of exact topic names or regular expressions.
topic.creation.$alias.exclude

A list of strings representing regular expressions that match topic names. This list is used to exclude topics with matching values from getting the group’s specfic configuration. $alias applies to any group defined in topic.creation.groups. This property does not apply to the default group. Note that exclusion rules override any inclusion rules for topics.

  • Type: List of String types
  • Default: empty
  • Possible Values: Comma-separated list of exact topic names or regular expressions.
topic.creation.$alias.${kafkaTopicSpecificConfigName}

Any of the Changing Broker Configurations Dynamically for the version of the Kafka broker where the records will be written. The broker’s topic-level configuration value is used if the configuration is not specified for the rule. $alias applies to the default group as well as any group defined in topic.creation.groups.

  • Type: property values
  • Default: Kafka broker value

File System

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
  • Valid value: Absolute path to a sftp 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
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
  • Valid value: Absolute path to a sftp directory that exists and is writable.
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
  • Valid value: Absolute path to a sftp directory that exists and is writable.
behavior.on.error

Sets how the connector should behave when error are encountered while processing records. FAIL stops the connector when any error occurs. IGNORE ignores the current file and continues to the next file for processing. LOG after logging the error message, it continues to the next file for processing.

  • Importance: HIGH
  • Type: STRING
  • Default Value: FAIL
  • Valid values: FAIL, IGNORE, LOG
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
  • Valid values: 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
  • Valid values: [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
  • Valid values: 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 and value.schema can be omitted, but schema.generation.key.name and schema.generation.value.name must be set.

  • Importance: MEDIUM
  • Type: BOOLEAN
  • Default Value: false
schema.generation.key.fields

Field(s) use to build key schema. This is only used during schema generation. If schema.generation.enabled is true and schema.generation.key.fields is set to empty list as [] then key.schema will be of type Struct with empty fields. If schema.generation.enabled is true and schema.generation.key.fields is set to list of field names then the key.schema will be generated by extracting the fields present in the list from value.schema.

  • Importance: MEDIUM
  • Type: LIST
  • Default Value: []
schema.generation.key.name

The name of the generated key schema.

  • Importance: MEDIUM
  • Type: STRING
  • Default Value: defaultkeyschemaname
schema.generation.value.name

The name of the generated value schema.

  • Importance: MEDIUM
  • Type: STRING
  • Default Value: defaultvalueschemaname
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
  • Default Value: “”

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
  • Valid values: 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