Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed default securityProtocol config #215

Merged
merged 3 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
14 changes: 14 additions & 0 deletions config/kafka.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@
*/
'brokers' => env('KAFKA_BROKERS', 'localhost:9092'),

/*
| Default security protocol
*/
'securityProtocol' => env('KAFKA_SECURITY_PROTOCOL', 'PLAINTEXT'),

/*
| Default sasl configuration
*/
'sasl' => [
'mechanisms' => env('KAFKA_MECHANISMS', 'PLAINTEXT'),
'username' => env('KAFKA_USERNAME', null),
'password' => env('KAFKA_PASSWORD', null)
],

/*
| Kafka consumers belonging to the same consumer group share a group id.
| The consumers in a group then divides the topic partitions as fairly amongst themselves as possible by
Expand Down
8 changes: 5 additions & 3 deletions src/Console/Commands/KafkaConsumer/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Options
private ?int $commit = 1;
private ?string $dlq = null;
private int $maxMessages = -1;
private ?string $securityProtocol = 'plaintext';
private ?string $securityProtocol = null;
private ?string $saslUsername;
private ?string $saslPassword;
private ?string $saslMechanisms;
Expand Down Expand Up @@ -81,13 +81,15 @@ public function getSasl(): ?Sasl
username: $this->saslUsername,
password: $this->saslPassword,
mechanisms: $this->saslMechanisms,
securityProtocol: $this->securityProtocol
securityProtocol: $this->getSecurityProtocol()
);
}

public function getSecurityProtocol(): ?string
{
return $this->securityProtocol;
return (
strlen($this->securityProtocol) > 1 ? $this->securityProtocol : $this->config['securityProtocol']
) || 'plaintext';
}

public function getBroker()
Expand Down
5 changes: 4 additions & 1 deletion src/Console/Commands/KafkaConsumerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ public function handle()

return;
}
$options = new Options($this->options(), $this->config);

$options = new Options(array_map(function ($value) {
return $value === '?' ? null : $value;
}, $this->options()), $this->config);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you extract this into two lines? It's more readable IMO


$consumer = $options->getConsumer();
$deserializer = $options->getDeserializer();
Expand Down