Skip to content
This repository has been archived by the owner on May 25, 2023. It is now read-only.

Support RDKafka 4 #2

Merged
merged 1 commit into from
Mar 2, 2021
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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
],
"require": {
"php": ">=7.1",
"codeception/codeception": "~2.5"
"ext-rdkafka": "^3 || ^4",
"codeception/codeception": "^2.5 | ^3.0 | ^4.0"
},
"autoload": {
"psr-4": {
Expand Down
6 changes: 6 additions & 0 deletions src/Extension/KafkaModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Codeception\Module;
use Exception;
use Lamoda\Codeception\Extension\MessageSerializer\ArrayMessageSerializer;
use Lamoda\Codeception\Extension\MessageSerializer\MessageSerializerInterface;
use RdKafka\Conf;
use RdKafka\Consumer;
Expand All @@ -17,6 +18,7 @@
class KafkaModule extends Module
{
protected const DEFAULT_PARTITION = 0;
protected const FLUSH_TIMEOUT_MS = 3000;

/**
* @var MessageSerializerInterface
Expand Down Expand Up @@ -83,6 +85,10 @@ public function putMessageInTopic(string $topicName, string $message, ?int $part
$topic = $producer->newTopic($topicName, $this->topicConf);

$topic->produce($partition ?? static::DEFAULT_PARTITION, 0, $message);

if (method_exists($producer, 'flush')) {
$producer->flush(self::FLUSH_TIMEOUT_MS);
}
}

public function putMessageListInTopic(string $topicName, array $messages, ?int $partition = null): void
Expand Down