Kafka Share Source
Provided by: "Apache Software Foundation"
Support Level for this Kamelet is: "Preview"
Receives each record from one or more Apache Kafka topics through a share group, which hands out the records like a queue: each record goes to one of many consumers.
Use it to share the work of a topic between many integrations or threads, more of them than the topic has partitions, such as orders or tasks that each take a while to handle, when the order of the records does not matter. To read the records in order, or to read them again from a given position, use kafka-source. Share groups are on by default from Kafka 4.2.
Output: the body is the value of the record, as text. With schemaRegistryVendor, the value is read with its schema from the registry and the body is JSON text, such as {"id": 7, "item": "camel"} for an Avro record. A Protobuf record is turned into JSON by the Protobuf JSON mapping, such as {"id":7,"item":"camel"}: the names of the fields are in lowerCamelCase (orderNo for order_no), 64-bit numbers are text, and the fields that have their default value, such as 0 or empty text, are left out. A record without a value (a tombstone) gives a message with no body. The kafka-topic, kafka-key, kafka-partition, kafka-offset and kafka-timestamp (in milliseconds since 1970) headers say where the record came from, and kafka-delivery-count how many times it has been delivered, this time included. They are also set as ce-kafkatopic, ce-kafkakey and so on, and as the CamelKafka* headers. The record headers become message headers, as text unless deserializeHeaders is false.
Good to know: each record is acknowledged on its own once the integration has handled it, and a record that was handled is not delivered again. A record whose handling fails is released by default: Kafka delivers it again, to this or another consumer, up to group.share.delivery.count.limit times in all (5 by default, a broker setting), and then drops it. Set onFailure to REJECT to drop it at once, or to ACCEPT to count it as handled. To decide for one record, set the header CamelKafkaShareAcknowledge to ACCEPT, RELEASE or REJECT in the integration, such as REJECT when kafka-delivery-count is too high; a record header of that name is not used. A record that takes longer to handle than the lock of the broker (group.share.record.lock.duration.ms, 30 seconds by default) is delivered to another consumer as well. A new share group starts at the newest records: the records sent before it first reads a topic are skipped. Set autoOffsetReset to earliest to read them: when the Kamelet starts, it sets the group setting share.auto.offset.reset on the broker, which needs the ALTER_CONFIGS permission on the group, and the Kamelet does not start when that fails. The setting only decides where the group starts on a partition it has not read yet, and it applies to all the consumers of the group. A Kafka of a single broker needs the broker settings share.coordinator.state.topic.replication.factor=1 and share.coordinator.state.topic.min.isr=1, or the share group gets no records, with no error. saslAuthType has no default and must be set; NONE connects with no login and no TLS. With schemaRegistryVendor, the integration needs the serde jars of the vendor, which Camel JBang downloads by itself; for confluent add the Confluent Maven repository, as in camel run --repos=confluent. With aws-glue and azure, the serde logs in with the credentials of the environment the integration runs in: the AWS default credentials chain, or the Azure DefaultAzureCredential. To log in to a confluent or apicurio registry, set schemaRegistryUsername and schemaRegistryPassword, or the OAuth2 client credentials schemaRegistryOauthClientId, schemaRegistryOauthClientSecret and schemaRegistryOauthTokenEndpoint. Kafka only calls an OAuth2 token endpoint that is listed in the JVM system property org.apache.kafka.sasl.oauthbearer.allowed.urls; without it, the integration fails to start. This applies to schemaRegistryOauthTokenEndpoint and to the oauthTokenEndpointUri of saslAuthType OAUTH.
Configuration Options
The following table summarizes the configuration options available for the kafka-share-source Kamelet:
| Property | Name | Description | Type | Default | Example |
|---|---|---|---|---|---|
Bootstrap Servers | Required The address of one or more Kafka brokers to connect to first, as | string | broker1:9092,broker2:9092 | ||
Authentication Type | Required How to log in to Kafka. It has no default and must be set. Enum values: * NONE * PLAIN * SCRAM_SHA_256 * SCRAM_SHA_512 * SSL * OAUTH * AWS_MSK_IAM * KERBEROS | string | |||
Share Group | Required The name of the share group. All the consumers with the same share group, in this and in other integrations, share the records of the topics: each record goes to one of them. The group remembers which records were handled, so that a restarted integration goes on where it stopped. | string | order-workers | ||
Topic Names | Required The topics to read from, separated by commas. A share group cannot read the topics whose names match a regular expression. | string | orders | ||
Auto Offset Reset | Where a new share group starts reading a topic: | string | earliest | ||
Consumers Count | How many consumers of the share group this Kamelet runs, each on its own thread, so that this many records are handled at the same time. Unlike a consumer group, it is not limited by the number of partitions of the topics. | integer | 1 | ||
Automatically Deserialize Headers | If true, the values of the record headers are turned into text. If false, they stay bytes. | boolean | true | ||
OAuth Client ID | The ID of the client registered with the OAuth 2.0 provider. Required when | string | |||
OAuth Client Secret | The secret of the OAuth client | string | |||
OAuth Scope | The scope to ask the OAuth 2.0 provider for, when it requires one. Only used when | string | kafka | ||
OAuth Token URL | The URL of the OAuth 2.0 provider where the Kamelet gets its access token. Required when | string | https://auth.example.com/oauth2/token | ||
On Failure | What to do with a record whose handling failed: Enum values: * ACCEPT * RELEASE * REJECT | string | RELEASE | ||
Poll On Error Behavior | What to do when reading from Kafka fails: Enum values: * DISCARD * ERROR_HANDLER * RECONNECT * RETRY * STOP | string | ERROR_HANDLER | ||
Password | The password of | string | |||
Username | The user name to log in to Kafka with. Required when | string | |||
Schema Format | The format of the record values in the schema registry: Enum values: * avro * json * protobuf | string | avro | ||
Schema Registry Name | The name of the registry in AWS Glue. When not set, it is | string | |||
Schema Registry OAuth Client ID | The OAuth2 client id, to log in to a | string | |||
Schema Registry OAuth Client Secret | The OAuth2 client secret of | string | |||
Schema Registry OAuth Scope | The OAuth2 scope to ask for when logging in to the schema registry with client credentials (optional). | string | |||
Schema Registry OAuth Token Endpoint | The token endpoint of the OAuth2 server, to log in to a | string | http://keycloak:8080/realms/registry/protocol/openid-connect/token | ||
Schema Registry Password | The password of | string | |||
Schema Registry Region | The AWS region of the AWS Glue Schema Registry, such as | string | |||
Schema Registry URL | The URL of the schema registry: for | string | |||
Schema Registry Username | The username to log in to a | string | |||
Schema Registry Vendor | The schema registry that holds the schemas of the record values: Enum values: * confluent * apicurio * aws-glue * azure | string | |||
SSL Key Password | The password of the private key in the key store file in | string | |||
SSL Keystore Location | The path of a key store file, in JKS format, with the certificate and private key of the client. Needed only to log in with a client certificate (mutual TLS), usually with | string | /etc/kafka/keystore.jks | ||
SSL Keystore Password | The password of the key store file in | string | |||
SSL Truststore Location | The path of a trust store file, in JKS format, with the certificates to trust the brokers by. Needed only when the brokers use a certificate that Java does not trust by default, such as a self-signed one. | string | /etc/kafka/truststore.jks | ||
SSL Truststore Password | The password of the trust store file in | string |
Dependencies
At runtime, the kafka-share-source Kamelet relies upon the presence of the following dependencies:
-
camel:jackson3
-
camel:kafka
-
camel:kafka-share
-
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-share-source"
parameters:
.
.
.
steps:
- to:
uri: "kamelet:log-sink" You can now run it directly through the following command
camel run route.yaml