Kafka
Overview
Kafka Connect is a framework for streaming data into or out of Apache Kafka®. This document explains how to use Kafka Connect connector for TimeBase. This service helps with importing data from TimeBase stream into Kafka topic (so-called Source Connector) or exporting data in reverse direction (so-called Sink Connector). Refer to Kafka resources to learn more about Kafka Connect technology.
Installation
Plugin is distributed in a Kafka Connect Docker image or as a jar file, for example: timebase-kafka-connector-0.7.1-all.jar. When installing plugin jar, add it to the classpath of Kafka Connect Worker (via worker plugin.path property). Connector can be executed in standalone or distributed mode (more about this later).
- The Source Connector class is called
deltix.kafka.connect.TBSourceConnector. - The Sink Connector class is called
deltix.kafka.connect.TBSinkConnector.
Source Connector
TimeBase Source Connector will copy data from the specified TimeBase stream to a Kafka topic. It supports the following config properties:
timebase.url- TimeBase server URL (dxtick://host:portordstick://host:portfor TLS).timebase.user- TimeBase username for basic authentication. Can also be set viaTIMEBASE_USERNAMEenvironment variable.timebase.pwd- TimeBase user password for basic authentication. Can also be set viaTIMEBASE_PASSWORDenvironment variable.timebase.sso.enable- Optional boolean (true/false, defaultfalse). Enable OAuth2 (SSO) authentication for TimeBase connection.timebase.sso.secret- OAuth2 (SSO) client secret. Required whentimebase.sso.enableistrue. Masked by Kafka Connect.timebase.sso.client.name- Optional OAuth2 (SSO) client application name (default:timebase.client.service). Used by TimeBase to resolve client ID and scope from the server's OAuth2 configuration.timebase.stream- Source stream name.timebase.message.id- Optional name ofINT64field containing unique message ID. Used to keep track of the last recorded message when plugin is restarted. When omitted, we will use timestamp and per-timestamp message counter.timebase.message.type- TimeBase message type name. Is used to select message type in polymorphic TimeBase streams. This parameter is only required when replicating polymorphic streams.topic- Kafka target topic the data is copied to.instrument.field- Optional Kafka topic field for storing TimeBase message Instrument Type.symbol.field- Optional Kafka topic field for storing TimeBase message Symbol.time.field- Optional Kafka topic field for storing TimeBase message Time.key.fields- Optional comma-separated list of TimeBase message fields. Is used as a record key in Kafka Topics. The key string will be created by concatenating field values in a specified order with ‘_’ as a separator.include.fields- Optional comma-separated list of stream fields. When specified, only these fields will be copied to Kafka.exclude.fields- Optional comma-separated list of stream fields that should not be copied to Kafka.rename.fields- Optional comma-separated list of top-level field names and their aliases (new names to be used in Kafka). The original name and alias must be separated by ‘:’. For instance, the property to renamebusiness_timefield to time, andbusiness_operationfield to operation will look like this:rename.fields=business_time:time,business_operation:operation.field.path.separator- Optional separator character for nested field paths (default:.).
Sink Connector
TimeBase Sink Connector will copy data from the specified Kafka topic to a TimeBase stream. It supports the following config properties:
timebase.url- TimeBase server URL (dxtick://host:portordstick://host:portfor TLS).timebase.user- TimeBase username for basic authentication. Can also be set viaTIMEBASE_USERNAMEenvironment variable.timebase.pwd- TimeBase user password for basic authentication. Can also be set viaTIMEBASE_PASSWORDenvironment variable.timebase.sso.enable- Optional boolean (true/false, defaultfalse). Enable OAuth2 (SSO) authentication for TimeBase connection.timebase.sso.secret- OAuth2 (SSO) client secret. Required whentimebase.sso.enableistrue. Masked by Kafka Connect.timebase.sso.client.name- Optional OAuth2 (SSO) client application name (default:timebase.client.service). Used by TimeBase to resolve client ID and scope from the server's OAuth2 configuration.timebase.stream- Destination stream name.timebase.message.id- Optional TimeBase message field for storing Kafka record offset.timebase.message.key- Optional TimeBase message field for storing Kafka record key.timebase.message.tombstone- Optional TimeBase field name to record tombstone messages.topics- Kafka topic from which data will be copied. Plugin supports copying from a single topic.instrument.field- Optional Kafka topic field to copy to TimeBase message Instrument Type.symbol.field- Optional Kafka topic field to copy to TimeBase message Symbol.time.field- Optional Kafka topicINT64field to copy to TimeBase message Time.include.fields- Optional comma-separated list of top-level topic fields. When specified, only these fields will be copied to TimeBase.exclude.fields- Optional comma-separated list of top-level topic fields that should not be copied to TimeBase.include.type- Optional schema name. When specified, only Kafka records matching this schema name will be copied to TimeBase.timestamp.fields- Optional comma-separated list ofINT64fields to be interpreted asAVROlogical type timestamp-millis (TimeBase DateTimeDataType).timestamp.tick.fields- Optional comma-separated list ofINT64fields to be interpreted as timestamps in ticks.flatten.fields- Optional comma-separated list of top levelStructfields which attributes should be written as top level attributes to TimeBase. Field names will contain ‘.’ separated field name path. For instance,business_timefield ofdatahub_operation_metadatastructure field will appear at the top level asdatahub_operation_metadata.business_time.rename.fields- Optional comma-separated list of top-level field names and their aliases (new names to be used in TimeBase). The original name and alias must be separated by ‘:’. For instance, using example above, where we flatteneddatahub_operation_metadata, thebusiness_timefield can be renamed tobtTimeBase field with thisrename.fieldsattribute:rename.fields=datahub_operation_metadata.business_time:bt.field.path.separator- Optional separator character for nested field paths (default:.).
TimeBase Authentication
TimeBase Kafka Connectors support two authentication mechanisms when connecting to TimeBase: Basic Authentication (username and password) and OAuth2 (SSO) client credentials.
Basic Authentication
Basic credentials can be supplied either directly in connector configuration or passed via environment variables on the Kafka Connect worker:
- In connector properties:
timebase.userandtimebase.pwd. - Via environment variables on the Connect worker:
TIMEBASE_USERNAMEandTIMEBASE_PASSWORD.
Credentials can also be embedded directly in the connection URL: dxtick://user:password@host:8011.
OAuth2 (SSO) Client Credentials
OAuth2 (SSO) authentication is available from connector version 0.1.18. Earlier versions only support basic authentication.
When connecting to a TimeBase server that has OAuth2 configured, the connector can authenticate using OAuth2 client credentials. On startup (and during automatic reconnection in the sink task), the connector queries the TimeBase server endpoint (/tb/oauthinfo) to automatically discover the token endpoint, client ID, and required scopes.
OAuth2 can be configured in two ways:
1. Connector Configuration Properties (Recommended)
This is the recommended approach because timebase.sso.secret is registered as a Kafka Connect PASSWORD type, ensuring that credentials are masked in logs and via the Kafka Connect REST API:
| Property | Required | Default | Description |
|---|---|---|---|
timebase.sso.enable | No | false | Enables OAuth2 (SSO) authentication when set to true. |
timebase.sso.secret | Yes (when SSO enabled) | null | The OAuth2 client secret. |
timebase.sso.client.name | No | timebase.client.service | Application name used to select client credentials and scope from the server's OAuth2 configuration. |
When using timebase.sso.enable=true, timebase.url must be a remote connection URL (dxtick:// or dstick:// with TLS). Embedded local file paths are not supported with OAuth2. Do not specify timebase.user and timebase.pwd when SSO is enabled.
Example standalone properties:
timebase.url=dxtick://timebase.example.com:8011
timebase.stream=trades
timebase.sso.enable=true
timebase.sso.secret=<client-secret>
timebase.sso.client.name=timebase.client.service
Example JSON configuration for distributed mode:
{
"name": "tb-source-sso",
"config": {
"connector.class": "deltix.kafka.connect.TBSourceConnector",
"tasks.max": "1",
"timebase.url": "dstick://timebase.example.com:8011",
"timebase.stream": "trades",
"topic": "trades",
"timebase.sso.enable": "true",
"timebase.sso.secret": "<client-secret>",
"timebase.sso.client.name": "timebase.client.service"
}
}
2. Connection URL Parameters
Alternatively, when timebase.sso.enable is false (default), OAuth2 settings can be passed as query parameters in timebase.url:
dxtick://localhost:8011?sso=true&secret=<client-secret>
dstick://localhost:8011?sso=true&secret=<client-secret>&sso_app=<app-name>
Supported query parameters:
| Parameter | Required | Description |
|---|---|---|
sso | Yes | Set to true to enable SSO. |
secret | Yes | OAuth2 client secret. |
sso_app | No | Application name from OAuth2 server configuration (default: timebase.client.service). |
client_id | No | Explicit OAuth2 client ID override. |
scope | No | Space-separated list of OAuth2 scopes. |
timebase.url is a plain string property in Kafka Connect. Secrets embedded directly in the connection URL are not masked in Kafka Connect worker logs or REST API responses. Use timebase.sso.secret for secure credential handling.
Supported Secret Formats
The OAuth2 client secret (supplied either via timebase.sso.secret or the URL secret parameter) supports several formats handled transparently by the TimeBase client:
- Plain text: Direct string value of the client secret.
- Environment variable substitution: References like
${OAUTH2_CLIENT_SECRET}or${TB_SSO_SECRET}are resolved by the client from the worker's environment variables. - Encrypted value: Strings prefixed with
EVare decrypted using TimeBase's internal cipher. - Vault storage reference: Strings prefixed with
vault:(e.g.,vault:/path/to/secretorvault:path/to/secret) retrieve the secret dynamically from HashiCorp Vault or Azure Key Vault configured on the worker.
Transformations
Kafka Connect framework supports Single Message Transformations (SMTs) that are applied to messages as they flow through the Connect. In the TimeBase to Kafka case, SMTs transform messages after the source connector has produced them, but before they are written to Kafka. In Kafka to TimeBase case, SMTs transform Kafka messages before they are sent to the Sink Connector.
Kafka Connect provides a number of SMTs. Some of the transformations overlap with field mapping features supported by the plugins. Transformations are specified in the same connector properties file. Multiple transformations can be chained together. See examples here for more information on how to use them.
Below, there is an example of transformation properties converting Avro logical date fields to strings before they are written to TimeBase by the Sink Connector. Without these transformations the fields hire_date and dismissal_date would be output as integers. In this case we chain two transformations (convert_hd and convert_dd) together:
transforms=convert_hd,convert_dd
transforms.convert_hd.field=hire_date
transforms.convert_hd.type=org.apache.kafka.connect.transforms.TimestampConverter$Value
transforms.convert_hd.format=yyyy-MM-dd
transforms.convert_hd.target.type=string
transforms.convert_dd.field=dismissal_date
transforms.convert_dd.type=org.apache.kafka.connect.transforms.TimestampConverter$Value
transforms.convert_dd.format=yyyy-MM-dd
transforms.convert_dd.target.type=string
Deploying Plugins in Standalone Mode
To run connectors in a standalone mode the user will need to execute worker using Kafka connect-standalone script:
bin/connect-standalone worker.properties \
connector1.properties connector2.properties connector3.properties ...
Here is a sample of worker.properties file with the Kafka Connect worker configuration that uses Avro serialization and integrates with the Confluent platform Schema Registry:
bootstrap.servers=localhost:9092
key.converter=org.apache.kafka.connect.storage.StringConverter
value.converter=io.confluent.connect.avro.AvroConverter
value.converter.schema.registry.url=http://localhost:8081
offset.storage.file.filename=/tmp/connect.offsets
plugin.path=/kafka-connect-tb/lib
A sample of the standalone TimeBase Source Connector configuration file:
name=tb-source-connector
connector.class=deltix.kafka.connect.TBSourceConnector
tasks.max=1
timebase.url=dxtick://localhost:8011
timebase.user=testuser
timebase.pwd=testpwd
timebase.stream=messages
timebase.message.id=sequence
topic=tb-messages
instrument.field=instrument_type
symbol.field=symbol
time.field=time
A sample of the standalone TimeBase Sink Connector configuration file:
name=tb-sink-connector
connector.class=deltix.kafka.connect.TBSinkConnector
tasks.max=1
timebase.url=dxtick://localhost:8011
timebase.user=testuser
timebase.pwd=testpwd
timebase.stream=messages
timebase.message.id=sequence
topics=tb-messages
instrument.field=instrument_type
symbol.field=symbol
time.field=time
Deploying Plugins in Distributed Mode
To run plugins in a distributed mode, start one or more workers, either by using Kafka connect-distributed.sh script or in a Docker using Confluent Platform Kafka Connect Docker image. Here is an example of a command that runs a worker in a Docker container:
# example for your reference
docker run -d \
--name="kafka-tbconnect" \
--net=host \
-e CONNECT_BOOTSTRAP_SERVERS=kafka_server:port \
-e CONNECT_REST_PORT=8083 \
-e CONNECT_GROUP_ID="tbconnect" \
-e CONNECT_CONFIG_STORAGE_TOPIC="tbconnect.docker-connect-configs" \
-e CONNECT_OFFSET_STORAGE_TOPIC="tbconnect.docker-connect-offsets" \
-e CONNECT_STATUS_STORAGE_TOPIC="tbconnect.docker-connect-status" \
-e CONNECT_CONFIG_STORAGE_REPLICATION_FACTOR=1 \
-e CONNECT_OFFSET_STORAGE_REPLICATION_FACTOR=1 \
-e CONNECT_STATUS_STORAGE_REPLICATION_FACTOR=1 \
-e CONNECT_KEY_CONVERTER="org.apache.kafka.connect.storage.StringConverter" \
-e CONNECT_VALUE_CONVERTER="io.confluent.connect.avro.AvroConverter" \
-e CONNECT_KEY_CONVERTER_SCHEMA_REGISTRY_URL="URL:port" \
-e CONNECT_VALUE_CONVERTER_SCHEMA_REGISTRY_URL="URL:port" \
-e CONNECT_REST_ADVERTISED_HOST_NAME="localhost" \
-e CONNECT_LOG4J_ROOT_LOGLEVEL=INFO \
-e CONNECT_PLUGIN_PATH=/usr/share/java,/var/customlib \
-v /home/user/kafka-connect-tb/lib:/var/customlib \
confluentinc/cp-kafka-connect:latest
All workers in the same group must share the group ID and Kafka topics for storing config, offset and status data. CONNECT_PLUGIN_PATH includes /var/customlib folder that contains TimeBase plugin JAR.
After worker is launched, it will start a webserver on a specified CONNECT_REST_PORT where it will provide REST API for managing connectors. The command to add a TimeBase Source connector will look like this:
curl -X POST -H "Content-Type: application/json" --data @kafka-connect-tb/config/ connector_TBSourceAppActivity_config.json http://$CONNECT_HOST:8083/connectors
Where connector_TBSourceAppActivity_config.json file will have the connector configuration in JSON format:
//example for your reference
{
"name": "TBSourceAppActivity",
"config": {
"connector.class": "deltix.kafka.connect.TBSourceConnector",
"tasks.max": "1",
"key.converter": "org.apache.kafka.connect.storage.StringConverter",
"value.converter": "io.confluent.connect.avro.AvroConverter",
"errors.log.enable": "true",
"errors.log.include.messages": "true",
"timebase.url": "dxtick://10.6.220.90:8011",
"timebase.stream": "application_activity",
"timebase.message.id": "",
"topic": "tbconnect.application-activity-extended",
"instrument.field": "instrument_type",
"symbol.field": "symbol",
"time.field": "time",
"value.converter.schema.registry.url": "URL:port"
}
}
Command to check the connector status:
curl -s -X GET http://$CONNECT_HOST:8083/connectors/TBSourceAppActivity/status
Kafka Broker Security Settings
With security enabled on the Kafka broker, worker and connector configurations will need to include additional security settings:
group.id=<kafka-group-id>
ssl.truststore.location=<jks-truststore-file>
ssl.truststore.password=<jks-truststore-password>
security.protocol=SASL_SSL
sasl.mechanism=GSSAPI
sasl.kerberos.service.name=kafka
sasl.jaas.config=com.sun.security.auth.module.Krb5LoginModule required \
useKeyTab=true \
principal="<principal-name>@xxx.com" \
keyTab="<keytab-file>" \
storeKey=true;
This set of properties will need to be also specified with an additional consumer. prefix in each property name for a Sink connector and producer. when using a Source connector. For instance: consumer.group.id. In addition, before running connect-standalone or connect-distributed worker script, set KAFKA_OPTS environment variable to include these Kerberos JVM properties:
export KAFKA_OPTS="-Djava.security.krb5.realm=xxx.com -Djava.security.krb5.kdc=xxx.comm-Djava.security.auth.login.config=/home/centos/tbconnect/config/kafka_client_jaas.conf -Dsun.security.krb5.debug=false"
Data Type Mapping
When converting TimeBase stream record to Kafka Connect record we map TimeBase data types to Kafka Connect Schema types as follows:
IntegerDataType->INT8,INT16,INT32orINT64depending on the native data type size.FloatDataType->FLOAT32(float) orFLOAT64(double).CharDataType->STRING.EnumDataType->STRING.VarcharDataType->STRING.BooleanDataType->BOOLEAN.DateTimeDataType->INT64with AvrologicalType = “timestamp-millis”.TimeOfDayDataType->INT32with AvrologicalType = “time-millis”.BinaryDataType->BYTES.ArrayDataType- Array of value types. Complex types with array of structures are not supported.ClassDataType- Not Supported. Currently all fields must have a primitive type or an Array type.
Limitations
Limitations of the current version 0.1:
- Polymorphic TimeBase streams are not fully supported. Source Plugin can only handle single type of messages specified with
timebase.message.type attribute. - Fields' values encoded with
AlphanumericandDecimal64encoders are not converted.