Migration from Apache Pekko Connectors Kafka 1.x to 2.x
Apache Pekko Connectors Kafka 2.x requires Apache Pekko 2.x. See the Pekko 1.x to 2.x migration guide for the changes in the core Pekko libraries.
Apache Pekko Connectors Kafka 2.x is not binary compatible with 1.x. Libraries built against Pekko Connectors Kafka 1.x or Pekko 1.x need to be rebuilt and released for Pekko 2.x.
General changes
- Apache Pekko 2.x is the new minimum Pekko version.
- Java 17 is the new minimum Java version.
- Scala 2.12 is no longer supported. Scala 2.13 and Scala 3 are supported.
- The Kafka client has been upgraded from 3.9.x to 4.x. See the Kafka client section below.
- Deprecated code has been removed. Before upgrading, build against the latest Pekko Connectors Kafka 1.x release and fix any deprecation warnings. The removed APIs and their replacements are listed below.
Kafka client 4.x
Apache Pekko Connectors Kafka 2.x uses kafka-clients 4.x, where 1.x used kafka-clients 3.x.
- Kafka clients 4.x can only communicate with brokers that are version 2.1 or newer.
- Kafka 4.0 removed client APIs and configuration properties that were deprecated in the 3.x releases. If your code uses the Kafka client API directly, for example in a custom
producerFactoryorconsumerFactory, aPartitionAssignmentHandlerPartitionAssignmentHandleror when setting Kafka properties onConsumerSettingsConsumerSettingsorProducerSettingsProducerSettings, review the Kafka upgrade notes. RestrictedConsumer.committed(TopicPartition)has been removed because the Kafka method it called no longer exists. Usecommitted(java.util.Set[TopicPartition]).- Libraries that depend on the Kafka client, such as Confluent’s
kafka-avro-serializer, need to be upgraded to versions that support Kafka clients 4.x (Confluent Platform 8.x).
Removed deprecated APIs
These APIs were deprecated in Alpakka Kafka or in Pekko Connectors Kafka 1.x and have been removed (PR369).
| Removed | Replacement |
|---|---|
Committable.commitScaladsl() and Committable.commitJavadsl() |
Committer.flow or Committer.sink |
Producer.committableSink(settings) (Scala and Java DSL) |
Producer.committableSink(producerSettings, committerSettings) |
Producer.flow(settings) (Scala and Java DSL) |
Producer.flexiFlow(settings) |
Producer.plainSink, committableSink, flow, flexiFlow and flowWithContext overloads that take a Kafka Producer instance |
Pass the producer in the settings using ProducerSettings.withProducer or ProducerSettings.withProducerFactory |
ProducerSettings.producerFactory |
createKafkaProducer(), createKafkaProducerAsync() or createKafkaProducerCompletionStage() |
SendProducer(settings, system) with a classic ActorSystem (Scala DSL) |
SendProducer(settings) with an implicit ClassicActorSystemProvider |
Metadata.GetCommittedOffset, Metadata.CommittedOffset and Metadata.createGetCommittedOffset |
Metadata.GetCommittedOffsets, Metadata.CommittedOffsets and Metadata.createGetCommittedOffsets |
MetadataClient.getCommittedOffset(partition) (Scala and Java DSL) |
MetadataClient.getCommittedOffsets(partitions) |
RestrictedConsumer.committed(TopicPartition) |
RestrictedConsumer.committed(java.util.Set[TopicPartition]) |
Java DSL changes
- The Java DSL uses
java.lang.Longfor offsets wherescala.Longleaked through asObject(PR691). Java code written againstMap<TopicPartition, Object>has to be changed to useMap<TopicPartition, Long>. This affects- the
getOffsetsOnAssignparameter ofConsumer.plainPartitionedManualOffsetSourceandConsumer.committablePartitionedManualOffsetSource, which now returns aCompletionStage<Map<TopicPartition, Long>> CommittableOffsetBatch.getOffsets, which now returns aMap<GroupTopicPartition, Long>
- the
Consumer.committableExternalSourcehas a new overload that takes ajava.time.Durationcommit timeout. The overload that takes a ScalaFiniteDurationis deprecated.Producer.committableSink, and themetadataFromRecord,getOffsetsOnAssignandonRevokefunction parameters of theConsumersources, accept wildcard generic types.Producer.committableSinkno longer needs an explicit type witness. The erased signatures are unchanged.TopicPartitionsAssignedandTopicPartitionsRevokedhave a newgetTopicPartitionsmethod that returns ajava.util.Set.
Behavior changes
ConsumerSettingsConsumerSettings,ProducerSettingsProducerSettingsandCommitterSettingsCommitterSettingsvalidate their values. A duration or count that is zero or negative, such aspoll-interval,stop-timeout,close-timeout,parallelismormax-batch, now fails with anIllegalArgumentExceptionwhen the settings are created, instead of being accepted. An infinitecommit-refresh-intervalis still valid. (PR627)- Offset commits that fail with a Kafka
TimeoutExceptionorCoordinatorLoadInProgressExceptionare retried by the consumer actor, as was already done forRebalanceInProgressException.commit-timeoutonly limits how long the caller waits: when it expires, the returnedFutureCompletionStagefails with aCommitTimeoutException. It does not cancel the retries, so the consumer actor keeps retrying the commit for as long as it fails with one of these exceptions. (PR505) - The Java DSL
Consumer.DrainingControl.isShutdowncompletes when the consumer has shut down and the stream has completed, as the Scala DSL does. It previously completed as soon as the consumer had shut down. In both DSLs,isShutdownreturns the sameFutureCompletionStageon every call. (PR683) - When the connection checker reports a
KafkaConnectionFailed, the failure is also sent to the owner actor of theKafkaConsumerActor, and not only to the stages that requested messages. (PR626) ConsumerSettings.toStringandProducerSettings.toStringprint[hidden]for the value of every property that is not defined by Kafka’s own consumer or producer configuration, as well as for Kafka password properties. This includes properties read by serializers, interceptors and config providers, such asschema.registry.url. The properties are still passed unchanged to the Kafka client.toStringalso no longer validates the properties: it used to throw a KafkaConfigExceptionfor a value that Kafka rejects, and that error is now only reported when the Kafka client is created. (PR714)
Testkit
- The Testcontainers support can start Confluent Platform 8.x (Kafka 4) images, which run in KRaft mode without ZooKeeper. The default
confluent-platform-versionis still a 7.x release (Kafka 3) and can be overridden with theCONFLUENT_PLATFORM_VERSIONenvironment variable or in the Testcontainers settings. (PR646)
2.0.0