Kafka Source
Provided by: "Apache Software Foundation"
Support Level for this Kamelet is: "Stable"
Receive data from Kafka topics.
Configuration Options
The following table summarizes the configuration options available for the kafka-source Kamelet:
| Property | Name | Description | Type | Default | Example |
|---|---|---|---|---|---|
Bootstrap Servers | Required Comma separated list of Kafka Broker URLs. | string | |||
Topic Names | Required Comma separated list of Kafka topic names. | string | |||
Allow Manual Commit | Whether to allow doing manual commits. | boolean | false | ||
Auto Commit Enable | If true, periodically commit to ZooKeeper the offset of messages already fetched by the consumer. | boolean | true | ||
Auto Offset Reset | What to do when there is no initial offset. There are 3 enums and the value can be one of latest, earliest, none. | string | latest | ||
Consumer Group | A string that uniquely identifies the group of consumers to which this source belongs. | string | my-group-id | ||
Automatically Deserialize Headers | When enabled the Kamelet source will deserialize all message headers to String representation. | boolean | true | ||
OAuth Client ID | OAuth client ID. Required when saslAuthType is OAUTH. | string | |||
OAuth Client Secret | OAuth client secret. Required when saslAuthType is OAUTH. | string | |||
OAuth Scope | OAuth scope. Optional when saslAuthType is OAUTH. | string | |||
OAuth Token Endpoint | OAuth token endpoint URI. Required when saslAuthType is OAUTH. | string | |||
Poll On Error Behavior | What to do if kafka threw an exception while polling for new messages. There are 5 enums and the value can be one of DISCARD, ERROR_HANDLER, RECONNECT, RETRY, STOP. | string | ERROR_HANDLER | ||
Authentication Type | Authentication type to use. Use NONE for no authentication, PLAIN or SCRAM_SHA_256/SCRAM_SHA_512 for username/password, SSL for certificate-based, OAUTH for OAuth 2.0, AWS_MSK_IAM for MSK, or KERBEROS for Kerberos. Enum values: * NONE * PLAIN * SCRAM_SHA_256 * SCRAM_SHA_512 * SSL * OAUTH * AWS_MSK_IAM * KERBEROS | string | NONE | ||
Password | Password for SASL authentication. Required when saslAuthType is PLAIN, SCRAM_SHA_256, or SCRAM_SHA_512. | string | |||
Username | Username for SASL authentication. Required when saslAuthType is PLAIN, SCRAM_SHA_256, or SCRAM_SHA_512. | string | |||
SSL Key Password | The password of the private key in the key store file. | string | |||
SSL Keystore Location | The location of the key store file. Used for mTLS authentication. | string | |||
SSL Keystore Password | The password for the key store file. | string | |||
SSL Truststore Location | The location of the trust store file. | string | |||
SSL Truststore Password | The password for the trust store file. | string | |||
Topic Is Pattern | Whether the topic is a pattern (regular expression). This can be used to subscribe to dynamic number of topics matching the pattern. | boolean | false |
Dependencies
At runtime, the kafka-source Kamelet relies upon the presence of the following dependencies:
-
camel:core
-
camel:kafka
-
camel:kamelet
Camel JBang usage
Prerequisites
-
You’ve installed JBang.
-
You have executed the following command:
jbang app install camel@apache/camel Supposing you have a file named route.yaml with this content:
- route:
from:
uri: "kamelet:kafka-source"
parameters:
.
.
.
steps:
- to:
uri: "kamelet:log-sink" You can now run it directly through the following command
camel run route.yaml Kafka Source Kamelet Description
Authentication
Authentication is selected with saslAuthType, which defaults to NONE, so out of the box the Kamelet connects to an unauthenticated broker. The accepted values are NONE, PLAIN, SCRAM_SHA_256, SCRAM_SHA_512, SSL, OAUTH, AWS_MSK_IAM and KERBEROS.
Which other properties are needed depends on that choice:
-
PLAIN,SCRAM_SHA_256andSCRAM_SHA_512takesaslUsernameandsaslPassword. -
OAUTHtakesoauthClientId,oauthClientSecret,oauthTokenEndpointUriandoauthScope. -
SSLtakes the keystore and truststore properties below. -
AWS_MSK_IAMandKERBEROSrely on the surrounding environment rather than on Kamelet properties.
Resolve credentials through a Camel vault rather than plaintext properties wherever the deployment allows it.
Configuration
Only topic and bootstrapServers are required. The Kamelet supports:
-
topic: Comma-separated list of Kafka topic names to consume from (required)
-
bootstrapServers: Comma-separated list of Kafka bootstrap servers (required)
-
saslAuthType: Authentication mechanism, default
NONE -
saslUsername / saslPassword: Credentials for the username and password mechanisms
-
oauthClientId / oauthClientSecret / oauthTokenEndpointUri / oauthScope: OAuth 2.0 settings
-
sslTruststoreLocation / sslTruststorePassword / sslKeystoreLocation / sslKeystorePassword / sslKeyPassword: TLS material
-
consumerGroup: Kafka consumer group ID for managing offsets
-
autoOffsetReset: What to do when there is no initial offset -
earliest,latestornone, defaultlatest -
autoCommitEnable: Commit offsets automatically, default
true -
allowManualCommit: Enable manual commit for control over when offsets advance, default
false -
pollOnError: What to do when polling fails, default
ERROR_HANDLER -
deserializeHeaders: Deserialize the Kafka record headers onto the exchange, default
true -
topicIsPattern: Treat
topicas a regular expression rather than a literal list, defaultfalse
Output Format
The body is the Kafka record value. The record metadata is surfaced as headers under names that are not Camel internals, so a downstream consumer does not have to read the CamelKafka* headers directly. Each has a ce- prefixed CloudEvents counterpart as well.
-
kafka-topicfromCamelKafkaTopic- the topic the record was consumed from, which is worth having when the Kamelet subscribes to several topics or to a pattern. -
kafka-keyfromCamelKafkaKey- the record key, absent for records produced without one. -
kafka-partitionfromCamelKafkaPartition- the partition the record came from. -
kafka-offsetfromCamelKafkaOffset- the offset within that partition. -
kafka-timestampfromCamelKafkaTimestamp- the record timestamp, in milliseconds since the epoch.
The CamelKafka* headers are left on the exchange as well, so consumers already reading them keep working. The Kafka record headers are passed through separately, controlled by the deserializeHeaders property.
Usage Example
- route:
from:
uri: "kamelet:kafka-source"
parameters:
topic: "orders,payments"
bootstrapServers: "kafka.example.com:9092"
saslAuthType: "PLAIN"
saslUsername: "kafka-user"
saslPassword: "kafka-password"
steps:
- to:
uri: "kamelet:log-sink" Example with Consumer Group
- route:
from:
uri: "kamelet:kafka-source"
parameters:
topic: "user-events"
bootstrapServers: "kafka1.example.com:9092,kafka2.example.com:9092"
saslAuthType: "PLAIN"
saslUsername: "kafka-user"
saslPassword: "kafka-password"
consumerGroup: "my-consumer-group"
autoOffsetReset: "earliest"
steps:
- to:
uri: "kamelet:log-sink" Security
Nothing is enabled by default: saslAuthType is NONE and no TLS material is configured, so an unconfigured binding talks to the broker in the clear. Set saslAuthType and the matching properties for the mechanism the broker expects, and supply the truststore and keystore properties for a TLS listener.