Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
timeout-minutes: 15
services:
kafka:
image: apache/kafka:3.9.0
image: apache/kafka:4.4.0
ports:
- 9092:9092
env:
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ The envelope wire format is versioned separately by `meta.schema_version`

## [Unreleased]

## [1.5.0] - 2026-12-03

### Changed

- **`kafka-clients` 3.9.2 -> 4.4.0.** The Kafka client is now the 4.x line. The public API of this
module is unchanged and the envelope is untouched (`schema_version` stays `1`); only the build
and the tests moved (the `MockProducer` test double lost its 3-argument constructor in 4.0).
The live-broker CI job now runs `apache/kafka:4.4.0`.
- **Minimum Kafka broker is now 2.1.** `kafka-clients` 4.x speaks only the protocol versions
that Kafka 2.1 and later brokers support, so the client no longer connects to brokers older
than 2.1. Run against brokers 2.1 or newer (a 4.x broker is fine).

## [1.4.0] - 2026-11-03

### Added
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ counter — this transport absorbs all four in the binding layer (the envelope s
<dependency>
<groupId>com.babelqueue</groupId>
<artifactId>babelqueue-kafka</artifactId>
<version>1.4.0</version>
<version>1.5.0</version>
</dependency>
```

It pulls `babelqueue-core` and `org.apache.kafka:kafka-clients` transitively.
It pulls `babelqueue-core` and `org.apache.kafka:kafka-clients` (4.x) transitively.

**Broker compatibility.** The `kafka-clients` 4.x line requires a **Kafka broker 2.1 or newer** (it drops the
protocol versions of older brokers). The live integration tests run against Apache Kafka 4.4 (KRaft).

## Produce

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.babelqueue</groupId>
<artifactId>babelqueue-kafka</artifactId>
<version>1.4.0</version>
<version>1.5.0</version>
<packaging>jar</packaging>

<name>BabelQueue Apache Kafka</name>
Expand Down Expand Up @@ -51,7 +51,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<babelqueue-core.version>1.15.0</babelqueue-core.version>
<kafka.version>3.9.2</kafka.version>
<kafka.version>4.4.0</kafka.version>
<junit.version>5.10.3</junit.version>
<mockito.version>5.24.0</mockito.version>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void schemaVersionGateMatchesGolden() throws Exception {
when(consumer.poll(any())).thenReturn(
new ConsumerRecords<>(Map.of(new TopicPartition("orders", 0), List.of(record))));
MockProducer<byte[], byte[]> producer =
new MockProducer<>(true, new ByteArraySerializer(), new ByteArraySerializer());
new MockProducer<>(true, null, new ByteArraySerializer(), new ByteArraySerializer());

int[] handled = {0};
KafkaConsumer.builder(consumer)
Expand Down
14 changes: 7 additions & 7 deletions src/test/java/com/babelqueue/kafka/KafkaConsumerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private static Consumer<byte[], byte[]> consumerWith(ConsumerRecord<byte[], byte
}

private static MockProducer<byte[], byte[]> producer() {
return new MockProducer<>(true, new ByteArraySerializer(), new ByteArraySerializer());
return new MockProducer<>(true, null, new ByteArraySerializer(), new ByteArraySerializer());
}

private static RetryTopics topology() {
Expand Down Expand Up @@ -595,7 +595,7 @@ void schemaVersionGateDlqAsyncFailureDoesNotCommitAndRewinds() {
when(consumer.poll(any())).thenReturn(new ConsumerRecords<>(Map.of(TP, List.of(gated, later))));
// autoComplete=false: the send future stays pending until errorNext() fails it.
MockProducer<byte[], byte[]> producer =
new MockProducer<>(false, new ByteArraySerializer(), new ByteArraySerializer());
new MockProducer<>(false, null, new ByteArraySerializer(), new ByteArraySerializer());
Thread failer = new Thread(() -> {
while (producer.history().isEmpty()) {
Thread.onSpinWait();
Expand Down Expand Up @@ -626,7 +626,7 @@ void schemaVersionGateDlqAsyncFailureDoesNotCommitAndRewinds() {
void schemaVersionGateDlqSyncFailureDoesNotCommitAndRewinds() {
byte[] body = "not-json".getBytes(StandardCharsets.UTF_8);
Consumer<byte[], byte[]> consumer = consumerWith(versionedRecord(body, "2", 8));
MockProducer<byte[], byte[]> producer = new MockProducer<>(true, new ByteArraySerializer(), new ByteArraySerializer()) {
MockProducer<byte[], byte[]> producer = new MockProducer<>(true, null, new ByteArraySerializer(), new ByteArraySerializer()) {
@Override
public synchronized java.util.concurrent.Future<org.apache.kafka.clients.producer.RecordMetadata> send(
ProducerRecord<byte[], byte[]> record) {
Expand Down Expand Up @@ -658,7 +658,7 @@ void schemaVersionGateRewoundRecordIsRedeliveredAndRejectedAgain() {
Consumer<byte[], byte[]> consumer = mock(Consumer.class);
when(consumer.poll(any())).thenReturn(new ConsumerRecords<>(Map.of(TP, List.of(gated))));
boolean[] dlqDown = {true};
MockProducer<byte[], byte[]> producer = new MockProducer<>(true, new ByteArraySerializer(), new ByteArraySerializer()) {
MockProducer<byte[], byte[]> producer = new MockProducer<>(true, null, new ByteArraySerializer(), new ByteArraySerializer()) {
@Override
public synchronized java.util.concurrent.Future<org.apache.kafka.clients.producer.RecordMetadata> send(
ProducerRecord<byte[], byte[]> record) {
Expand Down Expand Up @@ -689,7 +689,7 @@ public synchronized java.util.concurrent.Future<org.apache.kafka.clients.produce
void schemaVersionGateThrowingOnErrorStillRewindsWhenDlqFails() {
byte[] body = "not-json".getBytes(StandardCharsets.UTF_8);
Consumer<byte[], byte[]> consumer = consumerWith(versionedRecord(body, "2", 8));
MockProducer<byte[], byte[]> producer = new MockProducer<>(true, new ByteArraySerializer(), new ByteArraySerializer()) {
MockProducer<byte[], byte[]> producer = new MockProducer<>(true, null, new ByteArraySerializer(), new ByteArraySerializer()) {
@Override
public synchronized java.util.concurrent.Future<org.apache.kafka.clients.producer.RecordMetadata> send(
ProducerRecord<byte[], byte[]> record) {
Expand Down Expand Up @@ -731,7 +731,7 @@ void schemaVersionGateThrowingOnErrorStillCommitsAfterDlqSuccess() {

/** A producer whose every send fails asynchronously (the returned future completes exceptionally). */
private static MockProducer<byte[], byte[]> failingProducer() {
return new MockProducer<>(true, new ByteArraySerializer(), new ByteArraySerializer()) {
return new MockProducer<>(true, null, new ByteArraySerializer(), new ByteArraySerializer()) {
@Override
public synchronized java.util.concurrent.Future<org.apache.kafka.clients.producer.RecordMetadata> send(
ProducerRecord<byte[], byte[]> record) {
Expand Down Expand Up @@ -773,7 +773,7 @@ void synchronousSendFailureDoesNotCommitAndRewinds() {
List<Throwable> errors = new ArrayList<>();
// send() itself throws (buffer full / max.block.ms exceeded) instead of returning a failed future.
MockProducer<byte[], byte[]> throwingProducer =
new MockProducer<>(true, new ByteArraySerializer(), new ByteArraySerializer()) {
new MockProducer<>(true, null, new ByteArraySerializer(), new ByteArraySerializer()) {
@Override
public synchronized java.util.concurrent.Future<org.apache.kafka.clients.producer.RecordMetadata> send(
ProducerRecord<byte[], byte[]> record) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private static ConsumerRecord<byte[], byte[]> envelopeRecord(byte[] key, int att
}

private static MockProducer<byte[], byte[]> producer() {
return new MockProducer<>(true, new ByteArraySerializer(), new ByteArraySerializer());
return new MockProducer<>(true, null, new ByteArraySerializer(), new ByteArraySerializer());
}

private static RetryTopics topology() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void everyCaseHasTheExpectedFateThroughTheConsumer() throws IOException {
String body = c.getString("body");
boolean ok = "ok".equals(c.getString("expect"));
MockProducer<byte[], byte[]> producer =
new MockProducer<>(true, new ByteArraySerializer(), new ByteArraySerializer());
new MockProducer<>(true, null, new ByteArraySerializer(), new ByteArraySerializer());
int[] handled = {0};
// The delete strategy: a decodable record with no handler is dropped, so only poison writes anything.
KafkaConsumer.builder(consumerWith(body))
Expand Down Expand Up @@ -139,7 +139,7 @@ void everyCaseHasTheExpectedFateThroughTheConsumer() throws IOException {
void anOkBodyIsRoutedToItsHandler() {
int[] handled = {0};
MockProducer<byte[], byte[]> producer =
new MockProducer<>(true, new ByteArraySerializer(), new ByteArraySerializer());
new MockProducer<>(true, null, new ByteArraySerializer(), new ByteArraySerializer());
KafkaConsumer.builder(consumerWith("{\"job\":5,\"urn\":\"urn:x\"}"))
.producer(producer)
.retryTopics(RetryTopics.forTopic("orders").tier(Duration.ofSeconds(5)).build())
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/babelqueue/kafka/KafkaPublisherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class KafkaPublisherTest {
private static final String URN = "urn:babel:orders:created";

private static MockProducer<byte[], byte[]> producer() {
return new MockProducer<>(true, new ByteArraySerializer(), new ByteArraySerializer());
return new MockProducer<>(true, null, new ByteArraySerializer(), new ByteArraySerializer());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private static Consumer<byte[], byte[]> consumerWith(ConsumerRecord<byte[], byte
}

private static MockProducer<byte[], byte[]> producer() {
return new MockProducer<>(true, new ByteArraySerializer(), new ByteArraySerializer());
return new MockProducer<>(true, null, new ByteArraySerializer(), new ByteArraySerializer());
}

@Test
Expand Down Expand Up @@ -161,7 +161,7 @@ void nullValueRecordIsRestoredAsNullValue() throws Exception {
void failedRestoreOfInvalidUtf8RecordDoesNotCommit() throws Exception {
byte[] poison = {(byte) 0xFF, (byte) 0xFE, 0x01};
Consumer<byte[], byte[]> consumer = consumerWith(dlqRecord(KEYED, poison));
MockProducer<byte[], byte[]> producer = new MockProducer<>(false, new ByteArraySerializer(), new ByteArraySerializer());
MockProducer<byte[], byte[]> producer = new MockProducer<>(false, null, new ByteArraySerializer(), new ByteArraySerializer());
KafkaRedriveTransport transport = new KafkaRedriveTransport(consumer, producer);

Thread failer = new Thread(() -> {
Expand All @@ -183,7 +183,7 @@ void failedRestoreOfInvalidUtf8RecordDoesNotCommit() throws Exception {
@Test
void failedRestoreRewindsTheConsumerToTheRecordAndNeverCommits() throws Exception {
Consumer<byte[], byte[]> consumer = consumerWith(dlqRecord(KEYED, dlqValue()));
MockProducer<byte[], byte[]> producer = new MockProducer<>(false, new ByteArraySerializer(), new ByteArraySerializer());
MockProducer<byte[], byte[]> producer = new MockProducer<>(false, null, new ByteArraySerializer(), new ByteArraySerializer());
KafkaRedriveTransport transport = new KafkaRedriveTransport(consumer, producer);

// A dry run restores the record to the DLQ; the broker refuses that write.
Expand All @@ -203,7 +203,7 @@ void failedRestoreRewindsTheConsumerToTheRecordAndNeverCommits() throws Exceptio
@Test
void failedRedriveWriteAndFailedRestoreRewindAndReportBothErrors() throws Exception {
Consumer<byte[], byte[]> consumer = consumerWith(dlqRecord(KEYED, dlqValue()));
MockProducer<byte[], byte[]> producer = new MockProducer<>(false, new ByteArraySerializer(), new ByteArraySerializer());
MockProducer<byte[], byte[]> producer = new MockProducer<>(false, null, new ByteArraySerializer(), new ByteArraySerializer());
KafkaRedriveTransport transport = new KafkaRedriveTransport(consumer, producer);

Thread failer = failEveryWrite(producer);
Expand All @@ -225,7 +225,7 @@ void failedRedriveWriteAndFailedRestoreRewindAndReportBothErrors() throws Except
void failedRewindIsReportedAlongsideTheRestoreError() throws Exception {
Consumer<byte[], byte[]> consumer = consumerWith(dlqRecord(KEYED, dlqValue()));
org.mockito.Mockito.doThrow(new IllegalStateException("seek failed")).when(consumer).seek(any(TopicPartition.class), org.mockito.ArgumentMatchers.anyLong());
MockProducer<byte[], byte[]> producer = new MockProducer<>(false, new ByteArraySerializer(), new ByteArraySerializer());
MockProducer<byte[], byte[]> producer = new MockProducer<>(false, null, new ByteArraySerializer(), new ByteArraySerializer());
KafkaRedriveTransport transport = new KafkaRedriveTransport(consumer, producer);

Thread failer = failEveryWrite(producer);
Expand Down Expand Up @@ -307,7 +307,7 @@ void rewindLeavesAlreadyAcknowledgedRecordsAlone() {
void failedRestoreInAMultiPartitionBatchRewindsEveryPartition() throws Exception {
TopicPartition other = new TopicPartition("orders.dlq", 1);
Consumer<byte[], byte[]> consumer = consumerPolling(List.of(dlqRecordAt(0, 41), dlqRecordAt(1, 9)));
MockProducer<byte[], byte[]> producer = new MockProducer<>(false, new ByteArraySerializer(), new ByteArraySerializer());
MockProducer<byte[], byte[]> producer = new MockProducer<>(false, null, new ByteArraySerializer(), new ByteArraySerializer());
KafkaRedriveTransport transport = new KafkaRedriveTransport(consumer, producer);

Thread failer = failEveryWrite(producer);
Expand Down Expand Up @@ -397,7 +397,7 @@ void rewindReportsEverySeekFailureNotOnlyTheFirst() {
void failedWorkWriteWithASuccessfulRestoreRewindsTheRestButNotTheAcknowledgedRecord() throws Exception {
TopicPartition other = new TopicPartition("orders.dlq", 1);
Consumer<byte[], byte[]> consumer = consumerPolling(List.of(dlqRecordAt(0, 41), dlqRecordAt(1, 9)));
MockProducer<byte[], byte[]> producer = new MockProducer<>(false, new ByteArraySerializer(), new ByteArraySerializer());
MockProducer<byte[], byte[]> producer = new MockProducer<>(false, null, new ByteArraySerializer(), new ByteArraySerializer());
KafkaRedriveTransport transport = new KafkaRedriveTransport(consumer, producer);

// The work-topic write fails, the restore to the DLQ succeeds.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private static RetryTopics topology() {
}

private static MockProducer<byte[], byte[]> producer() {
return new MockProducer<>(true, new ByteArraySerializer(), new ByteArraySerializer());
return new MockProducer<>(true, null, new ByteArraySerializer(), new ByteArraySerializer());
}

private static ConsumerRecord<byte[], byte[]> retryRecord(long offset, long timestamp, byte[] key, byte[] value,
Expand Down Expand Up @@ -198,7 +198,7 @@ void aTombstoneKeepsItsNullValue() {
void failedWriteDoesNotCommitAndRewindsThePartition() {
ConsumerRecord<byte[], byte[]> rec = retryRecord(5, 0L, null, "{}".getBytes(StandardCharsets.UTF_8));
Consumer<byte[], byte[]> consumer = consumerReturning(rec);
MockProducer<byte[], byte[]> failing = new MockProducer<>(false, new ByteArraySerializer(), new ByteArraySerializer());
MockProducer<byte[], byte[]> failing = new MockProducer<>(false, null, new ByteArraySerializer(), new ByteArraySerializer());
KafkaRetryReinjector reinjector = reinjector(consumer, failing, new AtomicLong(60_000L));
// The send is not completed; fail it from another thread-free hook: errorNext after send is awaited by get().
Thread failer = new Thread(() -> {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/babelqueue/kafka/PoisonHandlingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private static Consumer<byte[], byte[]> consumerWith(ConsumerRecord<byte[], byte
}

private static MockProducer<byte[], byte[]> producer() {
return new MockProducer<>(true, new ByteArraySerializer(), new ByteArraySerializer());
return new MockProducer<>(true, null, new ByteArraySerializer(), new ByteArraySerializer());
}

private static RetryTopics topology() {
Expand Down