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

chore: config options refinement #136

Merged
merged 7 commits into from
Oct 18, 2023
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
49 changes: 0 additions & 49 deletions src/AbstractConfigManager.php

This file was deleted.

14 changes: 3 additions & 11 deletions src/Connectors/Consumer/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,11 @@ private function getTopicConfig(string $configName, string $topicId): array
throw new ConfigurationException("Topic '{$topicId}' not found");
}

$topicConfig['middlewares'] = $this->getMiddlewares(
$configName,
$topicConfig
$topicConfig['middlewares'] = config(
'kafka.middlewares.consumer',
[]
);

return $topicConfig;
}

private function getMiddlewares(string $configName, array $topicConfig): array
{
return array_merge(
config($configName . '.middlewares.consumer', []),
$topicConfig['consumer']['middlewares'] ?? []
);
}
}
43 changes: 0 additions & 43 deletions src/Connectors/Producer/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

namespace Metamorphosis\Connectors\Producer;

use Metamorphosis\AbstractConfigManager;
use Metamorphosis\Connectors\AbstractConfig;
use Metamorphosis\Exceptions\ConfigurationException;
use Metamorphosis\ProducerConfigManager;
use Metamorphosis\TopicHandler\ConfigOptions\Producer as ProducerConfigOptions;

class Config extends AbstractConfig
{
Expand Down Expand Up @@ -38,43 +34,4 @@ class Config extends AbstractConfig
'partition' => RD_KAFKA_PARTITION_UA,
'ssl_verify' => false,
];

public function make(ProducerConfigOptions $configOptions): AbstractConfigManager
{
$configManager = app(ProducerConfigManager::class);
$configManager->set($configOptions->toArray());

return $configManager;
}

public function makeByTopic(string $topicId): AbstractConfigManager
{
$topicConfig = $this->getTopicConfig($topicId);
$topicConfig['middlewares'] = $topicConfig['producer']['middlewares'] ?? [];
$brokerConfig = $this->getBrokerConfig('service');
$schemaConfig = $this->getSchemaConfig('service');
$config = array_merge($topicConfig, $brokerConfig, $schemaConfig);

$this->validate($config);
$config = array_merge($this->default, $config);

$configManager = app(ProducerConfigManager::class);
$configManager->set($config);

return $configManager;
}

private function getTopicConfig(string $topicId): array
{
$topicConfig = array_merge(
config('kafka.topics.' . $topicId, []),
config('kafka.topics.' . $topicId . '.producer', [])
);
if (!$topicConfig) {
throw new ConfigurationException("Topic '{$topicId}' not found");
}
$topicConfig['topic'] = $topicId;

return $topicConfig;
}
}
10 changes: 0 additions & 10 deletions src/Producer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Metamorphosis\Middlewares\Handler\Producer as ProducerMiddleware;
use Metamorphosis\Producer\Poll;
use Metamorphosis\TopicHandler\ConfigOptions\Producer as ProducerConfigOptions;
use Metamorphosis\TopicHandler\Producer\AbstractProducer;
use Metamorphosis\TopicHandler\Producer\HandlerInterface;

class Producer
Expand Down Expand Up @@ -73,13 +72,4 @@ public function getProducerMiddleware(
compact('topic', 'poll', 'partition')
);
}

private function getConfigManager(HandlerInterface $producerHandler): AbstractConfigManager
{
if ($producerHandler instanceof AbstractProducer) {
return $this->config->make($producerHandler->getConfigOptions());
}

return $this->config->makeByTopic($producerHandler->getTopic());
}
}
27 changes: 0 additions & 27 deletions src/ProducerConfigManager.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/TopicHandler/ConfigOptions/Consumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function toArray(): array
'auto_commit' => $this->isAutoCommit(),
'commit_async' => $this->isCommitASync(),
'offset_reset' => $this->getOffsetReset(),
'max_poll_interval' => $this->getMaxPollInterval(),
'max_poll_interval_ms' => $this->getMaxPollInterval(),
];

if ($avroSchema = $this->getAvroSchema()) {
Expand Down
122 changes: 0 additions & 122 deletions tests/Unit/Connectors/Producer/ConfigTest.php

This file was deleted.

Empty file.
Empty file removed tests/Unit/ManagerTest.php
Empty file.
47 changes: 0 additions & 47 deletions tests/Unit/ProducerConfigManagerTest.php

This file was deleted.

3 changes: 2 additions & 1 deletion tests/Unit/TopicHandler/ConfigOptions/ConsumerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function testShouldConvertConfigOptionsToArray(): void
[],
200,
false,
true
true,
);

$expected = [
Expand All @@ -41,6 +41,7 @@ public function testShouldConvertConfigOptionsToArray(): void
'auto_commit' => false,
'commit_async' => true,
'offset_reset' => 'smallest',
'max_poll_interval_ms' => 300000,
];

// Actions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function testShouldMakeConfigOptionWithAvroSchema(): void
'auto_commit' => true,
'commit_async' => true,
'offset_reset' => 'earliest',
'max_poll_interval_ms' => 300000,
];
// Actions
$result = ConsumerFactory::make(
Expand Down