Upgrade guide

  • The \Junges\Kafka\Contracts\CanProduceMessages contract was renamed to \Junges\Kafka\Contracts\MessageProducer
  • The \Junges\Kafka\Contracts\KafkaProducerMessage contract was renamed to \Junges\Kafka\Contracts\ProducerMessage
  • The \Junges\Kafka\Contracts\CanConsumeMessages was renamed to \Junges\Kafka\Contracts\MessageConsumer
  • The \Junges\Kafka\Contracts\KafkaConsumerMessage was renamed to \Junges\Kafka\Contracts\ConsumerMessage
  • The \Junges\Kafka\Contracts\CanPublishMessagesToKafka contract was removed.
  • The \Junges\Kafka\Contracts\CanConsumeMessagesFromKafka was removed.
  • The \Junges\Kafka\Contracts\CanConsumeBatchMessages contract was renamed to \Junges\Kafka\Contracts\BatchMessageConsumer
  • The \Junges\Kafka\Contracts\CanConsumeMessages contract was renamed to \Junges\Kafka\Contracts\MessageConsumer
  • Introduced a new \Junges\Kafka\Contracts\Manager used by \Junges\Kafka\Factory class

The withSasl method now accepts all SASL parameters instead of a Sasl object.

public function withSasl(string $username, string $password, string $mechanisms, string $securityProtocol = 'SASL_PLAINTEXT');

In v2 handler functions and handler classes require a \Junges\Kafka\Contracts\MessageConsumer as a second argument.

$consumer = Kafka::consumer(['topic'])
    ->withConsumerGroupId('group')
-     ->withHandler(function(ConsumerMessage $message) {
+     ->withHandler(function(ConsumerMessage $message, MessageConsumer $consumer) {
        //
    })

The Kafka::createConsumer method has been renamed to just consumer

The Kafka::publishOn method has been renamed to publish, and it does not accept the $topics parameter anymore.

Please chain a call to onTopic to specify in which topic the message should be published.

\Junges\Kafka\Facades\Kafka::publish('broker')->onTopic('topic-name');

To set onStopConsuming callbacks you need to define them while building the consumer, instead of after calling the build method as in v1.13.x:

$consumer = Kafka::consumer(['topic'])
    ->withConsumerGroupId('group')
    ->withHandler(new Handler)
+     ->onStopConsuming(static function () {
+         // Do something when the consumer stop consuming messages
+     })
    ->build()
-     ->onStopConsuming(static function () {
-         // Do something when the consumer stop consuming messages
-     })

PHP 8.2 Required

This package now requires PHP 8.2 or higher.

You can use tools such as rector to upgrade your app to PHP 8.2.

Previous
Changelog