Skip to content

Commit 9015bc6

Browse files
committed
allow multiple endpoints as dsn to avoid downtime if single node fails. (new config hosts)
1 parent d3c07c3 commit 9015bc6

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public function getConfigTreeBuilder()
1616
->children()
1717
->arrayNode('client')
1818
->children()
19+
->arrayNode('hosts')->defaultValue([])->info('An array of DSN to connect to the Elasticsearch cluster.')->scalarPrototype()->end()->end()
1920
->scalarNode('dsn')->defaultValue('http://localhost:9200')->info('The DSN to connect to the Elasticsearch cluster.')->end()
2021
->booleanNode('should_add_sentry_breadcrumbs')->defaultFalse()->info('If true, breadcrumbs are added to Sentry for every request made to Elasticsearch via Elastica.')->end()
2122
->end()

src/Repository/ConfigurationRepository.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Valantic\ElasticaBridgeBundle\Repository;
66

7+
use Psr\Container\ContainerExceptionInterface;
8+
use Psr\Container\NotFoundExceptionInterface;
79
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
810

911
/**
@@ -15,8 +17,18 @@ public function __construct(
1517
private readonly ContainerBagInterface $containerBag,
1618
) {}
1719

18-
public function getClientDsn(): string
20+
/**
21+
* @throws ContainerExceptionInterface
22+
* @throws NotFoundExceptionInterface
23+
*
24+
* @return string|array<string>
25+
*/
26+
public function getClientDsn(): string|array
1927
{
28+
if ($this->containerBag->get('valantic_elastica_bridge')['client']['hosts'] !== []) {
29+
return $this->containerBag->get('valantic_elastica_bridge')['client']['hosts'];
30+
}
31+
2032
return $this->containerBag->get('valantic_elastica_bridge')['client']['dsn'];
2133
}
2234

0 commit comments

Comments
 (0)