Skip to main content

Kafka Asset Bundle

A bundle of Kafka operations and apis for Teraslice.

APIS​

Operations​

Releases​

You can find a list of releases, changes, and pre-built asset bundles here.

Getting Started​

This asset bundle requires a running Teraslice cluster. Documentation.

# Step 1: make sure you have teraslice-cli installed
pnpm add -g teraslice-cli

# Step 2:
# teraslice-cli assets deploy <cluster_alias> <asset-name[@version]>
# deploy the latest release to a teraslice cluster
teraslice-cli assets deploy cluster1 terascope/file-assets

# or deploy a specific version to a teraslice cluster
teraslice-cli assets deploy localhost terascope/kafka-assets@4.2.2

# or build from source and deploy to a teraslice cluster
teraslice-cli assets deploy cluster2 --build

Connectors​

Kafka Connector​

Terafoundation connector for Kafka producer and consumer clients.

📖 Full Documentation | Configuration Hierarchy

To install from the root of your terafoundation based service.

pnpm add terafoundation_kafka_connector

Note: The terafoundation connector is preinstalled in Teraslice

Configuration:

The terafoundation level configuration is as follows:

ConfigurationDescriptionTypeNotes
brokersList of seed brokers for the kafka environmentString[]optional, defaults to ["localhost:9092"]
security_protocolProtocol used to communicate with brokers, may be set to plaintext or sslStringoptional, defaults to plaintext
ssl_ca_locationFile or directory path to CA certificate(s) for verifying the broker's key. Ignored if caCertificate is provided.Stringonly used when security_protocol is set to ssl
caCertificateCA certificate string (PEM format) for verifying the broker's key. If provided ssl_ca_location will be ignored.Stringonly used when security_protocol is set to ssl
ssl_certificate_locationPath to client's public key (PEM) used for authenticationStringonly used when security_protocol is set to ssl
ssl_crl_locationPath to CRL for verifying broker's certificate validityStringonly used when security_protocol is set to ssl
ssl_key_locationPath to client's private key (PEM) used for authenticationStringonly used when security_protocol is set to ssl
ssl_key_passwordPrivate key passphraseStringonly used when security_protocol is set to ssl

When using this connector in code, this connector exposes two different client implementations. One for producers type: producer and one for consumers type: consumer.

ConfigurationDescriptionTypeNotes
optionsConsumer or Producer specific optionsObjectrequired, see below
topic_optionslibrdkafka defined settings that apply per topicObjectoptional, defaults to {}
rdkafka_optionslibrdkafka defined settings that are not subscription specificObjectoptional, defaults to {}

The options object enables setting a few properties

ConfigurationDescriptionTypeNotes
typeWhat type of connector is required, either consumer or producer.Stringrequired, defaults to consumer
groupFor type 'consumer', what consumer group to useStringoptional
poll_intervalFor type 'producer', how often (in milliseconds) the producer connection is polled to keep it alive.Numberoptional, defaults to 100

Consumer connector configuration example:

{
options: {
type: 'consumer',
group: 'example-group'
},
topic_options: {
'enable.auto.commit': false
},
rdkafka_options: {
'fetch.min.bytes': 100000
}
}

Producer connector configuration example:

{
options: {
type: 'producer',
poll_interval: 1000,
},
topic_options: {},
rdkafka_options: {
'compression.codec': 'gzip',
'topic.metadata.refresh.interval.ms': -1,
'log.connection.close': false,
}
}

Terafoundation configuration example:

terafoundation:
connectors:
kafka:
default:
brokers: "localhost:9092"

With an encrypted connection to kafka broker:

terafoundation:
connectors:
kafka:
default:
brokers: "localhost:9092"
security_protocol: "ssl"
ssl_ca_location: "app/certs/CAs/rootCA.pem" # will be ignored if caCertificate is provided
caCertificate: | # if provided then ssl_ca_location will be ignored
-----BEGIN CERTIFICATE-----
MIIFJzCCA4+gAwIBAgIQX6DM59eAmZLzzdoyD0jbtDANBgkqhkiG9w0BAQsFADCB
...
...
...
R4eNRWMls7ceteGynZLUL0LULwW8Wio8w3Ht
-----END CERTIFICATE-----

Development​

This project uses pnpm. It is bundled with Node.js via Corepack, so no separate installation is needed:

corepack enable

Tests​

Run the kafka tests

Requirements:

  • docker - A Kafka container will be created using Docker

Environment:

  • KAFKA_BROKERS - Defaults to localhost:9092
pnpm test

Build​

Build a compiled asset bundle to deploy to a teraslice cluster.

Install Teraslice CLI:

pnpm add -g teraslice-cli
teraslice-cli assets build

Contributing​

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License​

MIT licensed.