|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Seasx\SeasLogger\Kafka; |
|
5
|
|
|
|
|
6
|
|
|
use Exception; |
|
7
|
|
|
use Seasx\SeasLogger\Exceptions\NotSupportedException; |
|
8
|
|
|
use function in_array; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @method int getRequestTimeout() |
|
12
|
|
|
* @method int getProduceInterval() |
|
13
|
|
|
* @method int getTimeout() |
|
14
|
|
|
* @method int getRequiredAck() |
|
15
|
|
|
* @method bool getIsAsyn() |
|
16
|
|
|
* @method int getCompression() |
|
17
|
|
|
*/ |
|
18
|
|
|
class ProducterConfig extends Config |
|
19
|
|
|
{ |
|
20
|
|
|
private const COMPRESSION_OPTIONS = [ |
|
21
|
|
|
Produce::COMPRESSION_NONE, |
|
22
|
|
|
Produce::COMPRESSION_GZIP, |
|
23
|
|
|
Produce::COMPRESSION_SNAPPY, |
|
24
|
|
|
]; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var mixed[] |
|
28
|
|
|
*/ |
|
29
|
|
|
protected static $defaults = [ |
|
30
|
|
|
'requiredAck' => 1, |
|
31
|
|
|
'timeout' => 5000, |
|
32
|
|
|
'requestTimeout' => 6000, |
|
33
|
|
|
'compression' => Protocol::COMPRESSION_NONE, |
|
34
|
|
|
]; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param int $requestTimeout |
|
38
|
|
|
* @throws Exception |
|
39
|
|
|
*/ |
|
40
|
|
|
public function setRequestTimeout(int $requestTimeout): void |
|
41
|
|
|
{ |
|
42
|
|
|
if ($requestTimeout < 1 || $requestTimeout > 900000) { |
|
43
|
|
|
throw new NotSupportedException('Set request timeout value is invalid, must set it 1 .. 900000'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$this->options['requestTimeout'] = $requestTimeout; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param int $timeout |
|
51
|
|
|
* @throws Exception |
|
52
|
|
|
*/ |
|
53
|
|
|
public function setTimeout(int $timeout): void |
|
54
|
|
|
{ |
|
55
|
|
|
if ($timeout < 1 || $timeout > 900000) { |
|
56
|
|
|
throw new NotSupportedException('Set timeout value is invalid, must set it 1 .. 900000'); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
$this->options['timeout'] = $timeout; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param int $requiredAck |
|
64
|
|
|
* @throws Exception |
|
65
|
|
|
*/ |
|
66
|
|
|
public function setRequiredAck(int $requiredAck): void |
|
67
|
|
|
{ |
|
68
|
|
|
if ($requiredAck < -1 || $requiredAck > 1000) { |
|
69
|
|
|
throw new NotSupportedException('Set required ack value is invalid, must set it -1 .. 1000'); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
$this->options['requiredAck'] = $requiredAck; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @param int $compression |
|
77
|
|
|
* @throws Exception |
|
78
|
|
|
*/ |
|
79
|
|
|
public function setCompression(int $compression): void |
|
80
|
|
|
{ |
|
81
|
|
|
if (!in_array($compression, self::COMPRESSION_OPTIONS, true)) { |
|
82
|
|
|
throw new NotSupportedException('Compression must be one the Produce::COMPRESSION_* constants'); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
$this->options['compression'] = $compression; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|