Skip to content

Commit

Permalink
Merge pull request #136 from leroy-merlin-br/chore/configOptions-refi…
Browse files Browse the repository at this point in the history
…nement

chore: config options refinement
  • Loading branch information
hcdias authored Oct 18, 2023
2 parents c1a0490 + 5b7bb45 commit ff4b769
Show file tree
Hide file tree
Showing 12 changed files with 7 additions and 311 deletions.
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

0 comments on commit ff4b769

Please sign in to comment.