Class KafkaTransport

All Implemented Interfaces:
Closeable, AutoCloseable

public final class KafkaTransport extends PollingTransport

Messaging over Apache Kafka, with no client library.

cn1.messaging.url=kafka://broker1:9092,broker2:9092

A destination is a topic, created by the broker on first use when it allows that (auto.create.topics.enable, its default). A send is one record, acknowledged by every in-sync replica (acks=all); a keyed one goes to the partition Kafka's own partitioner would choose, so records of one key stay in order, and an unkeyed one goes round the partitions.

A listener's group is a Kafka consumer group: each group sees every record, and within one the partitions are shared out among its members by range, as the Java client's default does. Records of one partition are handled one at a time, in order, and the group's offset moves past a record only after its handler returned; concurrency beyond the number of partitions a member holds therefore waits. Offsets are committed within a second of a handler finishing, and before the member gives its partitions up.

A record whose handler failed goes to <topic>.retry.<group>, which the group also consumes: a partition of it waits until its first record is due, so retries never hold up the topic itself -- what Spring Kafka calls a non-blocking retry. One that fails every attempt goes to <topic>.dlq.

A new group starts at the earliest offset, so nothing sent before a listener first started is skipped; cn1.messaging.kafka.auto-offset-reset (or Spring Boot's spring.kafka.consumer.auto-offset-reset) set to latest starts at the end instead. Records compressed with gzip, snappy, lz4 or zstd are read; what this transport sends is uncompressed.

cn1.messaging.kafka.isolation-level (or Spring Boot's spring.kafka.consumer.isolation-level) set to read_committed hides the records of aborted transactions and of transactions still open, as the Java client does; the default, read_uncommitted, is the Java client's default too. Sending in a transaction is not supported.

Authentication

SASL is configured as the Java client configures it, under cn1.messaging.kafka.sasl.* or Spring Boot's own keys:

cn1.messaging.url=kafkas://pkc-xxxxx.eu-west-1.aws.confluent.cloud:9092
cn1.messaging.kafka.sasl.mechanism=PLAIN
cn1.messaging.kafka.sasl.username=<api key>
cn1.messaging.kafka.sasl.password=<api secret>
Key Spring Boot equivalent
cn1.messaging.kafka.sasl.mechanism spring.kafka.properties.sasl.mechanism
cn1.messaging.kafka.sasl.username, .password the username and password of spring.kafka.properties.sasl.jaas.config
cn1.messaging.kafka.security.protocol spring.kafka.security.protocol
cn1.messaging.kafka.sasl.aws-region none: the region of an MSK host name, or AWS_REGION

The mechanisms are PLAIN, SCRAM-SHA-256, SCRAM-SHA-512 and AWS_MSK_IAM. A security protocol of SSL or SASL_SSL turns TLS on as kafkas:// does. Credentials in the URL, kafka://user:password@host (percent-encoded), mean PLAIN unless a mechanism is set. Azure Event Hubs takes PLAIN with the user name $ConnectionString and the connection string as the password, on port 9093 over TLS; Amazon MSK takes SCRAM-SHA-512 or AWS_MSK_IAM, whose credentials come from the environment, the container or the instance, as for S3.