Kafka Connector Reference¶
The following operations allow you to work with the Kafka Connector. Click an operation name to see parameter details and samples on how to use it.
Connection Configurations¶

The WSO2 Kafka Connector allows you to establish both secure and non-secure connections to Apache Kafka.
Connection Configuration Parameters¶
Kafka
This operation allows you to initialize the connection to Apache Kafka.
| Parameter Name | Description | Required |
|---|---|---|
| name | Unique name to identify the connection. | Yes |
| bootstrapServers | The Kafka brokers listed as host1:port1 and host2:port2. | Yes |
| keySerializerClass | The serializer class for the key that implements the serializer interface. | Yes |
| valueSerializerClass | The serializer class for the value that implements the serializer interface. | Yes |
| schemaRegistryUrl | The URL of the confluent schema registry, only applicable when dealing with apache avro serializer class.. | Optional |
| basicAuthCredentialsSource | The source of basic auth credentials (e.g. USER_INFO, URL), when schema registry is secured to use basic auth.. | Optional |
| basicAuthUserInfo | The relevant basic auth credentials (should be used with basicAuthCredentialsSource). | Optional |
| keySubjectNameStrategy | The strategy for determining the subject name under which the key schema is registered. Available in Kafka Connector v3.3.8 and above. |
Optional |
| subjectNameStrategy | The strategy for determining the subject name under which the value schema is registered. | Optional |
| autoRegisterSchemas | Serializer will/will not attempt to register new schemas. Available in Kafka Connector v3.3.8 and above. |
Optional |
| useLatestVersion | Serializer retrieve the latest schema version for the subject. Available in Kafka Connector v3.3.8 and above. |
Optional |
| bufferMemory | The total bytes of memory the producer can use to buffer records waiting to be sent to the server. | Optional |
| compressionType | The compression type for the data generated by the producer. | Optional |
| retries | Set a value greater than zero if you want the client to resent any records automatically when a request fails. | Optional |
| batchSize | Specify how many records the producer should batch together when multiple records are sent to the same partition. | Optional |
| clientId | The client identifier that you pass to the server when making requests. | Optional |
| connectionsMaxIdleTime | The duration in milliseconds after which idle connections should be closed. | Optional |
| lingerTime | The time, in milliseconds, to wait before sending a record. Set this property when you want the client to reduce the number of requests sent when the load is moderate. This adds a small delay rather than immediately sending out a record. Therefore, the producer waits up to allow other records to be sent so that the requests can be batched together. | Optional |
| maxBlockTime | The maximum time in milliseconds that the KafkaProducer.send() and the KafkaProducer.partitionsFor() methods can be blocked. | Optional |
| maxRequestSize | The maximum size of a request in bytes. | Optional |
| partitionerClass | The partitioner class that implements the partitioner interface. | Optional |
| sendBufferBytes | The size of the TCP send buffer (SO_SNDBUF) to use when sending data. | Optional |
| receiveBufferBytes | The size of the TCP receive buffer (SO_RCVBUF) to use when reading data. | Optional |
| requestTimeout | The maximum amount of time, in milliseconds, that a client waits for the server to respond. | Optional |
| acks | The number of acknowledgments that the producer requires for the leader to receive before considering a request to be complete. | Optional |
| enableIdempotence | When set to ‘true’, the producer will ensure that exactly one copy of each message is written in the stream. If ‘false’, producer retries due to broker failures, etc., may write duplicates of the retried message in the stream. Available in Kafka Connector v3.3.8 and above. |
Optional |
| maxInFlightRequestsPerConnection | The maximum number of unacknowledged requests that the client can send via a single connection before blocking. | Optional |
| timeout | The maximum amount of time, in milliseconds, that the server waits for the acknowledgments from followers to meet the acknowledgment requirements that the producer has specified with acks configuration. | Optional |
| reconnectBackoff | The amount of time to wait before attempting to reconnect to a given host. | Optional |
| reconnectBackoffMax | The maximum amount of time in milliseconds to wait when reconnecting to a broker that has repeatedly failed to connect. Available in Kafka Connector v3.3.8 and above. |
Optional |
| retryBackoff | The amount of time, in milliseconds, to wait before attempting to retry a failed request to a given topic partition. | Optional |
| blockOnBufferFull | Set to true to stop accepting new records when the memory buffer is full. When blocking is not desirable, set this property to false, which causes the producer to throw an exception if a recrord is sent to the memory buffer when it is full. | Optional |
| metadataMaxAge | The period of time, in milliseconds, after which you should refresh metadata even if there was no partition leadership changes to proactively discover any new brokers or partitions. | Optional |
| metadataFetchTimeout | The maximum amount of time, in milliseconds, to block and wait for the metadata fetch to succeed before throwing an exception to the client. | Optional |
| metricReporters | A list of classes to use as metrics reporters. | Optional |
| metricsNumSamples | The number of samples maintained to compute metrics. | Optional |
| metricsSampleWindow | The window of time, in milliseconds, that a metrics sample is computed over. | Optional |
| sendCallbackHandlerClass |
The class name of the producer(send) callback handler implementation. The connector supports two built-in callback handler classes:org.wso2.carbon.connector.callbackhandler.DefaultLoggingCallbackHandler- Logs topic and offset on success - Logs error details (topic, key, headers, etc.) on failure org.wso2.carbon.connector.callbackhandler.DefaultKafkaSendCallbackWithDlq- Same success logging as above - Sends failed messages to a configured Dead Letter Queue (DLQ) You can also implement your own custom send callback handler by overriding the onCompletion method in the KafkaSendCallbackHandler interface.
See the sample implementation here:
DefaultLoggingCallbackHandler.java
Available in Kafka Connector v3.3.8 and above. |
Optional |
| poolingEnabled | Indicates whether or not connection pooling is enabled. Set to 'true' if pooling is enabled and 'false' otherwise. | Optional |
| maxActiveConnections | Maximum number of active connections in the pool. | Optional |
| maxIdleConnections | Maximum number of idle connections in the pool. | Optional |
| maxWaitTime | Maximum time, in milliseconds, to wait for a connection from the pool to become available. | Optional |
| minEvictionTime | The minimum amount of time an object may remain idle in the pool before it is eligible for eviction. | Optional |
| evictionCheckInterval | The number of milliseconds between runs of the object evictor. | Optional |
| exhaustedAction | The behavior of the pool when the pool is exhausted (WHEN_EXHAUSTED_FAIL/WHEN_EXHAUSTED_BLOCK/WHEN_EXHAUSTED_GROW). | Optional |
Performance Tuning Tip: Connection pooling is disabled by default (
poolingEnabledisfalse), and this is the recommended setting for most producer scenarios. When pooling is disabled, the connector creates a single Kafka producer per named connection and shares it across all requests. The Kafka producer is thread-safe and is designed to be shared, so one shared producer is generally faster than several pooled ones.To improve producer throughput, tune the Kafka producer parameters on the connection, such as
acks,batchSize,lingerTime,compressionType, andbufferMemory, instead of the connection pool parameters.Migrating from Kafka connector 2.x: The
maxPoolSizeparameter was removed in Kafka connector 3.x and later versions and replaced bypoolingEnabledtogether with the pool parameters listed above.maxActiveConnectionsis the equivalent of the formermaxPoolSize. IfmaxPoolSizeis included in a<kafkaTransport.init>configuration, it is ignored.
Sample configuration
Given below is a sample configuration to create a producer without security.
<kafkaTransport.init>
<name>Sample_Kafka</name>
<bootstrapServers>localhost:9092</bootstrapServers>
<keySerializerClass>org.apache.kafka.common.serialization.StringSerializer</keySerializerClass>
<valueSerializerClass>org.apache.kafka.common.serialization.StringSerializer</valueSerializerClass>
</kafkaTransport.init>
There is an additional feature for security found in Kafka version 0.9.0.0 and above. You can configure it using the element
<kafkaTransport.init>
<name>Sample_Kafka</name>
<bootstrapServers>localhost:9092</bootstrapServers>
<keySerializerClass>org.apache.kafka.common.serialization.StringSerializer</keySerializerClass>
<valueSerializerClass>org.apache.kafka.common.serialization.StringSerializer</valueSerializerClass>
<securityProtocol>SSL</securityProtocol>
<sslTruststoreLocation>/home/hariprasath/Desktop/kafkaNewJira/certKafka/kafka.server.truststore.jks</sslTruststoreLocation>
<sslTruststorePassword>test1234</sslTruststorePassword>
<sslKeystoreLocation>/home/hariprasath/Desktop/kafkaNewJira/certKafka/kafka.server.keystore.jks</sslKeystoreLocation>
<sslKeystorePassword>test1234</sslKeystorePassword>
<sslKeyPassword>test1234</sslKeyPassword>
</kafkaTransport.init>
Given below is a sample configuration to create a producer for Kafka Avro Serialization,
<kafkaTransport.init>
<name>Sample_Kafka</name>
<bootstrapServers>localhost:9092</bootstrapServers>
<keySerializerClass>io.confluent.kafka.serializers.KafkaAvroSerializer</keySerializerClass>
<valueSerializerClass>io.confluent.kafka.serializers.KafkaAvroSerializer</valueSerializerClass>
<schemaRegistryUrl>http://localhost:8081</schemaRegistryUrl>
</kafkaTransport.init>
Sample init configuration when confluent schema registry is secured with basic auth,
<kafkaTransport.init>
<name>Sample_Kafka</name>
<bootstrapServers>localhost:9092</bootstrapServers>
<keySerializerClass>io.confluent.kafka.serializers.KafkaAvroSerializer</keySerializerClass>
<valueSerializerClass>io.confluent.kafka.serializers.KafkaAvroSerializer</valueSerializerClass>
<schemaRegistryUrl>http://localhost:8081</schemaRegistryUrl>
<basicAuthCredentialsSource>USER_INFO</basicAuthCredentialsSource>
<basicAuthUserInfo>admin:admin</basicAuthUserInfo>
</kafkaTransport.init>
KafkaSecure
In addition to the common configurations listed above, the following parameters are specific to setting up a secure connection with the Apache Kafka.
| Parameter Name | Description | Required |
|---|---|---|
| securityProtocol | The protocol used to communicate with brokers. | Optional |
| SSL Configurations | ||
| sslTruststoreLocation | The location of the trust store file. | Optional |
| sslTruststorePassword | The password for the trust store file. | Optional |
| sslTruststoreType | The format of the trust store file. | Optional |
| sslKeystoreLocation | The location of the key store file. Setting this for the client is optional. Set this when you want to have two-way authentication for the client. | Optional |
| sslKeystorePassword | The store password for the keystore file. Setting this for the client is optional. Set it only if ssl.keystore.location is configured. | Optional |
| sslKeystoreType | The format of the keystore file. Setting this for the client is optional. | Optional |
| sslKeyPassword | The password of the private key in the keystore file. Setting this for the client is optional. | Optional |
| sslEnabledProtocols | The list of protocols enabled for SSL connections. | Optional |
| sslCipherSuites | A list of cipher suites. | Optional |
| sslProtocol | The SSL protocol used to generate the SSLContext. | Optional |
| sslProvider | The name of the security provider used for SSL connections. The default value is the default security provider of the JVM. | Optional |
| sslEndpointIdentificationAlgorithm | The endpoint identification algorithm to validate the server hostname using a server certificate. | Optional |
| sslKeymanagerAlgorithm | The algorithm used by the key manager factory for SSL connections. The default value is the key manager factory algorithm configured for the Java Virtual Machine. | Optional |
| sslTrustmanagerAlgorithm | The algorithm used by the trust manager factory for SSL connections. The default value is the trust manager factory algorithm configured for the Java Virtual Machine. | Optional |
| sslSecureRandomImplementation | The SecureRandom PRNG implementation to use for SSL cryptography operations. | Optional |
| SASL Configurations | ||
| saslMechanism | The mechanism used for SASL. | Optional |
| saslJaasConfig | JAAS login context parameters for SASL connections in the format used by JAAS configuration files. | Optional |
| saslKerberosServiceName | The Kerberos principal name that Kafka runs as. | Optional |
| saslKerberosKinitCmd | The kerberos kinit command path. | Optional |
| saslKerberosMinTimeBeforeRelogin | Login thread's sleep time, in milliseconds, between refresh attempts. | Optional |
| saslKerberosTicketRenewJitter | Percentage of random jitter added to the renewal time. | Optional |
| saslKerberosTicketRenewWindowFactor | The login thread sleeps until the specified window factor of time from the last refresh to the ticket's expiry is reached, after which it will try to renew the ticket. | Optional |
| saslKerberosTicketRenewWindowFactor | Optional | |
| saslOauthbearerTokenEndpointUrl | The URL for the OAuth/OIDC identity provider. | Optional |
| saslOauthbearerScopeClaimName | The override name of the scope claim. | Optional |
| saslLoginConnectTimeout | The duration, in milliseconds, for HTTPS connect timeout. | Optional |
| saslLoginReadTimeout | The duration, in milliseconds, for HTTPS read timeout. | Optional |
| saslLoginRetryBackoff | The duration, in milliseconds, to wait between HTTPS call attempts. | Optional |
| saslLoginRetryBackoffMax | The maximum duration, in milliseconds, for HTTPS call attempts. | Optional |
Publishing messages to Kafka¶
publishMessages
The publishMessages operation allows you to publish messages to the Kafka brokers via Kafka topics.
| Parameter Name | Description | Required |
|---|---|---|
| topic | The name of the topic. | Yes |
| partitionNo | The partition number of the topic. | Yes |
| key | Key of the kafka message. If not specified, a random UUID will be created as the key. | Optional |
| keySchema | Schema of the provided key (applicable only with Kafka Avro Serialization). | Optional |
| keySchemaId | Schema id of the key schema that is stored in the confluent schema registry (applicable only with Kafka Avro Serialization). | Optional |
| keySchemaVersion | The Version of the key schema that is stored in the confluent schema registry. | Optional |
| keySchemaSubject | The Subject of the key schema that is stored in the confluent schema registry. | Optional |
| keySchemaMetadata | The Schema metadata of the key schema that is stored in the confluent schema registry. Available in Kafka Connector v3.3.8 and above. |
Optional |
| keySchemaSoftDeleted | Whether soft deleted key schemas also need to be considered. | Optional |
| value | The message to be published to Kafka. If not specified, the message body from message context will be considered as the message. | Optional |
| valueSchema | Schema of the Kafka value (applicable only with Kafka Avro Serialization). | Optional |
| valueSchemaId | Schema id of the value schema that is stored in the confluent schema registry (applicable only with Kafka Avro Serialization). | Optional |
| valueSchemaVersion | The Version of the value schema that is stored in the confluent schema registry. | Optional |
| valueSchemaSubject | The Subject of the value schema that is stored in the confluent schema registry. | Optional |
| valueSchemaMetadata | The Schema metadata of the value schema that is stored in the confluent schema registry. Available in Kafka Connector v3.3.8 and above. |
Optional |
| valueSchemaSoftDeleted | Whether soft deleted value schemas also need to be considered. | Optional |
| dlqTopic | The topic name of the Dead Letter Queue to which the failed messages should be redirected. This is applicable only when the sendCallbackHandler class has support for Dead Letter Queue (DLQ) handling. Available in Kafka Connector v3.3.8 and above. |
Optional |
| Kafka Headers Configurations | ||
| forwardExistingHeaders | Specifies whether to include existing transport headers in the Kafka message; can be none, all, or filteredAvailable in Kafka Connector v3.3.8 and above. |
Optional |
| kafkaHeaderPrefix | Specifies a prefix to filter out the Kafka related headers from the transport headers that start when forwardExistingHeaders is set to filteredAvailable in Kafka Connector v3.3.8 and above. |
Optional |
| removeHeaderPrefix | Indicates whether the configured prefix should be removed from header names before sending them to Kafka (applies when filtered).Available in Kafka Connector v3.3.8 and above. |
Optional |
| removeFilteredAfterSend | Determines whether the filtered transport headers should be removed from the transport headers after being forwarded to Kafka. Available in Kafka Connector v3.3.8 and above. |
Optional |
| customHeaders | Specifies a list of Kafka headers as a JSON array of objects, where each object represents a Kafka header as a key-value pair. E.g., [{"headerName":"headerValue"}].Available in Kafka Connector v3.3.8 and above. Support for configuring header values dynamically using expressions is available starting from MI-4.3.0. |
Optional |
| customHeaderExpression | Inject a list of headers via an expression that is evaluated at runtime. E.g., json-eval($.headers).Available in Kafka Connector v3.3.8 and above. |
Optional |
You can add the parameter as follows in the publishMessage operation:
<kafkaTransport.publishMessage configKey="kafkaConnection">
<topic>cities</topic>
<partitionNo>0</partitionNo>
<key>myKey</key>
<value>Hello, Kafka!</value>
</kafkaTransport.publishMessage>
<kafkaTransport.publishMessages configKey="kafkaConnection">
<topic>cities</topic>
<partitionNo>0</partitionNo>
<key>myKey</key>
<keySchema>{"type":"string"}</keySchema>
<value>{"userId": "abc123"}</value>
<valueSchema>{"type":"record","name":"UserKey","namespace":"com.example","fields":[{"name":"userId","type":"string"}]}</valueSchema>
</kafkaTransport.publishMessages>
<kafkaTransport.publishMessages configKey="kafkaConnection">
<topic>cities</topic>
<partitionNo>0</partitionNo>
<key>myKey</key>
<keySchemaId>10</keySchema>
<value>value of the message</value>
<valueSchemaId>12</valueSchema>
</kafkaTransport.publishMessages>
Note
In connector versions earlier than v3.3.8, custom Kafka headers can be added by using the header name as the XML element name and its value as the element's content, as shown below.
<kafkaTransport.publishMessages configKey="kafkaConnection">
.
.
<Content-Type>application/json</Content-Type>
<Keep-Alive>true</Keep-Alive>
</kafkaTransport.publishMessages>
Error codes related to Kafka Connector¶
Note
With Kafka connector v3.1.2 and above, when an error occurs, one of the following errors will get set to the message context. For details on how to access these error properties, refer Generic Properties.
| Error Code | Detail |
|---|---|
| 700501 | Connection error. |
| 700502 | Invalid configuration. |
| 700503 | Error while serializing the Avro message in the producer. |
| 700504 | Illegal type is used in an Avro message. |
| 700505 | Error while building Avro schemas. |
| 700506 | Error while parsing schemas and protocols. |
| 700507 | Expected contents of a union cannot be resolved. |
| 700508 | The request message cannot be processed. |
| 700509 | Any other Kafka related error. |