1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Level23\Druid\Lookups; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* @see https://druid.apache.org/docs/latest/querying/kafka-extraction-namespace |
8
|
|
|
*/ |
9
|
|
|
class KafkaLookup implements LookupInterface |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @param string $kafkaTopic The Kafka topic to read the data from |
13
|
|
|
* @param string|array<int,string> $servers |
14
|
|
|
* @param array<string,scalar> $kafkaProperties Kafka consumer properties |
15
|
|
|
* @param int $connectTimeout How long to wait for an initial connection |
16
|
|
|
* @param bool $isOneToOne The map is a one-to-one (like injective) |
17
|
|
|
*/ |
18
|
2 |
|
public function __construct( |
19
|
|
|
protected string $kafkaTopic, |
20
|
|
|
protected string|array $servers, |
21
|
|
|
protected array $kafkaProperties = [], |
22
|
|
|
protected int $connectTimeout = 0, |
23
|
|
|
protected bool $isOneToOne = false |
24
|
|
|
) { |
25
|
2 |
|
$this->kafkaProperties['bootstrap.servers'] = |
26
|
2 |
|
is_array($this->servers) |
27
|
1 |
|
? implode(',', $this->servers) |
28
|
2 |
|
: $this->servers; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @return array<string,string|array<string,scalar>|int|bool> |
33
|
|
|
*/ |
34
|
2 |
|
public function toArray(): array |
35
|
|
|
{ |
36
|
2 |
|
return [ |
37
|
2 |
|
'type' => 'kafka', |
38
|
2 |
|
'kafkaTopic' => $this->kafkaTopic, |
39
|
2 |
|
'kafkaProperties' => $this->kafkaProperties, |
40
|
2 |
|
'connectTimeout' => $this->connectTimeout, |
41
|
2 |
|
'isOneToOne' => $this->isOneToOne, |
42
|
2 |
|
]; |
43
|
|
|
} |
44
|
|
|
} |