Kafka Share
Since Camel 4.23
Only consumer is supported
The Kafka Share component consumes the records of Apache Kafka topics through a share group (KIP-932, Queues for Kafka).
The consumers of a share group work through the records of a topic like a queue:
-
several consumers read the same partition, so the number of consumers is not limited by the number of partitions;
-
every record is acknowledged on its own: a failing record does not hold up the records after it;
-
the broker delivers a released record again, possibly to another consumer, and counts the deliveries of each record.
A share group has no offsets to commit or seek, no ordering guarantee, no transactions and no topic patterns. Use the Kafka component to produce records, and to consume them in order with a consumer group.
Maven users will need to add the following dependency to their pom.xml for this component.
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-kafka-share</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency> URI format
kafka-share:topic[?options]
The topic can be a comma-separated list of topics. The groupId option, the name of the share group, is required.
Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties,*.yamlfiles, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The Kafka Share component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
Sets additional properties for either kafka consumer or kafka producer in case they can’t be set directly on the camel configurations (e.g.: new Kafka properties that are not reflected yet in Camel configurations), the properties have to be prefixed with additionalProperties., e.g.: additionalProperties.transactional.id=12345&additionalProperties.schema.registry.url=http://localhost:8811/avro. If the properties are set in the application.properties file, they must be prefixed with camel.component.kafka.additional-properties (camel.component.kafka-share.additional-properties for the Kafka Share component) followed by the property name enclosed in square brackets, for example the delivery.timeout.ms property in square brackets. When sslContextParameters is configured, additional properties whose names start with ssl. are ignored because that SSL context configures the complete TLS engine. This is a multi-value option with prefix: additionalProperties. | Map | ||
URL of the Kafka brokers to use. The format is host1:port1,host2:port2, and the list can be a subset of brokers or a VIP pointing to a subset of brokers. This option is known as bootstrap.servers in the Kafka documentation. | String | ||
The client id is a user-specified string sent in each request to help trace calls. It should logically identify the application making the request. | String | ||
Allows to pre-configure the Kafka share component with common options that the endpoints will reuse. | KafkaShareConfiguration | ||
Close idle connections after the number of milliseconds specified by this config. | 540000 | Integer | |
To use a custom HeaderFilterStrategy to filter header to and from Camel message. | HeaderFilterStrategy | ||
The period of time in milliseconds after which we force a refresh of metadata even if we haven’t seen any partition leadership changes to proactively discover any new brokers or partitions. | 300000 | Integer | |
A list of classes to use as metrics reporters. Implementing the org.apache.kafka.common.metrics.MetricsReporter interface allows plugging in classes that will be notified of new metric creation. When custom reporters are set and org.apache.kafka.common.metrics.JmxReporter is needed, it has to be explicitly added to the list. | String | ||
The window of time a metrics sample is computed over. | 30000 | Integer | |
The number of samples maintained to compute metrics. | 2 | Integer | |
The size of the TCP receive buffer (SO_RCVBUF) to use when reading data. If the value is -1, the OS default will be used. | 65536 | Integer | |
The maximum amount of time in milliseconds to wait when reconnecting to a broker that has repeatedly failed to connect. If provided, the backoff per host will increase exponentially for each consecutive connection failure, up to this maximum. After calculating the backoff increase, 20% random jitter is added to avoid connection storms. | 1000 | Integer | |
The base amount of time to wait before attempting to reconnect to a given host. This avoids repeatedly connecting to a host in a tight loop. This backoff applies to all connection attempts by the client to a broker. This value is the initial backoff value and will increase exponentially for each consecutive connection failure, up to the reconnectBackoffMaxMs value. | 50 | Integer | |
The maximum amount of time in milliseconds to wait when retrying a request to the broker that has repeatedly failed. If provided, the backoff per client will increase exponentially for each failed request, up to this maximum. To prevent all clients from being synchronized upon retry, a randomized jitter with a factor of 0.2 will be applied to the backoff, resulting in the backoff falling within a range between 20% below and 20% above the computed value. If retry.backoff.ms is set to be higher than retry.backoff.max.ms, then retry.backoff.max.ms will be used as a constant backoff from the beginning without any exponential increase. | 1000 | Integer | |
The amount of time to wait before attempting to retry a failed request to a given topic partition. This avoids repeatedly sending requests in a tight loop under some failure scenarios. This value is the initial backoff value and will increase exponentially for each failed request, up to the retry.backoff.max.ms value. | 100 | Integer | |
The size of the TCP send buffer (SO_SNDBUF) to use when sending data. If the value is -1, the OS default will be used. | 131072 | Integer | |
Timeout in milliseconds to wait gracefully for the consumer or producer to shut down and terminate its worker threads. | 30000 | int | |
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
Automatically check the CRC32 of the records consumed. This ensures no on-the-wire or on-disk corruption to the messages occurred. | true | Boolean | |
How the acknowledgements of the records of a poll are committed to the broker, once all the records of the poll are processed. SYNC waits for the result, up to commitTimeoutMs, and a failure to commit is reported to the exception handler of the consumer. ASYNC does not wait, and a failure to commit is logged as a WARN. The broker delivers the records again when their acknowledgements are not committed. Enum values:
| SYNC | KafkaShareCommitMode | |
The maximum time to wait for the acknowledgements to be committed, when commitMode is SYNC. | 5000 | Long | |
The maximum time in milliseconds that the share consumer waits for the response of a request to the broker (request.timeout.ms). When no response arrives in time, the client sends the request again or fails it. It is also the timeout to set the shareAutoOffsetReset group configuration with the Admin client. | 30000 | Integer | |
The number of share consumers (KafkaShareConsumer of the Kafka client) that the endpoint creates, each on its own thread. They all join the share group, and the broker shares the records of every partition among the consumers of the group, so unlike a consumer group, consumers beyond the number of partitions also receive records. | 1 | int | |
The maximum amount of data the server should return for a fetch request. This is not an absolute maximum: if the first record batch in the first non-empty partition of the fetch is larger than this value, the record batch will still be returned to ensure that the consumer can make progress. | 52428800 | Integer | |
The minimum amount of data the server should return for a fetch request. If insufficient data is available, the request will wait for that much data to accumulate before answering the request. | 1 | Integer | |
The maximum time in milliseconds that the broker waits before answering a fetch request when it does not have the fetchMinBytes amount of data yet (fetch.max.wait.ms). | 500 | Integer | |
Required The name of the share group. All the consumers that use the same share group name share the records of the topics: each record is delivered to one of them. | String | ||
To use a custom KafkaHeaderDeserializer to deserialize kafka headers values. | KafkaHeaderDeserializer | ||
Deserializer class for the key that implements the Deserializer interface. | org.apache.kafka.common.serialization.StringDeserializer | String | |
The maximum amount of data per partition that the broker returns (max.partition.fetch.bytes). The share consumer of the Kafka client in use (4.4) reads this setting but does not send it in its fetch requests, so a fetch is limited by fetchMaxBytes and maxPollRecords only. | 1048576 | Integer | |
The maximum number of records returned in a single call to poll(). With the batch_optimized acquire mode, a poll can return more records, to align with the batches of the topic. | 500 | Integer | |
How to acknowledge a record whose exchange failed or was rolled back, unless the route set the CamelKafkaShareAcknowledge header. RELEASE makes the record available again, to this or another consumer of the share group, until the delivery count limit of the share group is reached. REJECT discards the record. ACCEPT marks the record as consumed. Enum values:
| RELEASE | KafkaShareAcknowledgeType | |
What to do when the poll() of the share consumer throws an exception. DISCARD and RETRY log the exception and poll again: unlike the kafka component, there is no record to skip or to retry, as the poll itself failed, and the records that fail in the route are acknowledged with onFailure. ERROR_HANDLER logs the exception, passes it to the error handler of the route, and polls again. RECONNECT closes the share consumer and creates a new one. STOP stops the consumer thread. An authentication or authorization failure always stops the consumer thread. Enum values:
| ERROR_HANDLER | PollOnError | |
The maximum time that a poll() of the share consumer waits for records. The poll returns at once when records are available, and returns no records when the time is up. | 5000 | Long | |
Whether to eager validate that broker host:port is valid and can be DNS resolved to known host during starting this consumer. If the validation fails, then an exception is thrown, which makes Camel fail fast. Disabling this will postpone the validation after the consumer is started, and Camel will keep re-connecting in case of validation or DNS resolution error. | true | boolean | |
Sets the group configuration share.auto.offset.reset of the share group when the consumer starts, through the Kafka Admin client: earliest, latest, or by_duration: followed by an ISO-8601 duration (such as by_duration:PT1H). It decides where a share-partition starts when the group first consumes it, so earliest lets a new share group read the records already in the topic (a new share group starts at the latest records). It is a setting of the group, so it applies to all the consumers of the group, and it does not move a share-partition that the group already consumes. The principal of the consumer needs the ALTER_CONFIGS permission on the group, and the consumer fails to start when the configuration cannot be set. When not set, the group configuration is left as it is. | String | ||
This enables the use of a specific Avro reader for use with the in multiple Schema registries documentation with Avro Deserializers implementation. This option is only available externally (not standard Apache Kafka). When schemaRegistryVendor is set, it is set under the property of the vendor (for apicurio apicurio.registry.use-specific-avro-reader, for aws-glue avroRecordType=SPECIFIC_RECORD). | false | boolean | |
Deserializer class for value that implements the Deserializer interface. | org.apache.kafka.common.serialization.StringDeserializer | String | |
How the share consumer acquires records. With record_limit, a poll() returns at most maxPollRecords records. With batch_optimized, a poll() can return more records than maxPollRecords, to align with the batches of the topic. Enum values:
| batch_optimized | String | |
The delay in milliseconds between two attempts to create the Kafka consumer (see createConsumerBackoffMaxAttempts). | 5000 | long | |
The maximum number of attempts to create and subscribe the Kafka consumer of a consumer thread (also when it is created again after a reconnect), after which Camel gives up and terminates that consumer thread. Creating the consumer fails both for temporary causes, such as a broker host name that cannot be resolved yet, and for lasting ones, such as an invalid configuration, and the Kafka client does not tell them apart. 0 (the default) or a negative value retries forever. To try again after Camel gave up, restart the route. | int | ||
Autowired A custom PollExceptionStrategy that decides how the consumer handles an exception thrown while polling records, instead of pollOnError. One instance is shared by all consumer threads; pollExceptionStrategyFactory takes precedence. Only used by the kafka component. | PollExceptionStrategy | ||
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean | |
Autowired A custom factory that creates the Kafka ShareConsumer of each consumer thread, and the Admin client that sets the shareAutoOffsetReset group configuration, for example to create clients with logic that extends the Kafka clients. | KafkaShareClientFactory | ||
Used for enabling or disabling all consumer based health checks from this component. | true | boolean | |
Used for enabling or disabling all producer based health checks from this component. Notice: Camel has by default disabled all producer based health-checks. You can turn on producer checks globally by setting camel.health.producersEnabled=true. | true | boolean | |
The format of the record values in the schema registry, which selects the serializer and deserializer of the schemaRegistryVendor. Not every vendor supports every format: azure supports only avro. Only used when schemaRegistryVendor is set. Enum values:
| avro | String | |
URL of the schema registry servers to use. The format is host1:port1,host2:port2. This is known as schema.registry.url in multiple Schema registries documentation. This option is only available externally (not standard Apache Kafka). When schemaRegistryVendor is set, the URL is set under the property of the vendor: schema.registry.url for confluent, apicurio.registry.url for apicurio (the URL of the registry API, such as http://localhost:8080/apis/registry/v3), schema.registry.url for azure (the fully qualified namespace, such as my-namespace.servicebus.windows.net), and endpoint for aws-glue (optional, as Glue is addressed by the AWS region). | String | ||
The schema registry vendor, which sets up the value serializer (producer), the value deserializer (consumer) and the registry properties of the vendor for the schemaFormat, so that you do not need to know the class names or the property names of the vendor. The schemaRegistryURL is set as the registry URL of the vendor. A valueSerializer or valueDeserializer other than the default, and additionalProperties, take precedence. The serde jars of the vendor must be on the classpath, as Camel does not include them. Leave it unset to configure the serializer, deserializer and registry properties yourself. Enum values:
| String | ||
Login thread sleep time between refresh attempts. | 60000 | Integer | |
Location of the kerberos config file. | String | ||
Kerberos kinit command path. Default is /usr/bin/kinit. | /usr/bin/kinit | String | |
A list of rules for mapping from principal names to short names (typically operating system usernames). The rules are evaluated in order, and the first rule that matches a principal name is used to map it to a short name. Any later rules in the list are ignored. By default, principal names made of a username, a hostname and a Kerberos realm are mapped to the username. For more details on the format, please see the Security Authorization and ACLs documentation (at the Apache Kafka project website). Multiple values can be separated by comma. | DEFAULT | String | |
Percentage of random jitter added to the renewal time. | 0.05 | Double | |
Login thread will sleep until the specified window factor of time from last refresh to ticket’s expiry has been reached, at which time it will try to renew the ticket. | 0.8 | Double | |
OAuth client ID. Used when saslAuthType is set to OAUTH. | String | ||
OAuth client secret. Used when saslAuthType is set to OAUTH. | String | ||
OAuth scope. Used when saslAuthType is set to OAUTH. | String | ||
OAuth token endpoint URI. Used when saslAuthType is set to OAUTH. | String | ||
Simplified authentication type to use. This provides an easier way to configure Kafka authentication without manually setting securityProtocol, saslMechanism, and saslJaasConfig. When set, the appropriate security settings are automatically derived. Note: This is optional. You can still use the traditional approach with explicit securityProtocol, saslMechanism, and saslJaasConfig properties. Enum values:
| KafkaAuthType | ||
Expose the kafka sasl.jaas.config parameter Example: org.apache.kafka.common.security.plain.PlainLoginModule required username=USERNAME password=PASSWORD;. | String | ||
The Kerberos principal name that Kafka runs as. This can be defined either in Kafka’s JAAS config or in Kafka’s config. | String | ||
The Simple Authentication and Security Layer (SASL) Mechanism used. For the valid values see http://www.iana.org/assignments/sasl-mechanisms/sasl-mechanisms.xhtml. | GSSAPI | String | |
Password for SASL authentication. Used when saslAuthType is set to PLAIN, SCRAM_SHA_256, or SCRAM_SHA_512. | String | ||
Username for SASL authentication. Used when saslAuthType is set to PLAIN, SCRAM_SHA_256, or SCRAM_SHA_512. | String | ||
The OAuth2 client id to log in to the schema registry with client credentials. Used with schemaRegistryVendor confluent and apicurio. | String | ||
The OAuth2 client secret to log in to the schema registry with client credentials. | String | ||
The OAuth2 scope to ask for when logging in to the schema registry with client credentials (optional). | String | ||
The token endpoint of the OAuth2 server to log in to the schema registry with client credentials, with schemaRegistryOauthClientId and schemaRegistryOauthClientSecret. Used with schemaRegistryVendor confluent (bearer.auth.issuer.endpoint.url) and apicurio (apicurio.registry.auth.service.token.endpoint, such as the token endpoint of a Keycloak realm). | String | ||
The password to log in to the schema registry with basic auth, with schemaRegistryUsername. For Confluent Cloud, the API secret. | String | ||
The username to log in to the schema registry with basic auth, with schemaRegistryPassword. Used with schemaRegistryVendor confluent (basic.auth.user.info, which is the API key for Confluent Cloud) and apicurio (apicurio.registry.auth.username). The azure and aws-glue vendors log in with the credentials of the environment instead. | String | ||
Protocol used to communicate with brokers. SASL_PLAINTEXT, PLAINTEXT, SASL_SSL and SSL are supported. | PLAINTEXT | String | |
A list of cipher suites. This is a named combination of authentication, encryption, MAC and key exchange algorithm used to negotiate the security settings for a network connection using TLS or SSL network protocol. By default, all the available cipher suites are supported. | String | ||
SSL configuration using a Camel SSLContextParameters object. When configured, Camel creates Kafka TLS engines with its own SslEngineFactory and this SSL context. It takes precedence over the other SSL endpoint options and additionalProperties entries whose names start with ssl.; only sslEndpointAlgorithm remains applicable for broker hostname verification. | SSLContextParameters | ||
The list of protocols enabled for SSL connections. The default is TLSv1.2,TLSv1.3. This means that clients and servers will prefer TLSv1.3 if both support it and fallback to TLSv1.2 otherwise (assuming both support at least TLSv1.2). This default should be fine for most use cases. Also see the documentation of sslProtocol to understand how it can impact the TLS version negotiation behavior. | TLSv1.2,TLSv1.3 | String | |
The endpoint identification algorithm to validate server hostname using server certificate. Use none or false to disable server hostname verification. | https | String | |
The algorithm used by key manager factory for SSL connections. Default value is the key manager factory algorithm configured for the Java Virtual Machine. | SunX509 | String | |
The password of the private key in the key store file or the PEM key specified in sslKeystoreKey. This is required for clients only if two-way authentication is configured. | String | ||
The location of the key store file. This is optional for the client and can be used for two-way authentication for the client. | String | ||
The store password for the key store file. This is optional for the client and only needed if sslKeystoreLocation is configured. Key store password is not supported for PEM format. | String | ||
The file format of the key store file. This is optional for the client. The supported values are JKS, PKCS12 and PEM. | JKS | String | |
The SSL protocol used to generate the SSLContext. The default is TLSv1.3, which should be fine for most use cases. A typical alternative to the default is TLSv1.2. Allowed values for this config are dependent on the JVM. Clients using the defaults for this config and sslEnabledProtocols will downgrade to TLSv1.2 if the server does not support TLSv1.3. If this config is set to TLSv1.2, however, clients will not use TLSv1.3 even if it is one of the values in sslEnabledProtocols and the server only supports TLSv1.3. | TLSv1.3 | String | |
The name of the security provider used for SSL connections. Default value is the default security provider of the JVM. | String | ||
The algorithm used by trust manager factory for SSL connections. Default value is the trust manager factory algorithm configured for the Java Virtual Machine. | PKIX | String | |
The location of the trust store file. | String | ||
The password for the trust store file. If a password is not set, trust store file configured will still be used, but integrity checking is disabled. Trust store password is not supported for PEM format. | String | ||
The file format of the trust store file. The supported values are JKS, PKCS12 and PEM. | JKS | String | |
Whether to use the global SSL context parameters of the CamelContext when the endpoint has no sslContextParameters. | false | boolean |
Endpoint Options
The Kafka Share endpoint is configured using URI syntax:
kafka-share:topic
With the following path and query parameters:
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
Sets additional properties for either kafka consumer or kafka producer in case they can’t be set directly on the camel configurations (e.g.: new Kafka properties that are not reflected yet in Camel configurations), the properties have to be prefixed with additionalProperties., e.g.: additionalProperties.transactional.id=12345&additionalProperties.schema.registry.url=http://localhost:8811/avro. If the properties are set in the application.properties file, they must be prefixed with camel.component.kafka.additional-properties (camel.component.kafka-share.additional-properties for the Kafka Share component) followed by the property name enclosed in square brackets, for example the delivery.timeout.ms property in square brackets. When sslContextParameters is configured, additional properties whose names start with ssl. are ignored because that SSL context configures the complete TLS engine. This is a multi-value option with prefix: additionalProperties. | Map | ||
URL of the Kafka brokers to use. The format is host1:port1,host2:port2, and the list can be a subset of brokers or a VIP pointing to a subset of brokers. This option is known as bootstrap.servers in the Kafka documentation. | String | ||
The client id is a user-specified string sent in each request to help trace calls. It should logically identify the application making the request. | String | ||
Close idle connections after the number of milliseconds specified by this config. | 540000 | Integer | |
To use a custom HeaderFilterStrategy to filter header to and from Camel message. | HeaderFilterStrategy | ||
The period of time in milliseconds after which we force a refresh of metadata even if we haven’t seen any partition leadership changes to proactively discover any new brokers or partitions. | 300000 | Integer | |
A list of classes to use as metrics reporters. Implementing the org.apache.kafka.common.metrics.MetricsReporter interface allows plugging in classes that will be notified of new metric creation. When custom reporters are set and org.apache.kafka.common.metrics.JmxReporter is needed, it has to be explicitly added to the list. | String | ||
The window of time a metrics sample is computed over. | 30000 | Integer | |
The number of samples maintained to compute metrics. | 2 | Integer | |
The size of the TCP receive buffer (SO_RCVBUF) to use when reading data. If the value is -1, the OS default will be used. | 65536 | Integer | |
The maximum amount of time in milliseconds to wait when reconnecting to a broker that has repeatedly failed to connect. If provided, the backoff per host will increase exponentially for each consecutive connection failure, up to this maximum. After calculating the backoff increase, 20% random jitter is added to avoid connection storms. | 1000 | Integer | |
The base amount of time to wait before attempting to reconnect to a given host. This avoids repeatedly connecting to a host in a tight loop. This backoff applies to all connection attempts by the client to a broker. This value is the initial backoff value and will increase exponentially for each consecutive connection failure, up to the reconnectBackoffMaxMs value. | 50 | Integer | |
The maximum amount of time in milliseconds to wait when retrying a request to the broker that has repeatedly failed. If provided, the backoff per client will increase exponentially for each failed request, up to this maximum. To prevent all clients from being synchronized upon retry, a randomized jitter with a factor of 0.2 will be applied to the backoff, resulting in the backoff falling within a range between 20% below and 20% above the computed value. If retry.backoff.ms is set to be higher than retry.backoff.max.ms, then retry.backoff.max.ms will be used as a constant backoff from the beginning without any exponential increase. | 1000 | Integer | |
The amount of time to wait before attempting to retry a failed request to a given topic partition. This avoids repeatedly sending requests in a tight loop under some failure scenarios. This value is the initial backoff value and will increase exponentially for each failed request, up to the retry.backoff.max.ms value. | 100 | Integer | |
The size of the TCP send buffer (SO_SNDBUF) to use when sending data. If the value is -1, the OS default will be used. | 131072 | Integer | |
Timeout in milliseconds to wait gracefully for the consumer or producer to shut down and terminate its worker threads. | 30000 | int | |
Automatically check the CRC32 of the records consumed. This ensures no on-the-wire or on-disk corruption to the messages occurred. | true | Boolean | |
How the acknowledgements of the records of a poll are committed to the broker, once all the records of the poll are processed. SYNC waits for the result, up to commitTimeoutMs, and a failure to commit is reported to the exception handler of the consumer. ASYNC does not wait, and a failure to commit is logged as a WARN. The broker delivers the records again when their acknowledgements are not committed. Enum values:
| SYNC | KafkaShareCommitMode | |
The maximum time to wait for the acknowledgements to be committed, when commitMode is SYNC. | 5000 | Long | |
The maximum time in milliseconds that the share consumer waits for the response of a request to the broker (request.timeout.ms). When no response arrives in time, the client sends the request again or fails it. It is also the timeout to set the shareAutoOffsetReset group configuration with the Admin client. | 30000 | Integer | |
The number of share consumers (KafkaShareConsumer of the Kafka client) that the endpoint creates, each on its own thread. They all join the share group, and the broker shares the records of every partition among the consumers of the group, so unlike a consumer group, consumers beyond the number of partitions also receive records. | 1 | int | |
The maximum amount of data the server should return for a fetch request. This is not an absolute maximum: if the first record batch in the first non-empty partition of the fetch is larger than this value, the record batch will still be returned to ensure that the consumer can make progress. | 52428800 | Integer | |
The minimum amount of data the server should return for a fetch request. If insufficient data is available, the request will wait for that much data to accumulate before answering the request. | 1 | Integer | |
The maximum time in milliseconds that the broker waits before answering a fetch request when it does not have the fetchMinBytes amount of data yet (fetch.max.wait.ms). | 500 | Integer | |
Required The name of the share group. All the consumers that use the same share group name share the records of the topics: each record is delivered to one of them. | String | ||
To use a custom KafkaHeaderDeserializer to deserialize kafka headers values. | KafkaHeaderDeserializer | ||
Deserializer class for the key that implements the Deserializer interface. | org.apache.kafka.common.serialization.StringDeserializer | String | |
The maximum amount of data per partition that the broker returns (max.partition.fetch.bytes). The share consumer of the Kafka client in use (4.4) reads this setting but does not send it in its fetch requests, so a fetch is limited by fetchMaxBytes and maxPollRecords only. | 1048576 | Integer | |
The maximum number of records returned in a single call to poll(). With the batch_optimized acquire mode, a poll can return more records, to align with the batches of the topic. | 500 | Integer | |
How to acknowledge a record whose exchange failed or was rolled back, unless the route set the CamelKafkaShareAcknowledge header. RELEASE makes the record available again, to this or another consumer of the share group, until the delivery count limit of the share group is reached. REJECT discards the record. ACCEPT marks the record as consumed. Enum values:
| RELEASE | KafkaShareAcknowledgeType | |
What to do when the poll() of the share consumer throws an exception. DISCARD and RETRY log the exception and poll again: unlike the kafka component, there is no record to skip or to retry, as the poll itself failed, and the records that fail in the route are acknowledged with onFailure. ERROR_HANDLER logs the exception, passes it to the error handler of the route, and polls again. RECONNECT closes the share consumer and creates a new one. STOP stops the consumer thread. An authentication or authorization failure always stops the consumer thread. Enum values:
| ERROR_HANDLER | PollOnError | |
The maximum time that a poll() of the share consumer waits for records. The poll returns at once when records are available, and returns no records when the time is up. | 5000 | Long | |
Whether to eager validate that broker host:port is valid and can be DNS resolved to known host during starting this consumer. If the validation fails, then an exception is thrown, which makes Camel fail fast. Disabling this will postpone the validation after the consumer is started, and Camel will keep re-connecting in case of validation or DNS resolution error. | true | boolean | |
Sets the group configuration share.auto.offset.reset of the share group when the consumer starts, through the Kafka Admin client: earliest, latest, or by_duration: followed by an ISO-8601 duration (such as by_duration:PT1H). It decides where a share-partition starts when the group first consumes it, so earliest lets a new share group read the records already in the topic (a new share group starts at the latest records). It is a setting of the group, so it applies to all the consumers of the group, and it does not move a share-partition that the group already consumes. The principal of the consumer needs the ALTER_CONFIGS permission on the group, and the consumer fails to start when the configuration cannot be set. When not set, the group configuration is left as it is. | String | ||
This enables the use of a specific Avro reader for use with the in multiple Schema registries documentation with Avro Deserializers implementation. This option is only available externally (not standard Apache Kafka). When schemaRegistryVendor is set, it is set under the property of the vendor (for apicurio apicurio.registry.use-specific-avro-reader, for aws-glue avroRecordType=SPECIFIC_RECORD). | false | boolean | |
Deserializer class for value that implements the Deserializer interface. | org.apache.kafka.common.serialization.StringDeserializer | String | |
How the share consumer acquires records. With record_limit, a poll() returns at most maxPollRecords records. With batch_optimized, a poll() can return more records than maxPollRecords, to align with the batches of the topic. Enum values:
| batch_optimized | String | |
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. | ExceptionHandler | ||
Sets the exchange pattern when the consumer creates an exchange. Enum values:
| ExchangePattern | ||
A custom factory that creates the Kafka ShareConsumer of each consumer thread, and the Admin client that sets the shareAutoOffsetReset group configuration, for example to create clients with logic that extends the Kafka clients. | KafkaShareClientFactory | ||
The format of the record values in the schema registry, which selects the serializer and deserializer of the schemaRegistryVendor. Not every vendor supports every format: azure supports only avro. Only used when schemaRegistryVendor is set. Enum values:
| avro | String | |
URL of the schema registry servers to use. The format is host1:port1,host2:port2. This is known as schema.registry.url in multiple Schema registries documentation. This option is only available externally (not standard Apache Kafka). When schemaRegistryVendor is set, the URL is set under the property of the vendor: schema.registry.url for confluent, apicurio.registry.url for apicurio (the URL of the registry API, such as http://localhost:8080/apis/registry/v3), schema.registry.url for azure (the fully qualified namespace, such as my-namespace.servicebus.windows.net), and endpoint for aws-glue (optional, as Glue is addressed by the AWS region). | String | ||
The schema registry vendor, which sets up the value serializer (producer), the value deserializer (consumer) and the registry properties of the vendor for the schemaFormat, so that you do not need to know the class names or the property names of the vendor. The schemaRegistryURL is set as the registry URL of the vendor. A valueSerializer or valueDeserializer other than the default, and additionalProperties, take precedence. The serde jars of the vendor must be on the classpath, as Camel does not include them. Leave it unset to configure the serializer, deserializer and registry properties yourself. Enum values:
| String | ||
Login thread sleep time between refresh attempts. | 60000 | Integer | |
Location of the kerberos config file. | String | ||
Kerberos kinit command path. Default is /usr/bin/kinit. | /usr/bin/kinit | String | |
A list of rules for mapping from principal names to short names (typically operating system usernames). The rules are evaluated in order, and the first rule that matches a principal name is used to map it to a short name. Any later rules in the list are ignored. By default, principal names made of a username, a hostname and a Kerberos realm are mapped to the username. For more details on the format, please see the Security Authorization and ACLs documentation (at the Apache Kafka project website). Multiple values can be separated by comma. | DEFAULT | String | |
Percentage of random jitter added to the renewal time. | 0.05 | Double | |
Login thread will sleep until the specified window factor of time from last refresh to ticket’s expiry has been reached, at which time it will try to renew the ticket. | 0.8 | Double | |
OAuth client ID. Used when saslAuthType is set to OAUTH. | String | ||
OAuth client secret. Used when saslAuthType is set to OAUTH. | String | ||
OAuth scope. Used when saslAuthType is set to OAUTH. | String | ||
OAuth token endpoint URI. Used when saslAuthType is set to OAUTH. | String | ||
Simplified authentication type to use. This provides an easier way to configure Kafka authentication without manually setting securityProtocol, saslMechanism, and saslJaasConfig. When set, the appropriate security settings are automatically derived. Note: This is optional. You can still use the traditional approach with explicit securityProtocol, saslMechanism, and saslJaasConfig properties. Enum values:
| KafkaAuthType | ||
Expose the kafka sasl.jaas.config parameter Example: org.apache.kafka.common.security.plain.PlainLoginModule required username=USERNAME password=PASSWORD;. | String | ||
The Kerberos principal name that Kafka runs as. This can be defined either in Kafka’s JAAS config or in Kafka’s config. | String | ||
The Simple Authentication and Security Layer (SASL) Mechanism used. For the valid values see http://www.iana.org/assignments/sasl-mechanisms/sasl-mechanisms.xhtml. | GSSAPI | String | |
Password for SASL authentication. Used when saslAuthType is set to PLAIN, SCRAM_SHA_256, or SCRAM_SHA_512. | String | ||
Username for SASL authentication. Used when saslAuthType is set to PLAIN, SCRAM_SHA_256, or SCRAM_SHA_512. | String | ||
The OAuth2 client id to log in to the schema registry with client credentials. Used with schemaRegistryVendor confluent and apicurio. | String | ||
The OAuth2 client secret to log in to the schema registry with client credentials. | String | ||
The OAuth2 scope to ask for when logging in to the schema registry with client credentials (optional). | String | ||
The token endpoint of the OAuth2 server to log in to the schema registry with client credentials, with schemaRegistryOauthClientId and schemaRegistryOauthClientSecret. Used with schemaRegistryVendor confluent (bearer.auth.issuer.endpoint.url) and apicurio (apicurio.registry.auth.service.token.endpoint, such as the token endpoint of a Keycloak realm). | String | ||
The password to log in to the schema registry with basic auth, with schemaRegistryUsername. For Confluent Cloud, the API secret. | String | ||
The username to log in to the schema registry with basic auth, with schemaRegistryPassword. Used with schemaRegistryVendor confluent (basic.auth.user.info, which is the API key for Confluent Cloud) and apicurio (apicurio.registry.auth.username). The azure and aws-glue vendors log in with the credentials of the environment instead. | String | ||
Protocol used to communicate with brokers. SASL_PLAINTEXT, PLAINTEXT, SASL_SSL and SSL are supported. | PLAINTEXT | String | |
A list of cipher suites. This is a named combination of authentication, encryption, MAC and key exchange algorithm used to negotiate the security settings for a network connection using TLS or SSL network protocol. By default, all the available cipher suites are supported. | String | ||
SSL configuration using a Camel SSLContextParameters object. When configured, Camel creates Kafka TLS engines with its own SslEngineFactory and this SSL context. It takes precedence over the other SSL endpoint options and additionalProperties entries whose names start with ssl.; only sslEndpointAlgorithm remains applicable for broker hostname verification. | SSLContextParameters | ||
The list of protocols enabled for SSL connections. The default is TLSv1.2,TLSv1.3. This means that clients and servers will prefer TLSv1.3 if both support it and fallback to TLSv1.2 otherwise (assuming both support at least TLSv1.2). This default should be fine for most use cases. Also see the documentation of sslProtocol to understand how it can impact the TLS version negotiation behavior. | TLSv1.2,TLSv1.3 | String | |
The endpoint identification algorithm to validate server hostname using server certificate. Use none or false to disable server hostname verification. | https | String | |
The algorithm used by key manager factory for SSL connections. Default value is the key manager factory algorithm configured for the Java Virtual Machine. | SunX509 | String | |
The password of the private key in the key store file or the PEM key specified in sslKeystoreKey. This is required for clients only if two-way authentication is configured. | String | ||
The location of the key store file. This is optional for the client and can be used for two-way authentication for the client. | String | ||
The store password for the key store file. This is optional for the client and only needed if sslKeystoreLocation is configured. Key store password is not supported for PEM format. | String | ||
The file format of the key store file. This is optional for the client. The supported values are JKS, PKCS12 and PEM. | JKS | String | |
The SSL protocol used to generate the SSLContext. The default is TLSv1.3, which should be fine for most use cases. A typical alternative to the default is TLSv1.2. Allowed values for this config are dependent on the JVM. Clients using the defaults for this config and sslEnabledProtocols will downgrade to TLSv1.2 if the server does not support TLSv1.3. If this config is set to TLSv1.2, however, clients will not use TLSv1.3 even if it is one of the values in sslEnabledProtocols and the server only supports TLSv1.3. | TLSv1.3 | String | |
The name of the security provider used for SSL connections. Default value is the default security provider of the JVM. | String | ||
The algorithm used by trust manager factory for SSL connections. Default value is the trust manager factory algorithm configured for the Java Virtual Machine. | PKIX | String | |
The location of the trust store file. | String | ||
The password for the trust store file. If a password is not set, trust store file configured will still be used, but integrity checking is disabled. Trust store password is not supported for PEM format. | String | ||
The file format of the trust store file. The supported values are JKS, PKCS12 and PEM. | JKS | String |
Message Headers
The Kafka Share component supports the following message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
| Constant: | The topic from where the message originated. | String | |
CamelKafkaPartition (consumer) Constant: | The partition where the message was stored. | Integer | |
| Constant: | The offset of the message. | Long | |
| Constant: | The key of the record. The header is not set when the record has no key. | Object | |
CamelKafkaTimestamp (consumer) Constant: | The timestamp of the record, in milliseconds since the epoch: the create time or the log append time, as configured on the topic. | Long | |
| Constant: | The headers of the record, as the Kafka Headers object. The headers are also mapped one by one to message headers, through the headerFilterStrategy and the headerDeserializer. | Headers | |
CamelKafkaShareDeliveryCount (consumer) Constant: | How many times the share group has delivered the record, this delivery included (1 on the first delivery). | Short | |
CamelKafkaShareAcknowledge (consumer) Constant: | How to acknowledge the record (ACCEPT, RELEASE or REJECT, in any case), instead of deriving it from the outcome of the exchange. Set it in the route, for example to REJECT a record that was delivered too many times. An invalid value is ignored with a WARN log. Enum values:
| String |
Message Body
The message body at each side of the Kafka Share component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.
| Side | Body | Description |
|---|---|---|
Consumer |
| The value of the record: a String with the default valueDeserializer (StringDeserializer), null for a tombstone. The key of the record, when it has one, is in the CamelKafkaKey header.
Not known when |
The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.
Deterministic simulation tests
The consumer of the Kafka Share component is tested with deterministic simulation tests: the real consumer runs under a seeded virtual-time scheduler against a fake of the external system, which injects faults while the tests check invariants. A failing seed can be replayed. These are the fake worlds of the component:
| World | What it checks | Issues |
|---|---|---|
Fake: FakeShareGroup: a share group (KIP-932) of one topic with one partition, behind ShareConsumer Tests: | Covers:
Faults:
Invariants:
|
The worlds and their tests are in the test sources of the component. How to run them, replay a seed and write a world is described in Running the tests and Writing a fake world.
Usage
TLS with sslContextParameters
When sslContextParameters is configured, Camel creates Kafka TLS engines with its CamelSslEngineFactory and the SSLContext created from those parameters. The complete Camel JSSE configuration is applied, including key and trust managers, cipher suites, enabled protocols, named groups, signature schemes and Camel’s post-quantum named-group preference when available.
In this mode, sslContextParameters is authoritative. All Kafka-specific SSL endpoint options other than sslEndpointAlgorithm (for example, sslKeystoreLocation, sslTruststoreLocation and sslProtocol) and additionalProperties entries whose names start with ssl. are ignored. Camel logs warnings listing non-default SSL endpoint option names and ignored additional-property names, without logging their values. To use different TLS settings for a particular endpoint, configure endpoint-specific sslContextParameters. The sslEndpointAlgorithm option remains applicable and controls broker hostname verification. SASL and non-SSL additional properties continue to work.
Without sslContextParameters, Camel keeps using Kafka’s default SSL engine factory and the Kafka ssl.* endpoint options and additional properties as before.
Broker requirements
Share groups need the share.version feature of the cluster at level 1. It is enabled by default on a cluster created with Kafka 4.2 or newer; a cluster upgraded from an older version enables it with kafka-features.sh --bootstrap-server <broker> upgrade --feature share.version=1. On a single broker, also set share.coordinator.state.topic.replication.factor=1 and share.coordinator.state.topic.min.isr=1, otherwise the broker cannot create the internal topic that holds the state of the share groups, and the consumers receive no records.
The broker setting group.share.delivery.count.limit (default 5) limits how many times a record is delivered, and group.share.record.lock.duration.ms (default 30 seconds) limits how long a consumer can hold a record before the broker makes it available to another consumer.
Where a new share group starts
A new share group starts with the records produced after it is created. To consume the records already in the topic, the group configuration share.auto.offset.reset must be earliest before the group first consumes. It is a configuration of the group on the broker, not a client property, so the consumer can set it with the shareAutoOffsetReset option:
from("kafka-share:orders?brokers=localhost:9092&groupId=order-workers&shareAutoOffsetReset=earliest")
.to("log:orders"); When the consumer starts, before its share consumers subscribe, it sets share.auto.offset.reset of the group with the Kafka Admin client (incrementalAlterConfigs on the GROUP resource). The admin client gets the same brokers, security and additional properties as the share consumer. The values are:
-
earliest: a share-partition starts at the earliest record of the partition; -
latest: a share-partition starts at the next record produced (the default of Kafka); -
by_duration:<duration>: a share-partition starts at the records produced within the ISO-8601 duration before now, such asby_duration:PT1Hfor the last hour.
The setting decides where a share-partition starts when the group first consumes it: it does not move a share group that already consumes the topic. It is a setting of the group, so it applies to all the consumers of the group, and the last consumer to start wins when they are configured differently. When the option is not set, the group configuration is left as it is.
The principal of the consumer needs the ALTER_CONFIGS permission on the group (with ACLs: kafka-acls.sh --add --allow-principal User:camel --operation AlterConfigs --group order-workers), and the consumer fails to start, with an error naming the group, when the configuration cannot be set, such as when the principal is not authorized or the brokers cannot be reached within consumerRequestTimeoutMs. Without that permission, set the group configuration once with kafka-configs.sh: kafka-configs.sh --bootstrap-server <broker> --entity-type groups --entity-name order-workers --alter --add-config share.auto.offset.reset=earliest.
Acknowledgements
Each record is acknowledged after its exchange is processed, from the outcome of the exchange:
| Exchange outcome | Acknowledgement |
|---|---|
The route set the | The value of the header |
Completed, or failed with an exception handled by the route (for example |
|
Failed, or rolled back | The |
Not processed because the consumer is stopping |
|
ACCEPT-
The record was processed: it is not delivered again.
RELEASE-
The record was not processed: the broker delivers it again, to this or another consumer, until the delivery count limit of the broker is reached.
REJECT-
The record cannot be processed: it is discarded and not delivered again.
The acknowledgements of the records of a poll are committed to the broker after they are processed. With commitMode=SYNC (default) the consumer waits for the result, and a failure to commit is reported to the exception handler; with commitMode=ASYNC it does not wait, and a failure is logged. When the acknowledgements cannot be committed, the broker delivers the records again.
The CamelKafkaShareAcknowledge header starts with Camel, so a header with this name in a Kafka record is removed by the header filter strategy: only the route can set it.
Delivery count and poison records
The CamelKafkaShareDeliveryCount header holds how many times the record has been delivered, this delivery included. As the broker delivers a released record again, a route can stop retrying a record that keeps failing, and move it elsewhere:
-
Java
-
YAML
errorHandler(noErrorHandler()); // no local retries: the broker delivers the record again, possibly to another pod
onException(InvalidInvoiceException.class)
.handled(true) // handled -> ACCEPT
.to("kafka:invoices-invalid?brokers={{kafka.brokers}}");
from("kafka-share:invoices?brokers={{kafka.brokers}}&groupId=invoice-ocr")
.filter(header(KafkaShareConstants.DELIVERY_COUNT).isGreaterThanOrEqualTo(4))
.setHeader(KafkaShareConstants.ACKNOWLEDGE, constant("REJECT"))
.to("kafka:invoices-dlq?brokers={{kafka.brokers}}")
.stop()
.end()
.to("http://ocr-service/extract")
.to("kafka:invoices-extracted?brokers={{kafka.brokers}}"); - route:
from:
uri: kafka-share:invoices
parameters:
brokers: "{{kafka.brokers}}"
groupId: invoice-ocr
steps:
- filter:
simple: "${header.CamelKafkaShareDeliveryCount} >= 4"
steps:
- setHeader:
name: CamelKafkaShareAcknowledge
constant: REJECT
- to: "kafka:invoices-dlq?brokers={{kafka.brokers}}"
- stop: {}
- to: "http://ocr-service/extract"
- to: "kafka:invoices-extracted?brokers={{kafka.brokers}}" Consumers count
Each consumer (consumersCount) runs on its own thread with its own share consumer, as the Kafka client is not thread safe. Unlike a consumer group, consumers beyond the number of partitions are not idle: all of them receive records.
-
Java
-
YAML
// 20 concurrent consumers on a topic with 3 partitions: a slow ticket does not hold up the others
from("kafka-share:support-tickets?brokers={{kafka.brokers}}&groupId=ticket-triage&consumersCount=20")
.to("langchain4j-chat:triage")
.to("kafka:tickets-triaged?brokers={{kafka.brokers}}"); - route:
from:
uri: kafka-share:support-tickets
parameters:
brokers: "{{kafka.brokers}}"
groupId: ticket-triage
consumersCount: 20
steps:
- to: "langchain4j-chat:triage"
- to: "kafka:tickets-triaged?brokers={{kafka.brokers}}" Delivery semantics
Delivery is at-least-once. A record is processed again when:
-
its acquisition lock expires while the route processes it (see
group.share.record.lock.duration.ms); -
the JVM stops after the route’s side effects but before the acknowledgement reaches the broker;
-
the acknowledgements cannot be committed;
-
the route releases a record after a partial side effect.
Use the Idempotent Consumer where duplicates matter.
Differences from the Kafka component
The options of the Kafka component that are about offsets, consumer group membership and ordering do not apply to a share group: seekTo, autoOffsetReset (see shareAutoOffsetReset instead), autoCommitEnable, allowManualCommit, breakOnFirstError, partitionAssignor, groupProtocol, groupInstanceId, topicIsPattern, isolationLevel, offsetRepository and batching. A share consumer cannot be paused, so suspending a route stops its consumer. The brokers, security, deserializer, header and additional properties options are the same as the Kafka component.
The client properties that a share consumer rejects (auto.offset.reset, enable.auto.commit, group.instance.id, isolation.level, partition.assignment.strategy, interceptor.classes, session.timeout.ms, heartbeat.interval.ms, group.protocol and group.remote.assignor) make the consumer fail to start, with an error naming them, when they are set as additionalProperties.
Health check
The consumer is ready when all its share consumers are created and subscribed. When a share consumer cannot be created, the health check reports it as down, with the error and the bootstrap.servers, group.id, client.id, route.id and topic details.
The pollOnError option applies to exceptions only. The Kafka client wraps only a RuntimeException of a deserializer in a RecordDeserializationException. A java.lang.Error, such as an ExceptionInInitializerError or NoClassDefFoundError of a deserializer whose classes cannot be loaded, fails every poll the same way. The consumer thread then logs the error, closes its share consumer and terminates, and the health check reports it as down. Fix the cause (for example, a dependency version), and then restart the route or the application.