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

[1.6.x] Remove producer config property from getConsumerOptions method #76

Merged
merged 3 commits into from
Feb 16, 2022
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
58 changes: 55 additions & 3 deletions src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,55 @@ class Config
{
const SASL_PLAINTEXT = 'SASL_PLAINTEXT';
const SASL_SSL = 'SASL_SSL';
const PRODUCER_ONLY_CONFIG_OPTIONS = [
'transactional.id',
'transaction.timeout.ms',
'enable.idempotence',
'enable.gapless.guarantee',
'queue.buffering.max.messages',
'queue.buffering.max.kbytes',
'queue.buffering.max.ms',
'linger.ms',
'message.send.max.retries',
'retries',
'retry.backoff.ms',
'queue.buffering.backpressure.threshold',
'compression.codec',
'compression.type',
'batch.num.messages',
'batch.size',
'delivery.report.only.error',
'dr_cb',
'dr_msg_cb',
'sticky.partitioning.linger.ms'
];
const CONSUMER_ONLY_CONFIG_OPTIONS = [
'partition.assignment.strategy',
'session.timeout.ms',
'heartbeat.interval.ms',
'group.protocol.type',
'coordinator.query.interval.ms',
'max.poll.interval.ms',
'enable.auto.commit',
'auto.commit.interval.ms',
'enable.auto.offset.store',
'queued.min.messages',
'queued.max.messages.kbytes',
'fetch.wait.max.ms',
'fetch.message.max.bytes',
'max.partition.fetch.bytes',
'fetch.max.bytes',
'fetch.min.bytes',
'fetch.error.backoff.ms',
'offset.store.method',
'isolation.level',
'consume_cb',
'rebalance_cb',
'offset_commit_cb',
'enable.partition.eof',
'check.crcs',
'allow.auto.create.topics'
];

public function __construct(
private string $broker,
Expand Down Expand Up @@ -67,7 +116,6 @@ public function getConsumerOptions(): array
'metadata.broker.list' => $this->broker,
'auto.offset.reset' => config('kafka.offset_reset', 'latest'),
'enable.auto.commit' => config('kafka.auto_commit', true) === true ? 'true' : 'false',
'compression.codec' => config('kafka.compression', 'snappy'),
'group.id' => $this->groupId,
'bootstrap.servers' => $this->broker,
];
Expand All @@ -76,7 +124,9 @@ public function getConsumerOptions(): array
$options['enable.auto.commit'] = $this->autoCommit === true ? 'true' : 'false';
}

return array_merge($options, $this->customOptions, $this->getSaslOptions());
return collect(array_merge($options, $this->customOptions, $this->getSaslOptions()))
->reject(fn ($option) => in_array($option, self::PRODUCER_ONLY_CONFIG_OPTIONS))
->toArray();
}

#[Pure]
Expand All @@ -88,7 +138,9 @@ public function getProducerOptions(): array
'metadata.broker.list' => $this->broker,
];

return array_merge($config, $this->customOptions, $this->getSaslOptions());
return collect(array_merge($config, $this->customOptions, $this->getSaslOptions()))
->reject(fn ($option) => in_array($option, self::CONSUMER_ONLY_CONFIG_OPTIONS))
->toArray();
}

#[Pure]
Expand Down
1 change: 0 additions & 1 deletion tests/Config/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public function testItReturnsDefaultKafkaConfiguration()
$expectedOptions = [
'auto.offset.reset' => 'latest',
'enable.auto.commit' => 'true',
'compression.codec' => 'snappy',
'group.id' => 'group',
'bootstrap.servers' => 'broker',
'metadata.broker.list' => 'broker',
Expand Down